@danielx/civet 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,19 @@ This changelog is generated automatically by [`build/changelog.civet`](build/cha
4
4
  For each version of Civet, it lists and links to all incorporated PRs,
5
5
  as well as a full diff and commit list.
6
6
 
7
+ ## 0.8.1 (2024-10-13, [diff](https://github.com/DanielXMoore/Civet/compare/v0.8.0...v0.8.1), [commits](https://github.com/DanielXMoore/Civet/commits/v0.8.1))
8
+ * Fix `catch` type annotation by forbidding indented type arguments in `catch` [[#1446](https://github.com/DanielXMoore/Civet/pull/1446)]
9
+ * Require parentheses in complex `&` type annotation [[#1447](https://github.com/DanielXMoore/Civet/pull/1447)]
10
+ * BREAKING CHANGE: `&: number | string` is now treated as `(&: number) | string`, and `&: T ? a : b` is consistently treated as `(&: T) ? a : b`
11
+ * CLI exposes top-level declarations with top-level `await` [[#1448](https://github.com/DanielXMoore/Civet/pull/1448)]
12
+ * `.d.ts` matches output extension in CLI; `declarationExtension` option in unplugin [[#1451](https://github.com/DanielXMoore/Civet/pull/1451)]
13
+ * Fix CLI executing ESM code from stdin or `-e` [[#1454](https://github.com/DanielXMoore/Civet/pull/1454)]
14
+ * CLI REPL supports (strips) TypeScript [[#1453](https://github.com/DanielXMoore/Civet/pull/1453)]
15
+ * Variance annotations (`in`/`out`) in type parameters [[#1459](https://github.com/DanielXMoore/Civet/pull/1459)]
16
+ * Allow pipes etc. in explicit function arguments [[#1460](https://github.com/DanielXMoore/Civet/pull/1460)]
17
+ * Pipeline doesn't unwrap in multi-`&` function shorthand [[#1462](https://github.com/DanielXMoore/Civet/pull/1462)]
18
+ * Add missing parentheses with `++` concat operator [[#1461](https://github.com/DanielXMoore/Civet/pull/1461)]
19
+
7
20
  ## 0.8.0 (2024-10-10, [diff](https://github.com/DanielXMoore/Civet/compare/v0.7.36...v0.8.0), [commits](https://github.com/DanielXMoore/Civet/commits/v0.8.0))
8
21
  * Assigned expressionized statement followed by pipe, grammar cleanup [[#1442](https://github.com/DanielXMoore/Civet/pull/1442)]
9
22
  * `yield` in `do` yields in parent in all cases [[#1443](https://github.com/DanielXMoore/Civet/pull/1443)]
package/dist/browser.js CHANGED
@@ -38,9 +38,9 @@ var Civet = (() => {
38
38
  ));
39
39
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
40
 
41
- // node_modules/@danielx/hera/dist/machine.js
41
+ // node_modules/.pnpm/@danielx+hera@0.8.16/node_modules/@danielx/hera/dist/machine.js
42
42
  var require_machine = __commonJS({
43
- "node_modules/@danielx/hera/dist/machine.js"(exports, module) {
43
+ "node_modules/.pnpm/@danielx+hera@0.8.16/node_modules/@danielx/hera/dist/machine.js"(exports, module) {
44
44
  "use strict";
45
45
  var __defProp2 = Object.defineProperty;
46
46
  var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
@@ -70,7 +70,7 @@ var Civet = (() => {
70
70
  $N: () => $N2,
71
71
  $P: () => $P2,
72
72
  $Q: () => $Q2,
73
- $R: () => $R99,
73
+ $R: () => $R100,
74
74
  $R$0: () => $R$02,
75
75
  $S: () => $S2,
76
76
  $T: () => $T2,
@@ -107,7 +107,7 @@ var Civet = (() => {
107
107
  return;
108
108
  };
109
109
  }
110
- function $R99(regExp) {
110
+ function $R100(regExp) {
111
111
  return function(_ctx, state2) {
112
112
  const { input, pos } = state2;
113
113
  regExp.lastIndex = state2.pos;
@@ -543,6 +543,7 @@ ${body}`;
543
543
  getPrecedence: () => getPrecedence,
544
544
  getTrimmingSpace: () => getTrimmingSpace,
545
545
  hasAwait: () => hasAwait,
546
+ hasExportDeclaration: () => hasExportDeclaration,
546
547
  hasImportDeclaration: () => hasImportDeclaration,
547
548
  hasYield: () => hasYield,
548
549
  insertTrimmingSpace: () => insertTrimmingSpace,
@@ -993,6 +994,9 @@ ${body}`;
993
994
  function hasImportDeclaration(exp) {
994
995
  return gatherRecursiveWithinFunction(exp, ($3) => $3.type === "ImportDeclaration").length > 0;
995
996
  }
997
+ function hasExportDeclaration(exp) {
998
+ return gatherRecursiveWithinFunction(exp, ($4) => $4.type === "ExportDeclaration").length > 0;
999
+ }
996
1000
  function deepCopy(node) {
997
1001
  if (node == null)
998
1002
  return node;
@@ -1031,6 +1035,7 @@ ${body}`;
1031
1035
  }
1032
1036
  var skipParens = /* @__PURE__ */ new Set([
1033
1037
  "AmpersandRef",
1038
+ "ArrayExpression",
1034
1039
  "CallExpression",
1035
1040
  "Identifier",
1036
1041
  "JSXElement",
@@ -1044,6 +1049,10 @@ ${body}`;
1044
1049
  // wrapIIFE
1045
1050
  ]);
1046
1051
  function makeLeftHandSideExpression(expression) {
1052
+ while (expression && Array.isArray(expression) && len(expression, 1)) {
1053
+ const [item] = expression;
1054
+ expression = item;
1055
+ }
1047
1056
  if (isASTNodeObject(expression)) {
1048
1057
  if (expression.parenthesized) {
1049
1058
  return expression;
@@ -1051,7 +1060,7 @@ ${body}`;
1051
1060
  if (skipParens.has(expression.type)) {
1052
1061
  return expression;
1053
1062
  }
1054
- if (expression.type === "MemberExpression" && !startsWithPredicate(expression, ($4) => $4.type === "ObjectExpression")) {
1063
+ if (expression.type === "MemberExpression" && !startsWithPredicate(expression, ($5) => $5.type === "ObjectExpression")) {
1055
1064
  return expression;
1056
1065
  }
1057
1066
  }
@@ -2431,7 +2440,12 @@ ${body}`;
2431
2440
  if (isStatement(body)) {
2432
2441
  braceBlock(block);
2433
2442
  fn.ampersandBlock = false;
2434
- delete fn.body;
2443
+ }
2444
+ if (gatherRecursiveWithinFunction(
2445
+ block,
2446
+ (a4) => a4 === ref
2447
+ ).length > 1) {
2448
+ fn.ampersandBlock = false;
2435
2449
  }
2436
2450
  return fn;
2437
2451
  }
@@ -2794,7 +2808,7 @@ ${body}`;
2794
2808
  a = makeAsConst(a);
2795
2809
  b = makeAsConst(b);
2796
2810
  }
2797
- let children;
2811
+ let children, type;
2798
2812
  if (op.type === "PatternTest") {
2799
2813
  children = [processPatternTest(a, b)];
2800
2814
  } else if (op.type === "ChainOp") {
@@ -2803,28 +2817,31 @@ ${body}`;
2803
2817
  children = ["(", ...children, ")"];
2804
2818
  }
2805
2819
  } else if (op.call) {
2806
- wsOp = insertTrimmingSpace(wsOp, "");
2820
+ wsOp = trimFirstSpace(wsOp);
2807
2821
  if (op.reversed) {
2808
- wsB = insertTrimmingSpace(wsB, "");
2822
+ wsB = trimFirstSpace(wsB);
2809
2823
  children = [wsOp, op.call, "(", wsB, b, ", ", a, ")", op.suffix];
2810
2824
  } else {
2811
2825
  children = [wsOp, op.call, "(", a, ",", wsB, b, ")", op.suffix];
2812
2826
  }
2827
+ type = "CallExpression";
2813
2828
  } else if (op.method) {
2814
- wsOp = insertTrimmingSpace(wsOp, "");
2815
- wsB = insertTrimmingSpace(wsB, "");
2829
+ wsOp = trimFirstSpace(wsOp);
2830
+ wsB = trimFirstSpace(wsB);
2816
2831
  if (op.reversed) {
2817
- if (end !== i + 2)
2832
+ if (!(b.type === "CallExpression")) {
2818
2833
  b = makeLeftHandSideExpression(b);
2834
+ }
2819
2835
  b = dotNumericLiteral(b);
2820
2836
  children = [wsB, b, wsOp, ".", op.method, "(", a, ")"];
2821
2837
  } else {
2822
- if (start !== i - 2 || a.type === "NumericLiteral") {
2838
+ if (!(a.type === "CallExpression")) {
2823
2839
  a = makeLeftHandSideExpression(a);
2824
2840
  }
2825
2841
  a = dotNumericLiteral(a);
2826
2842
  children = [a, wsOp, ".", op.method, "(", wsB, b, ")"];
2827
2843
  }
2844
+ type = "CallExpression";
2828
2845
  } else if (op.token) {
2829
2846
  children = [a, wsOp, op, wsB, b];
2830
2847
  if (op.negated)
@@ -2838,6 +2855,7 @@ ${body}`;
2838
2855
  children.push(error);
2839
2856
  }
2840
2857
  expandedOps.splice(start, end - start + 1, {
2858
+ type,
2841
2859
  children
2842
2860
  });
2843
2861
  i = start + 2;
@@ -4843,8 +4861,9 @@ ${body}`;
4843
4861
  let line = "?";
4844
4862
  let column = "?";
4845
4863
  let offset;
4846
- if (options && typeof options === "object" && "sourceMap" in options) {
4847
- const { sourceMap } = options;
4864
+ let ref;
4865
+ if (ref = options.sourceMap) {
4866
+ const sourceMap = ref;
4848
4867
  line = sourceMap.data.srcLine + 1;
4849
4868
  column = sourceMap.data.srcColumn + 1;
4850
4869
  offset = sourceMap.data.srcOffset;
@@ -7530,6 +7549,7 @@ ${js}`
7530
7549
  TypeIndex,
7531
7550
  TypeSuffix,
7532
7551
  MaybeNestedType,
7552
+ MaybeNestedTypePrimary,
7533
7553
  ReturnTypeSuffix,
7534
7554
  ReturnType,
7535
7555
  TypePredicate,
@@ -7986,14 +8006,15 @@ ${js}`
7986
8006
  var $R88 = (0, import_lib3.$R)(new RegExp("(?=if|unless)", "suy"));
7987
8007
  var $R89 = (0, import_lib3.$R)(new RegExp("[|&<!=\\-\u21D2\u2192]", "suy"));
7988
8008
  var $R90 = (0, import_lib3.$R)(new RegExp("(extends|not|is)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
7989
- var $R91 = (0, import_lib3.$R)(new RegExp("#![^\\r\\n]*", "suy"));
7990
- var $R92 = (0, import_lib3.$R)(new RegExp("[\\t ]*", "suy"));
7991
- var $R93 = (0, import_lib3.$R)(new RegExp("[\\s]*", "suy"));
7992
- var $R94 = (0, import_lib3.$R)(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([\\p{ID_Continue}.,+-]*))?", "suy"));
7993
- var $R95 = (0, import_lib3.$R)(new RegExp("\\/\\/\\/[^\\r\\n]*", "suy"));
7994
- var $R96 = (0, import_lib3.$R)(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
7995
- var $R97 = (0, import_lib3.$R)(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
7996
- var $R98 = (0, import_lib3.$R)(new RegExp("[^]*", "suy"));
8009
+ var $R91 = (0, import_lib3.$R)(new RegExp("const|in|out", "suy"));
8010
+ var $R92 = (0, import_lib3.$R)(new RegExp("#![^\\r\\n]*", "suy"));
8011
+ var $R93 = (0, import_lib3.$R)(new RegExp("[\\t ]*", "suy"));
8012
+ var $R94 = (0, import_lib3.$R)(new RegExp("[\\s]*", "suy"));
8013
+ var $R95 = (0, import_lib3.$R)(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([\\p{ID_Continue}.,+-]*))?", "suy"));
8014
+ var $R96 = (0, import_lib3.$R)(new RegExp("\\/\\/\\/[^\\r\\n]*", "suy"));
8015
+ var $R97 = (0, import_lib3.$R)(new RegExp("(?=[ \\t\\r\\n\\/#]|$)", "suy"));
8016
+ var $R98 = (0, import_lib3.$R)(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
8017
+ var $R99 = (0, import_lib3.$R)(new RegExp("[^]*", "suy"));
7997
8018
  var Program$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(Reset, Init, (0, import_lib3.$E)(EOS), TopLevelStatements, __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
7998
8019
  var reset = $1;
7999
8020
  var init = $2;
@@ -8172,11 +8193,11 @@ ${js}`
8172
8193
  function ImplicitArguments(ctx, state2) {
8173
8194
  return (0, import_lib3.$EVENT)(ctx, state2, "ImplicitArguments", ImplicitArguments$0);
8174
8195
  }
8175
- var ExplicitArguments$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(OpenParen, (0, import_lib3.$E)((0, import_lib3.$S)(ArgumentList, (0, import_lib3.$E)((0, import_lib3.$S)(__, Comma)))), __, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4) {
8196
+ var ExplicitArguments$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(OpenParen, AllowAll, (0, import_lib3.$E)((0, import_lib3.$S)(ArgumentList, (0, import_lib3.$E)((0, import_lib3.$S)(__, Comma)))), __, RestoreAll, CloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6) {
8176
8197
  var open = $1;
8177
- var args = $2;
8178
- var ws = $3;
8179
- var close = $4;
8198
+ var args = $3;
8199
+ var ws = $4;
8200
+ var close = $6;
8180
8201
  if (args) {
8181
8202
  if (args[1]) {
8182
8203
  args = [...args[0], args[1]];
@@ -8935,8 +8956,10 @@ ${js}`
8935
8956
  function Placeholder(ctx, state2) {
8936
8957
  return (0, import_lib3.$EVENT_C)(ctx, state2, "Placeholder", Placeholder$$);
8937
8958
  }
8938
- var PlaceholderTypeSuffix$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$Y)((0, import_lib3.$S)((0, import_lib3.$E)(QuestionMark), Colon)), TypeSuffix), function(value) {
8939
- return value[1];
8959
+ var PlaceholderTypeSuffix$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$E)(QuestionMark), Colon, MaybeNestedTypePrimary), function(value) {
8960
+ var optional = value[0];
8961
+ var t = value[2];
8962
+ return { "type": "TypeSuffix", "ts": true, "optional": optional, "t": t, "children": value };
8940
8963
  });
8941
8964
  function PlaceholderTypeSuffix(ctx, state2) {
8942
8965
  return (0, import_lib3.$EVENT)(ctx, state2, "PlaceholderTypeSuffix", PlaceholderTypeSuffix$0);
@@ -13649,7 +13672,15 @@ ${js}`
13649
13672
  return (0, import_lib3.$EVENT)(ctx, state2, "CatchClause", CatchClause$0);
13650
13673
  }
13651
13674
  var CatchBind$0 = (0, import_lib3.$S)((0, import_lib3.$E)(_), OpenParen, __, CatchParameter, __, CloseParen);
13652
- var CatchBind$1 = (0, import_lib3.$S)(_, InsertOpenParen, (0, import_lib3.$N)(EOS), CatchParameter, InsertCloseParen);
13675
+ var CatchBind$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(_, InsertOpenParen, (0, import_lib3.$N)(EOS), ForbidIndentedApplication, (0, import_lib3.$E)(CatchParameter), RestoreIndentedApplication, InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7) {
13676
+ var ws = $1;
13677
+ var open = $2;
13678
+ var param = $5;
13679
+ var close = $7;
13680
+ if (!param)
13681
+ return $skip;
13682
+ return [ws, open, param, close];
13683
+ });
13653
13684
  var CatchBind$$ = [CatchBind$0, CatchBind$1];
13654
13685
  function CatchBind(ctx, state2) {
13655
13686
  return (0, import_lib3.$EVENT_C)(ctx, state2, "CatchBind", CatchBind$$);
@@ -17055,6 +17086,19 @@ ${js}`
17055
17086
  function MaybeNestedType(ctx, state2) {
17056
17087
  return (0, import_lib3.$EVENT_C)(ctx, state2, "MaybeNestedType", MaybeNestedType$$);
17057
17088
  }
17089
+ var MaybeNestedTypePrimary$0 = NestedTypeBulletedTuple;
17090
+ var MaybeNestedTypePrimary$1 = NestedInterfaceBlock;
17091
+ var MaybeNestedTypePrimary$2 = NestedTypeBinaryChain;
17092
+ var MaybeNestedTypePrimary$3 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, Type)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
17093
+ if (!$2)
17094
+ return $skip;
17095
+ return $2;
17096
+ });
17097
+ var MaybeNestedTypePrimary$4 = TypePrimary;
17098
+ var MaybeNestedTypePrimary$$ = [MaybeNestedTypePrimary$0, MaybeNestedTypePrimary$1, MaybeNestedTypePrimary$2, MaybeNestedTypePrimary$3, MaybeNestedTypePrimary$4];
17099
+ function MaybeNestedTypePrimary(ctx, state2) {
17100
+ return (0, import_lib3.$EVENT_C)(ctx, state2, "MaybeNestedTypePrimary", MaybeNestedTypePrimary$$);
17101
+ }
17058
17102
  var ReturnTypeSuffix$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$E)(_), (0, import_lib3.$E)(QuestionMark), (0, import_lib3.$E)(_), Colon, ReturnType), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
17059
17103
  var optional = $2;
17060
17104
  var t = $5;
@@ -17762,7 +17806,7 @@ ${js}`
17762
17806
  function TypeParameters(ctx, state2) {
17763
17807
  return (0, import_lib3.$EVENT)(ctx, state2, "TypeParameters", TypeParameters$0);
17764
17808
  }
17765
- var TypeParameter$0 = (0, import_lib3.$S)(__, (0, import_lib3.$E)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($L173, 'TypeParameter "const"'), (0, import_lib3.$E)(_))), Identifier, (0, import_lib3.$E)(TypeConstraint), (0, import_lib3.$E)(TypeInitializer), TypeParameterDelimiter);
17809
+ var TypeParameter$0 = (0, import_lib3.$S)(__, (0, import_lib3.$Q)((0, import_lib3.$S)((0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R91, "TypeParameter /const|in|out/")), _)), Identifier, (0, import_lib3.$E)(TypeConstraint), (0, import_lib3.$E)(TypeInitializer), TypeParameterDelimiter);
17766
17810
  function TypeParameter(ctx, state2) {
17767
17811
  return (0, import_lib3.$EVENT)(ctx, state2, "TypeParameter", TypeParameter$0);
17768
17812
  }
@@ -17789,15 +17833,15 @@ ${js}`
17789
17833
  function ThisType(ctx, state2) {
17790
17834
  return (0, import_lib3.$EVENT)(ctx, state2, "ThisType", ThisType$0);
17791
17835
  }
17792
- var Shebang$0 = (0, import_lib3.$S)((0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R91, "Shebang /#![^\\r\\n]*/")), EOL);
17836
+ var Shebang$0 = (0, import_lib3.$S)((0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R92, "Shebang /#![^\\r\\n]*/")), EOL);
17793
17837
  function Shebang(ctx, state2) {
17794
17838
  return (0, import_lib3.$EVENT)(ctx, state2, "Shebang", Shebang$0);
17795
17839
  }
17796
- var CivetPrologue$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($R92, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, SimpleStatementDelimiter, (0, import_lib3.$EXPECT)($R20, "CivetPrologue /[ \\t]*/"), (0, import_lib3.$C)(EOL, (0, import_lib3.$Y)(RestOfLine))), function(value) {
17840
+ var CivetPrologue$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($R93, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, SimpleStatementDelimiter, (0, import_lib3.$EXPECT)($R20, "CivetPrologue /[ \\t]*/"), (0, import_lib3.$C)(EOL, (0, import_lib3.$Y)(RestOfLine))), function(value) {
17797
17841
  var content = value[2];
17798
17842
  return content;
17799
17843
  });
17800
- var CivetPrologue$1 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($R92, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, SimpleStatementDelimiter, (0, import_lib3.$EXPECT)($R20, "CivetPrologue /[ \\t]*/"), (0, import_lib3.$C)(EOL, (0, import_lib3.$Y)(RestOfLine))), function(value) {
17844
+ var CivetPrologue$1 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($R93, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, SimpleStatementDelimiter, (0, import_lib3.$EXPECT)($R20, "CivetPrologue /[ \\t]*/"), (0, import_lib3.$C)(EOL, (0, import_lib3.$Y)(RestOfLine))), function(value) {
17801
17845
  var content = value[2];
17802
17846
  return content;
17803
17847
  });
@@ -17805,7 +17849,7 @@ ${js}`
17805
17849
  function CivetPrologue(ctx, state2) {
17806
17850
  return (0, import_lib3.$EVENT_C)(ctx, state2, "CivetPrologue", CivetPrologue$$);
17807
17851
  }
17808
- var CivetPrologueContent$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($L238, 'CivetPrologueContent "civet"'), NonIdContinue, (0, import_lib3.$Q)(CivetOption), (0, import_lib3.$EXPECT)($R93, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3, $4) {
17852
+ var CivetPrologueContent$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($L238, 'CivetPrologueContent "civet"'), NonIdContinue, (0, import_lib3.$Q)(CivetOption), (0, import_lib3.$EXPECT)($R94, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3, $4) {
17809
17853
  var options = $3;
17810
17854
  return {
17811
17855
  type: "CivetPrologue",
@@ -17816,7 +17860,7 @@ ${js}`
17816
17860
  function CivetPrologueContent(ctx, state2) {
17817
17861
  return (0, import_lib3.$EVENT)(ctx, state2, "CivetPrologueContent", CivetPrologueContent$0);
17818
17862
  }
17819
- var CivetOption$0 = (0, import_lib3.$TR)((0, import_lib3.$EXPECT)($R94, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([\\p{ID_Continue}.,+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
17863
+ var CivetOption$0 = (0, import_lib3.$TR)((0, import_lib3.$EXPECT)($R95, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([\\p{ID_Continue}.,+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
17820
17864
  const optionName = $2.replace(/-+([a-z]?)/g, (_2, l) => {
17821
17865
  if (l)
17822
17866
  return l.toUpperCase();
@@ -17838,11 +17882,11 @@ ${js}`
17838
17882
  function CivetOption(ctx, state2) {
17839
17883
  return (0, import_lib3.$EVENT)(ctx, state2, "CivetOption", CivetOption$0);
17840
17884
  }
17841
- var UnknownPrologue$0 = (0, import_lib3.$S)((0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R92, "UnknownPrologue /[\\t ]*/")), StringLiteral, (0, import_lib3.$TEXT)(SimpleStatementDelimiter), EOS);
17885
+ var UnknownPrologue$0 = (0, import_lib3.$S)((0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R93, "UnknownPrologue /[\\t ]*/")), StringLiteral, (0, import_lib3.$TEXT)(SimpleStatementDelimiter), EOS);
17842
17886
  function UnknownPrologue(ctx, state2) {
17843
17887
  return (0, import_lib3.$EVENT)(ctx, state2, "UnknownPrologue", UnknownPrologue$0);
17844
17888
  }
17845
- var TripleSlashDirective$0 = (0, import_lib3.$S)((0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R95, "TripleSlashDirective /\\/\\/\\/[^\\r\\n]*/")), (0, import_lib3.$E)(EOS));
17889
+ var TripleSlashDirective$0 = (0, import_lib3.$S)((0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R96, "TripleSlashDirective /\\/\\/\\/[^\\r\\n]*/")), (0, import_lib3.$E)(EOS));
17846
17890
  function TripleSlashDirective(ctx, state2) {
17847
17891
  return (0, import_lib3.$EVENT)(ctx, state2, "TripleSlashDirective", TripleSlashDirective$0);
17848
17892
  }
@@ -17858,13 +17902,13 @@ ${js}`
17858
17902
  function PrologueString(ctx, state2) {
17859
17903
  return (0, import_lib3.$EVENT_C)(ctx, state2, "PrologueString", PrologueString$$);
17860
17904
  }
17861
- var EOS$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($R96, "EOS /(?=[ \\t\\r\\n\\/#]|$)/"), (0, import_lib3.$P)(RestOfLine)), function(value) {
17905
+ var EOS$0 = (0, import_lib3.$T)((0, import_lib3.$S)((0, import_lib3.$EXPECT)($R97, "EOS /(?=[ \\t\\r\\n\\/#]|$)/"), (0, import_lib3.$P)(RestOfLine)), function(value) {
17862
17906
  return value[1];
17863
17907
  });
17864
17908
  function EOS(ctx, state2) {
17865
17909
  return (0, import_lib3.$EVENT)(ctx, state2, "EOS", EOS$0);
17866
17910
  }
17867
- var EOL$0 = (0, import_lib3.$TR)((0, import_lib3.$EXPECT)($R97, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
17911
+ var EOL$0 = (0, import_lib3.$TR)((0, import_lib3.$EXPECT)($R98, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
17868
17912
  return { $loc, token: $0 };
17869
17913
  });
17870
17914
  function EOL(ctx, state2) {
@@ -18264,7 +18308,7 @@ ${js}`
18264
18308
  function Prologue(ctx, state2) {
18265
18309
  return (0, import_lib3.$EVENT)(ctx, state2, "Prologue", Prologue$0);
18266
18310
  }
18267
- var ProloguePrefix$0 = (0, import_lib3.$S)(Prologue, (0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R98, "ProloguePrefix /[^]*/")));
18311
+ var ProloguePrefix$0 = (0, import_lib3.$S)(Prologue, (0, import_lib3.$R$0)((0, import_lib3.$EXPECT)($R99, "ProloguePrefix /[^]*/")));
18268
18312
  function ProloguePrefix(ctx, state2) {
18269
18313
  return (0, import_lib3.$EVENT)(ctx, state2, "ProloguePrefix", ProloguePrefix$0);
18270
18314
  }
package/dist/civet CHANGED
@@ -419,26 +419,35 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
419
419
  prefix + (coffee ? "(do ->\n" : "async do\n") + rest.replace(/^/gm, " ") + (coffee ? ")" : ""),
420
420
  { ...options, filename, ast: true }
421
421
  );
422
- import_main.lib.gatherRecursive(ast, ($) => $.type === "BlockStatement").forEach((topBlock) => {
423
- return import_main.lib.gatherRecursiveWithinFunction(topBlock, ($1) => $1.type === "Declaration").forEach((decl) => {
424
- const type = decl.children.shift();
422
+ let ref1;
423
+ if (coffee) {
424
+ ref1 = import_main.lib.gatherRecursive(ast.children, ($) => $.type === "BlockStatement")[0];
425
+ } else {
426
+ ref1 = import_main.lib.gatherRecursive(ast.children, ($1) => $1.type === "DoStatement")[0].block;
427
+ }
428
+ ;
429
+ const topBlock = ref1;
430
+ for (let ref2 = topBlock.expressions, i3 = 0, len2 = ref2.length; i3 < len2; i3++) {
431
+ const [, statement] = ref2[i3];
432
+ if (typeof statement === "object" && statement != null && "type" in statement && statement.type === "Declaration") {
433
+ statement.children.shift();
425
434
  if (!Array.isArray(ast)) {
426
435
  ast = [ast];
427
436
  }
428
- return ast.unshift(`var ${decl.names.join(",")};`);
429
- });
430
- });
437
+ ast.unshift(`var ${statement.names.join(",")};`);
438
+ }
439
+ }
431
440
  }
432
441
  let errors = [];
433
442
  try {
434
- output = (0, import_main.generate)(ast, { errors });
443
+ output = (0, import_main.generate)(ast, { ...options, errors, sourceMap: void 0 });
435
444
  } catch (error) {
436
445
  console.error(error);
437
446
  return callback(null, void 0);
438
447
  }
439
448
  if (errors.length) {
440
449
  errors = [];
441
- (0, import_main.generate)(ast, { errors, sourceMap: (0, import_main.SourceMap)(input) });
450
+ (0, import_main.generate)(ast, { ...options, errors, sourceMap: (0, import_main.SourceMap)(input) });
442
451
  showError2(errors[0]);
443
452
  return callback(null, void 0);
444
453
  }
@@ -546,7 +555,8 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
546
555
  const unpluginOptions = {
547
556
  ...options,
548
557
  ts: options.js ? "civet" : "preserve",
549
- outputExtension: ".tsx"
558
+ outputExtension: ".tsx",
559
+ declarationExtension: options.outputExt?.replace(/\.[jt]sx?$/i, ".d.ts")
550
560
  };
551
561
  (unpluginOptions.parseOptions ??= {}).rewriteCivetImports = ".civet.jsx";
552
562
  unplugin = (0, import_unplugin.rawPlugin)(unpluginOptions, { framework: "civet-cli" });
@@ -559,8 +569,16 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
559
569
  if (options.repl) {
560
570
  return repl(args, options);
561
571
  }
572
+ process.stdout.on("error", (e) => {
573
+ if (["EPIPE", "EOF"].includes(e.code)) {
574
+ return process.exit(0);
575
+ } else {
576
+ console.error(e);
577
+ return process.exit(1);
578
+ }
579
+ });
562
580
  let errors = 0;
563
- for await (const { filename, error, content, stdin } of readFiles(filenames, options.eval)) {
581
+ for await (let { filename, error, content, stdin } of readFiles(filenames, options.eval)) {
564
582
  if (error) {
565
583
  console.error(`${filename} failed to load:`);
566
584
  console.error(error);
@@ -583,14 +601,6 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
583
601
  errors++;
584
602
  continue;
585
603
  }
586
- process.stdout.on("error", (e) => {
587
- if (["EPIPE", "EOF"].includes(e.code)) {
588
- return process.exit(0);
589
- } else {
590
- console.error(e);
591
- return process.exit(1);
592
- }
593
- });
594
604
  if (options.ast) {
595
605
  process.stdout.write(JSON.stringify(output, null, 2));
596
606
  } else if (options.compile) {
@@ -626,14 +636,24 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
626
636
  }
627
637
  }
628
638
  } else if (options.run) {
629
- const esm = /^\s*(import|export)\b/m.test(output);
639
+ let ref3;
640
+ {
641
+ if (typeof output === "string" && /\b(await|import|export)\b/.test(output)) {
642
+ const ast = await (0, import_main.compile)(content, { ...options, ast: true, filename });
643
+ ref3 = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast) || import_main.lib.hasExportDeclaration(ast);
644
+ } else {
645
+ ref3 = void 0;
646
+ }
647
+ }
648
+ ;
649
+ const esm = ref3;
630
650
  if (esm) {
631
651
  if (stdin) {
632
- const filename2 = `.stdin-${process.pid}.civet`;
652
+ filename = `.stdin-${process.pid}.civet`;
633
653
  try {
634
- await import_promises.default.writeFile(filename2, content, { encoding });
654
+ await import_promises.default.writeFile(filename, content, { encoding });
635
655
  } catch (e) {
636
- console.error(`Could not write ${filename2} for Civet ESM mode:`);
656
+ console.error(`Could not write ${filename} for Civet ESM mode:`);
637
657
  console.error(e);
638
658
  process.exit(1);
639
659
  }
@@ -706,9 +726,9 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
706
726
  }
707
727
  }, !filenames.length);
708
728
  } catch (error) {
709
- let ref1;
710
- if (ref1 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
711
- const match = ref1;
729
+ let ref4;
730
+ if (ref4 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
731
+ const match = ref4;
712
732
  return process.exitCode = Math.min(255, errors + +match[1]);
713
733
  } else {
714
734
  process.exitCode = 1;