@danielx/civet 0.4.7 → 0.4.9

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/dist/browser.js CHANGED
@@ -456,6 +456,7 @@ var Civet = (() => {
456
456
  SuperProperty,
457
457
  MetaProperty,
458
458
  Parameters,
459
+ NonEmptyParameters,
459
460
  ParameterElement,
460
461
  ParameterElementDelimiter,
461
462
  BindingIdentifier,
@@ -476,6 +477,7 @@ var Civet = (() => {
476
477
  Arrow,
477
478
  Block,
478
479
  BracedOrEmptyBlock,
480
+ EmptyBlock,
479
481
  BracedBlock,
480
482
  SingleNestedExpression,
481
483
  NestedBlockExpressions,
@@ -587,9 +589,8 @@ var Civet = (() => {
587
589
  TripleDoubleStringCharacters,
588
590
  TripleSingleStringCharacters,
589
591
  CoffeeStringSubstitution,
590
- CoffeeCompat,
591
- CoffeeCompatDoubleQuotedString,
592
- CoffeeCompatDoubleQuotedStringCharacters,
592
+ CoffeeInterpolatedDoubleQuotedString,
593
+ CoffeeDoubleQuotedStringCharacters,
593
594
  RegularExpressionLiteral,
594
595
  RegularExpressionBody,
595
596
  RegExpCharacter,
@@ -717,6 +718,10 @@ var Civet = (() => {
717
718
  TypeConstraint,
718
719
  TypeParameterDelimiter,
719
720
  Shebang,
721
+ CivetPrologue,
722
+ CivetPrologueContent,
723
+ CivetOption,
724
+ UnknownPrologue,
720
725
  DirectivePrologue,
721
726
  EOS,
722
727
  EOL,
@@ -733,6 +738,8 @@ var Civet = (() => {
733
738
  InsertSpace,
734
739
  InsertDot,
735
740
  InsertBreak,
741
+ CoffeeCommentEnabled,
742
+ CoffeeInterpolationEnabled,
736
743
  Reset,
737
744
  Init,
738
745
  Indent,
@@ -884,8 +891,9 @@ var Civet = (() => {
884
891
  var $L138 = $L("keyof");
885
892
  var $L139 = $L("infer");
886
893
  var $L140 = $L("[]");
887
- var $L141 = $L(" ");
888
- var $L142 = $L(" ");
894
+ var $L141 = $L("civet");
895
+ var $L142 = $L(" ");
896
+ var $L143 = $L(" ");
889
897
  var $R0 = $R(new RegExp("(of)(?!\\p{ID_Continue})", "suy"));
890
898
  var $R1 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
891
899
  var $R2 = $R(new RegExp("[!~+-]", "suy"));
@@ -922,8 +930,10 @@ var Civet = (() => {
922
930
  var $R33 = $R(new RegExp("[+-]", "suy"));
923
931
  var $R34 = $R(new RegExp("#![^\\r\\n]*", "suy"));
924
932
  var $R35 = $R(new RegExp("[\\t ]*", "suy"));
925
- var $R36 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
926
- var $R37 = $R(new RegExp("$", "suy"));
933
+ var $R36 = $R(new RegExp("[\\s]*", "suy"));
934
+ var $R37 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)", "suy"));
935
+ var $R38 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
936
+ var $R39 = $R(new RegExp("$", "suy"));
927
937
  var Program$0 = $S(Reset, Init, __, $Q(TopLevelStatement), __);
928
938
  function Program(state) {
929
939
  if (state.verbose)
@@ -1179,7 +1189,19 @@ var Civet = (() => {
1179
1189
  }
1180
1190
  }
1181
1191
  var ArrowFunction$0 = ThinArrowFunction;
1182
- var ArrowFunction$1 = $S(Parameters, $E(ReturnTypeSuffix), FatArrow, FatArrowBody);
1192
+ var ArrowFunction$1 = $TS($S(Parameters, $E(ReturnTypeSuffix), FatArrow, FatArrowBody), function($skip, $loc, $0, $1, $2, $3, $4) {
1193
+ var suffix = $2;
1194
+ var expOrBlock = $4;
1195
+ const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1196
+ const isBlock = expOrBlock.type === "BlockStatement";
1197
+ if (module.config.implicitReturns && !isVoid && isBlock) {
1198
+ module.addImplicitReturns(expOrBlock);
1199
+ }
1200
+ return {
1201
+ type: "FunctionExpression",
1202
+ children: $0
1203
+ };
1204
+ });
1183
1205
  function ArrowFunction(state) {
1184
1206
  if (state.tokenize) {
1185
1207
  return $TOKEN("ArrowFunction", state, ArrowFunction$0(state) || ArrowFunction$1(state));
@@ -1202,11 +1224,17 @@ var Civet = (() => {
1202
1224
  return FatArrow$0(state);
1203
1225
  }
1204
1226
  }
1205
- var FatArrowBody$0 = $S(__, OpenBrace, EOS, NestedBlockExpressions, __, CloseBrace);
1206
- var FatArrowBody$1 = $S(InsertOpenBrace, EOS, NestedBlockExpressions, InsertNewline, InsertIndent, InsertCloseBrace);
1227
+ var FatArrowBody$0 = $T($S(__, OpenBrace, EOS, NestedBlockExpressions, __, CloseBrace), function(value) {
1228
+ var exps = value[3];
1229
+ return { "type": "BlockStatement", "expressions": exps, "children": value };
1230
+ });
1231
+ var FatArrowBody$1 = $T($S(InsertOpenBrace, EOS, NestedBlockExpressions, InsertNewline, InsertIndent, InsertCloseBrace), function(value) {
1232
+ var exps = value[2];
1233
+ return { "type": "BlockStatement", "expressions": exps, "children": value };
1234
+ });
1207
1235
  var FatArrowBody$2 = AssignmentExpression;
1208
1236
  var FatArrowBody$3 = $S(__, AssignmentExpression);
1209
- var FatArrowBody$4 = $S(InsertOpenBrace, InsertCloseBrace);
1237
+ var FatArrowBody$4 = EmptyBlock;
1210
1238
  function FatArrowBody(state) {
1211
1239
  if (state.tokenize) {
1212
1240
  return $TOKEN("FatArrowBody", state, FatArrowBody$0(state) || FatArrowBody$1(state) || FatArrowBody$2(state) || FatArrowBody$3(state) || FatArrowBody$4(state));
@@ -1522,7 +1550,7 @@ var Civet = (() => {
1522
1550
  return MetaProperty$0(state) || MetaProperty$1(state);
1523
1551
  }
1524
1552
  }
1525
- var Parameters$0 = $S($E(TypeParameters), OpenParen, $Q(ParameterElement), __, CloseParen);
1553
+ var Parameters$0 = NonEmptyParameters;
1526
1554
  var Parameters$1 = $TV($EXPECT($L1, fail, 'Parameters ""'), function($skip, $loc, $0, $1) {
1527
1555
  return { $loc, token: "()" };
1528
1556
  });
@@ -1533,6 +1561,16 @@ var Civet = (() => {
1533
1561
  return Parameters$0(state) || Parameters$1(state);
1534
1562
  }
1535
1563
  }
1564
+ var NonEmptyParameters$0 = $S($E(TypeParameters), OpenParen, $Q(ParameterElement), __, CloseParen);
1565
+ function NonEmptyParameters(state) {
1566
+ if (state.verbose)
1567
+ console.log("ENTER:", "NonEmptyParameters");
1568
+ if (state.tokenize) {
1569
+ return $TOKEN("NonEmptyParameters", state, NonEmptyParameters$0(state));
1570
+ } else {
1571
+ return NonEmptyParameters$0(state);
1572
+ }
1573
+ }
1536
1574
  var ParameterElement$0 = $S(__, $C(BindingIdentifier, BindingPattern), $E(TypeSuffix), $E(Initializer), ParameterElementDelimiter);
1537
1575
  function ParameterElement(state) {
1538
1576
  if (state.verbose)
@@ -1701,8 +1739,17 @@ var Civet = (() => {
1701
1739
  }
1702
1740
  }
1703
1741
  var FunctionExpression$0 = ThinArrowFunction;
1704
- var FunctionExpression$1 = $T($S($E($S(Async, __)), Function, $E($S(Star, __)), $E(BindingIdentifier), __, Parameters, $E(ReturnTypeSuffix), BracedBlock), function(value) {
1705
- return { "type": "FunctionExpression", "children": value };
1742
+ var FunctionExpression$1 = $TS($S($E($S(Async, __)), Function, $E($S(Star, __)), $E(BindingIdentifier), __, Parameters, $E(ReturnTypeSuffix), BracedBlock), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8) {
1743
+ var suffix = $7;
1744
+ var block = $8;
1745
+ const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1746
+ if (module.config.implicitReturns && !isVoid) {
1747
+ module.addImplicitReturns(block);
1748
+ }
1749
+ return {
1750
+ type: "FunctionExpression",
1751
+ children: $0
1752
+ };
1706
1753
  });
1707
1754
  function FunctionExpression(state) {
1708
1755
  if (state.tokenize) {
@@ -1716,7 +1763,8 @@ var Civet = (() => {
1716
1763
  var suffix = $2;
1717
1764
  var arrow = $4;
1718
1765
  var block = $5;
1719
- if (module.implicitReturns && suffix?.children[3] !== "void") {
1766
+ const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1767
+ if (module.config.implicitReturns && !isVoid) {
1720
1768
  block = module.addImplicitReturns(block);
1721
1769
  }
1722
1770
  return {
@@ -1768,9 +1816,7 @@ var Civet = (() => {
1768
1816
  }
1769
1817
  }
1770
1818
  var BracedOrEmptyBlock$0 = BracedBlock;
1771
- var BracedOrEmptyBlock$1 = $T($S(InsertOpenBrace, InsertCloseBrace), function(value) {
1772
- return { "type": "BlockStatement", "expressions": [], "children": value };
1773
- });
1819
+ var BracedOrEmptyBlock$1 = EmptyBlock;
1774
1820
  function BracedOrEmptyBlock(state) {
1775
1821
  if (state.tokenize) {
1776
1822
  return $TOKEN("BracedOrEmptyBlock", state, BracedOrEmptyBlock$0(state) || BracedOrEmptyBlock$1(state));
@@ -1778,6 +1824,18 @@ var Civet = (() => {
1778
1824
  return BracedOrEmptyBlock$0(state) || BracedOrEmptyBlock$1(state);
1779
1825
  }
1780
1826
  }
1827
+ var EmptyBlock$0 = $T($S(InsertOpenBrace, InsertCloseBrace), function(value) {
1828
+ return { "type": "BlockStatement", "expressions": [], "children": value };
1829
+ });
1830
+ function EmptyBlock(state) {
1831
+ if (state.verbose)
1832
+ console.log("ENTER:", "EmptyBlock");
1833
+ if (state.tokenize) {
1834
+ return $TOKEN("EmptyBlock", state, EmptyBlock$0(state));
1835
+ } else {
1836
+ return EmptyBlock$0(state);
1837
+ }
1838
+ }
1781
1839
  var BracedBlock$0 = $T($S(__, OpenBrace, EOS, NestedBlockExpressions, __, CloseBrace), function(value) {
1782
1840
  var exps = value[3];
1783
1841
  return { "type": "BlockStatement", "expressions": exps, "children": value };
@@ -2101,7 +2159,17 @@ var Civet = (() => {
2101
2159
  return PropertyName$0(state) || PropertyName$1(state) || PropertyName$2(state) || PropertyName$3(state);
2102
2160
  }
2103
2161
  }
2104
- var MethodDefinition$0 = $S(MethodSignature, BracedBlock);
2162
+ var MethodDefinition$0 = $TS($S(MethodSignature, BracedBlock), function($skip, $loc, $0, $1, $2) {
2163
+ var sig = $1;
2164
+ var block = $2;
2165
+ const isConstructor = sig.name === "constructor";
2166
+ const isVoid = sig.returnType === "void";
2167
+ const isSet = sig.modifier === "set";
2168
+ if (module.config.implicitReturns && !isConstructor && !isSet && !isVoid) {
2169
+ block = module.addImplicitReturns(block);
2170
+ }
2171
+ return $0;
2172
+ });
2105
2173
  function MethodDefinition(state) {
2106
2174
  if (state.verbose)
2107
2175
  console.log("ENTER:", "MethodDefinition");
@@ -2122,8 +2190,26 @@ var Civet = (() => {
2122
2190
  return MethodModifier$0(state) || MethodModifier$1(state) || MethodModifier$2(state) || MethodModifier$3(state);
2123
2191
  }
2124
2192
  }
2125
- var MethodSignature$0 = $S(ConstructorShorthand, Parameters);
2126
- var MethodSignature$1 = $S($E(MethodModifier), ClassElementName, $Q(_), Parameters);
2193
+ var MethodSignature$0 = $TS($S(ConstructorShorthand, Parameters), function($skip, $loc, $0, $1, $2) {
2194
+ return {
2195
+ type: "MethodSignature",
2196
+ children: $0,
2197
+ name: $1.token,
2198
+ returnType: void 0
2199
+ };
2200
+ });
2201
+ var MethodSignature$1 = $TS($S($E(MethodModifier), ClassElementName, $Q(_), NonEmptyParameters, $E(ReturnTypeSuffix)), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
2202
+ var name = $2;
2203
+ var suffix = $5;
2204
+ name = name.token.match(/^(?:"|')/) ? name.token.slice(1, -1) : name.token;
2205
+ return {
2206
+ type: "MethodSignature",
2207
+ children: $0,
2208
+ name,
2209
+ modifier: $1?.[0]?.token,
2210
+ returnType: void 0
2211
+ };
2212
+ });
2127
2213
  function MethodSignature(state) {
2128
2214
  if (state.tokenize) {
2129
2215
  return $TOKEN("MethodSignature", state, MethodSignature$0(state) || MethodSignature$1(state));
@@ -2140,7 +2226,12 @@ var Civet = (() => {
2140
2226
  return ClassElementName$0(state) || ClassElementName$1(state);
2141
2227
  }
2142
2228
  }
2143
- var PrivateIdentifier$0 = $S($EXPECT($L8, fail, 'PrivateIdentifier "#"'), IdentifierName);
2229
+ var PrivateIdentifier$0 = $TV($TEXT($S($EXPECT($L8, fail, 'PrivateIdentifier "#"'), IdentifierName)), function($skip, $loc, $0, $1) {
2230
+ return {
2231
+ $loc,
2232
+ token: $1
2233
+ };
2234
+ });
2144
2235
  function PrivateIdentifier(state) {
2145
2236
  if (state.verbose)
2146
2237
  console.log("ENTER:", "PrivateIdentifier");
@@ -2215,7 +2306,7 @@ var Civet = (() => {
2215
2306
  var BinaryOpSymbol$12 = $EXPECT($L53, fail, 'BinaryOpSymbol ">"');
2216
2307
  var BinaryOpSymbol$13 = $EXPECT($L54, fail, 'BinaryOpSymbol "!=="');
2217
2308
  var BinaryOpSymbol$14 = $TV($EXPECT($L55, fail, 'BinaryOpSymbol "!="'), function($skip, $loc, $0, $1) {
2218
- if (module.coffeeCompat)
2309
+ if (module.config.coffeeEq)
2219
2310
  return "!==";
2220
2311
  return $1;
2221
2312
  });
@@ -2224,7 +2315,7 @@ var Civet = (() => {
2224
2315
  });
2225
2316
  var BinaryOpSymbol$16 = $EXPECT($L57, fail, 'BinaryOpSymbol "==="');
2226
2317
  var BinaryOpSymbol$17 = $TV($EXPECT($L58, fail, 'BinaryOpSymbol "=="'), function($skip, $loc, $0, $1) {
2227
- if (module.coffeeCompat)
2318
+ if (module.config.coffeeEq)
2228
2319
  return "===";
2229
2320
  return $1;
2230
2321
  });
@@ -2345,7 +2436,10 @@ var Civet = (() => {
2345
2436
  return EmptyStatement$0(state);
2346
2437
  }
2347
2438
  }
2348
- var BlockStatement$0 = $S(__, OpenBrace, EOS, NestedBlockExpressions, __, CloseBrace);
2439
+ var BlockStatement$0 = $T($S(__, OpenBrace, EOS, NestedBlockExpressions, __, CloseBrace), function(value) {
2440
+ var exps = value[3];
2441
+ return { "type": "BlockStatement", "children": value, "expressions": exps };
2442
+ });
2349
2443
  function BlockStatement(state) {
2350
2444
  if (state.verbose)
2351
2445
  console.log("ENTER:", "BlockStatement");
@@ -3135,7 +3229,7 @@ var Civet = (() => {
3135
3229
  var e = $3;
3136
3230
  return [s, module.dedentBlockString(str), e];
3137
3231
  });
3138
- var StringLiteral$2 = CoffeeCompatDoubleQuotedString;
3232
+ var StringLiteral$2 = CoffeeInterpolatedDoubleQuotedString;
3139
3233
  var StringLiteral$3 = BasicStringLiteral;
3140
3234
  function StringLiteral(state) {
3141
3235
  if (state.tokenize) {
@@ -3223,21 +3317,7 @@ var Civet = (() => {
3223
3317
  return CoffeeStringSubstitution$0(state);
3224
3318
  }
3225
3319
  }
3226
- var CoffeeCompat$0 = $TV($EXPECT($L1, fail, 'CoffeeCompat ""'), function($skip, $loc, $0, $1) {
3227
- if (module.coffeeCompat)
3228
- return;
3229
- return $skip;
3230
- });
3231
- function CoffeeCompat(state) {
3232
- if (state.verbose)
3233
- console.log("ENTER:", "CoffeeCompat");
3234
- if (state.tokenize) {
3235
- return $TOKEN("CoffeeCompat", state, CoffeeCompat$0(state));
3236
- } else {
3237
- return CoffeeCompat$0(state);
3238
- }
3239
- }
3240
- var CoffeeCompatDoubleQuotedString$0 = $TS($S(CoffeeCompat, DoubleQuote, $Q($C(CoffeeCompatDoubleQuotedStringCharacters, CoffeeStringSubstitution)), DoubleQuote), function($skip, $loc, $0, $1, $2, $3, $4) {
3320
+ var CoffeeInterpolatedDoubleQuotedString$0 = $TS($S(CoffeeInterpolationEnabled, DoubleQuote, $Q($C(CoffeeDoubleQuotedStringCharacters, CoffeeStringSubstitution)), DoubleQuote), function($skip, $loc, $0, $1, $2, $3, $4) {
3241
3321
  var s = $2;
3242
3322
  var parts = $3;
3243
3323
  var e = $4;
@@ -3257,25 +3337,25 @@ var Civet = (() => {
3257
3337
  s.token = e.token = "`";
3258
3338
  return [s, parts, e];
3259
3339
  });
3260
- function CoffeeCompatDoubleQuotedString(state) {
3340
+ function CoffeeInterpolatedDoubleQuotedString(state) {
3261
3341
  if (state.verbose)
3262
- console.log("ENTER:", "CoffeeCompatDoubleQuotedString");
3342
+ console.log("ENTER:", "CoffeeInterpolatedDoubleQuotedString");
3263
3343
  if (state.tokenize) {
3264
- return $TOKEN("CoffeeCompatDoubleQuotedString", state, CoffeeCompatDoubleQuotedString$0(state));
3344
+ return $TOKEN("CoffeeInterpolatedDoubleQuotedString", state, CoffeeInterpolatedDoubleQuotedString$0(state));
3265
3345
  } else {
3266
- return CoffeeCompatDoubleQuotedString$0(state);
3346
+ return CoffeeInterpolatedDoubleQuotedString$0(state);
3267
3347
  }
3268
3348
  }
3269
- var CoffeeCompatDoubleQuotedStringCharacters$0 = $TR($EXPECT($R13, fail, 'CoffeeCompatDoubleQuotedStringCharacters /(?:\\\\.|#(?!\\{)|[^"#])+/'), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3349
+ var CoffeeDoubleQuotedStringCharacters$0 = $TR($EXPECT($R13, fail, 'CoffeeDoubleQuotedStringCharacters /(?:\\\\.|#(?!\\{)|[^"#])+/'), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3270
3350
  return { $loc, token: $0 };
3271
3351
  });
3272
- function CoffeeCompatDoubleQuotedStringCharacters(state) {
3352
+ function CoffeeDoubleQuotedStringCharacters(state) {
3273
3353
  if (state.verbose)
3274
- console.log("ENTER:", "CoffeeCompatDoubleQuotedStringCharacters");
3354
+ console.log("ENTER:", "CoffeeDoubleQuotedStringCharacters");
3275
3355
  if (state.tokenize) {
3276
- return $TOKEN("CoffeeCompatDoubleQuotedStringCharacters", state, CoffeeCompatDoubleQuotedStringCharacters$0(state));
3356
+ return $TOKEN("CoffeeDoubleQuotedStringCharacters", state, CoffeeDoubleQuotedStringCharacters$0(state));
3277
3357
  } else {
3278
- return CoffeeCompatDoubleQuotedStringCharacters$0(state);
3358
+ return CoffeeDoubleQuotedStringCharacters$0(state);
3279
3359
  }
3280
3360
  }
3281
3361
  var RegularExpressionLiteral$0 = $TV($TEXT($S($EXPECT($L44, fail, 'RegularExpressionLiteral "/"'), RegularExpressionBody, $EXPECT($L44, fail, 'RegularExpressionLiteral "/"'), RegularExpressionFlags)), function($skip, $loc, $0, $1) {
@@ -3387,7 +3467,7 @@ var Civet = (() => {
3387
3467
  var SingleLineComment$0 = $TR($EXPECT($R20, fail, "SingleLineComment /\\/\\/[^\\r\\n]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3388
3468
  return { $loc, token: $0 };
3389
3469
  });
3390
- var SingleLineComment$1 = $S(CoffeeCompat, CoffeeSingleLineComment);
3470
+ var SingleLineComment$1 = $S(CoffeeCommentEnabled, CoffeeSingleLineComment);
3391
3471
  function SingleLineComment(state) {
3392
3472
  if (state.tokenize) {
3393
3473
  return $TOKEN("SingleLineComment", state, SingleLineComment$0(state) || SingleLineComment$1(state));
@@ -4413,7 +4493,7 @@ var Civet = (() => {
4413
4493
  }
4414
4494
  }
4415
4495
  var InterfaceProperty$0 = $S($C(TypeIndexSignature, PropertyName), TypeSuffix, InterfacePropertyDelimiter);
4416
- var InterfaceProperty$1 = $S(MethodSignature, $E(TypeSuffix));
4496
+ var InterfaceProperty$1 = MethodSignature;
4417
4497
  function InterfaceProperty(state) {
4418
4498
  if (state.tokenize) {
4419
4499
  return $TOKEN("InterfaceProperty", state, InterfaceProperty$0(state) || InterfaceProperty$1(state));
@@ -4491,7 +4571,7 @@ var Civet = (() => {
4491
4571
  }
4492
4572
  }
4493
4573
  var TypeSuffix$0 = $T($S($E(QuestionMark), __, Colon, Type), function(value) {
4494
- return { "ts": true, "children": value };
4574
+ return { "type": "TypeSuffix", "ts": true, "children": value };
4495
4575
  });
4496
4576
  function TypeSuffix(state) {
4497
4577
  if (state.verbose)
@@ -4502,8 +4582,16 @@ var Civet = (() => {
4502
4582
  return TypeSuffix$0(state);
4503
4583
  }
4504
4584
  }
4505
- var ReturnTypeSuffix$0 = $T($S(__, Colon, $E($S(__, $EXPECT($L137, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function(value) {
4506
- return { "ts": true, "children": value };
4585
+ var ReturnTypeSuffix$0 = $TS($S(__, Colon, $E($S(__, $EXPECT($L137, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2, $3, $4) {
4586
+ if (!$3)
4587
+ $0.splice(2, 1);
4588
+ if ($1.length === 0)
4589
+ $0.shift();
4590
+ return {
4591
+ type: "ReturnTypeAnnotation",
4592
+ children: $0,
4593
+ ts: true
4594
+ };
4507
4595
  });
4508
4596
  function ReturnTypeSuffix(state) {
4509
4597
  if (state.verbose)
@@ -4514,7 +4602,11 @@ var Civet = (() => {
4514
4602
  return ReturnTypeSuffix$0(state);
4515
4603
  }
4516
4604
  }
4517
- var TypePredicate$0 = $S(Type, $E($S(__, $EXPECT($L56, fail, 'TypePredicate "is"'), NonIdContinue, Type)));
4605
+ var TypePredicate$0 = $TS($S(Type, $E($S(__, $EXPECT($L56, fail, 'TypePredicate "is"'), NonIdContinue, Type))), function($skip, $loc, $0, $1, $2) {
4606
+ if (!$2)
4607
+ return $1;
4608
+ return $0;
4609
+ });
4518
4610
  function TypePredicate(state) {
4519
4611
  if (state.verbose)
4520
4612
  console.log("ENTER:", "TypePredicate");
@@ -4534,7 +4626,11 @@ var Civet = (() => {
4534
4626
  return Type$0(state);
4535
4627
  }
4536
4628
  }
4537
- var TypeBinary$0 = $S(TypeUnary, $Q($S(__, TypeBinaryOp, __, TypeUnary)));
4629
+ var TypeBinary$0 = $TS($S(TypeUnary, $Q($S(__, TypeBinaryOp, __, TypeUnary))), function($skip, $loc, $0, $1, $2) {
4630
+ if ($2.length)
4631
+ return $0;
4632
+ return $1;
4633
+ });
4538
4634
  function TypeBinary(state) {
4539
4635
  if (state.verbose)
4540
4636
  console.log("ENTER:", "TypeBinary");
@@ -4544,7 +4640,13 @@ var Civet = (() => {
4544
4640
  return TypeBinary$0(state);
4545
4641
  }
4546
4642
  }
4547
- var TypeUnary$0 = $S($Q($S(__, TypeUnaryOp, NonIdContinue)), TypePrimary, $Q(TypeUnarySuffix));
4643
+ var TypeUnary$0 = $TS($S($Q($S(__, TypeUnaryOp, NonIdContinue)), TypePrimary, $Q(TypeUnarySuffix)), function($skip, $loc, $0, $1, $2, $3) {
4644
+ if (!$3.length)
4645
+ $0.pop();
4646
+ if (!$1.length)
4647
+ $0.shift();
4648
+ return $0;
4649
+ });
4548
4650
  function TypeUnary(state) {
4549
4651
  if (state.verbose)
4550
4652
  console.log("ENTER:", "TypeUnary");
@@ -4587,8 +4689,8 @@ var Civet = (() => {
4587
4689
  var TypePrimary$0 = InterfaceBlock;
4588
4690
  var TypePrimary$1 = $S(__, OpenParen, Type, __, CloseParen);
4589
4691
  var TypePrimary$2 = $S($Q(_), FunctionType);
4590
- var TypePrimary$3 = $S($Q(_), IdentifierName, $Q($S(Dot, IdentifierName)), $E(TypeArguments));
4591
- var TypePrimary$4 = $S($Q(_), TypeLiteral);
4692
+ var TypePrimary$3 = $S($Q(_), TypeLiteral);
4693
+ var TypePrimary$4 = $S($Q(_), IdentifierName, $Q($S(Dot, IdentifierName)), $E(TypeArguments));
4592
4694
  function TypePrimary(state) {
4593
4695
  if (state.tokenize) {
4594
4696
  return $TOKEN("TypePrimary", state, TypePrimary$0(state) || TypePrimary$1(state) || TypePrimary$2(state) || TypePrimary$3(state) || TypePrimary$4(state));
@@ -4596,7 +4698,11 @@ var Civet = (() => {
4596
4698
  return TypePrimary$0(state) || TypePrimary$1(state) || TypePrimary$2(state) || TypePrimary$3(state) || TypePrimary$4(state);
4597
4699
  }
4598
4700
  }
4599
- var TypeConditional$0 = $S(TypeBinary, $E($S(__, $EXPECT($L6, fail, 'TypeConditional "extends"'), Type, $E($S(__, QuestionMark, Type, __, Colon, Type)))));
4701
+ var TypeConditional$0 = $TS($S(TypeBinary, $E($S(__, $EXPECT($L6, fail, 'TypeConditional "extends"'), Type, $E($S(__, QuestionMark, Type, __, Colon, Type))))), function($skip, $loc, $0, $1, $2) {
4702
+ if ($2)
4703
+ return $0;
4704
+ return $1;
4705
+ });
4600
4706
  function TypeConditional(state) {
4601
4707
  if (state.verbose)
4602
4708
  console.log("ENTER:", "TypeConditional");
@@ -4607,8 +4713,12 @@ var Civet = (() => {
4607
4713
  }
4608
4714
  }
4609
4715
  var TypeLiteral$0 = Literal;
4610
- var TypeLiteral$1 = $EXPECT($L70, fail, 'TypeLiteral "void"');
4611
- var TypeLiteral$2 = $EXPECT($L140, fail, 'TypeLiteral "[]"');
4716
+ var TypeLiteral$1 = $TV($EXPECT($L70, fail, 'TypeLiteral "void"'), function($skip, $loc, $0, $1) {
4717
+ return { $loc, token: "void" };
4718
+ });
4719
+ var TypeLiteral$2 = $TV($EXPECT($L140, fail, 'TypeLiteral "[]"'), function($skip, $loc, $0, $1) {
4720
+ return { $loc, token: "[]" };
4721
+ });
4612
4722
  function TypeLiteral(state) {
4613
4723
  if (state.tokenize) {
4614
4724
  return $TOKEN("TypeLiteral", state, TypeLiteral$0(state) || TypeLiteral$1(state) || TypeLiteral$2(state));
@@ -4616,8 +4726,12 @@ var Civet = (() => {
4616
4726
  return TypeLiteral$0(state) || TypeLiteral$1(state) || TypeLiteral$2(state);
4617
4727
  }
4618
4728
  }
4619
- var TypeBinaryOp$0 = $EXPECT($L68, fail, 'TypeBinaryOp "|"');
4620
- var TypeBinaryOp$1 = $EXPECT($L66, fail, 'TypeBinaryOp "&"');
4729
+ var TypeBinaryOp$0 = $TV($EXPECT($L68, fail, 'TypeBinaryOp "|"'), function($skip, $loc, $0, $1) {
4730
+ return { $loc, token: "|" };
4731
+ });
4732
+ var TypeBinaryOp$1 = $TV($EXPECT($L66, fail, 'TypeBinaryOp "&"'), function($skip, $loc, $0, $1) {
4733
+ return { $loc, token: "&" };
4734
+ });
4621
4735
  function TypeBinaryOp(state) {
4622
4736
  if (state.tokenize) {
4623
4737
  return $TOKEN("TypeBinaryOp", state, TypeBinaryOp$0(state) || TypeBinaryOp$1(state));
@@ -4702,14 +4816,73 @@ var Civet = (() => {
4702
4816
  return Shebang$0(state);
4703
4817
  }
4704
4818
  }
4705
- var DirectivePrologue$0 = $Q($S($R$0($EXPECT($R35, fail, "DirectivePrologue /[\\t ]*/")), StringLiteral, $TEXT(StatementDelimiter), EOS));
4706
- function DirectivePrologue(state) {
4819
+ var CivetPrologue$0 = $T($S($EXPECT($R35, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
4820
+ var content = value[2];
4821
+ return content;
4822
+ });
4823
+ var CivetPrologue$1 = $T($S($EXPECT($R35, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
4824
+ var content = value[2];
4825
+ return content;
4826
+ });
4827
+ function CivetPrologue(state) {
4828
+ if (state.tokenize) {
4829
+ return $TOKEN("CivetPrologue", state, CivetPrologue$0(state) || CivetPrologue$1(state));
4830
+ } else {
4831
+ return CivetPrologue$0(state) || CivetPrologue$1(state);
4832
+ }
4833
+ }
4834
+ var CivetPrologueContent$0 = $TS($S($EXPECT($L141, fail, 'CivetPrologueContent "civet"'), $Q(CivetOption), $EXPECT($R36, fail, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3) {
4835
+ var options = $2;
4836
+ return {
4837
+ type: "CivetPrologue",
4838
+ children: [],
4839
+ config: Object.fromEntries(options)
4840
+ };
4841
+ });
4842
+ function CivetPrologueContent(state) {
4843
+ if (state.verbose)
4844
+ console.log("ENTER:", "CivetPrologueContent");
4845
+ if (state.tokenize) {
4846
+ return $TOKEN("CivetPrologueContent", state, CivetPrologueContent$0(state));
4847
+ } else {
4848
+ return CivetPrologueContent$0(state);
4849
+ }
4850
+ }
4851
+ var CivetOption$0 = $TR($EXPECT($R37, fail, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
4852
+ const optionName = $2.toLowerCase().replace(/-+([a-z]?)/g, (_2, l) => {
4853
+ if (l)
4854
+ return l.toUpperCase();
4855
+ return "";
4856
+ });
4857
+ const value = $1 === "-" ? false : true;
4858
+ return [optionName, value];
4859
+ });
4860
+ function CivetOption(state) {
4707
4861
  if (state.verbose)
4708
- console.log("ENTER:", "DirectivePrologue");
4862
+ console.log("ENTER:", "CivetOption");
4709
4863
  if (state.tokenize) {
4710
- return $TOKEN("DirectivePrologue", state, DirectivePrologue$0(state));
4864
+ return $TOKEN("CivetOption", state, CivetOption$0(state));
4711
4865
  } else {
4712
- return DirectivePrologue$0(state);
4866
+ return CivetOption$0(state);
4867
+ }
4868
+ }
4869
+ var UnknownPrologue$0 = $S($R$0($EXPECT($R35, fail, "UnknownPrologue /[\\t ]*/")), BasicStringLiteral, $TEXT(StatementDelimiter), EOS);
4870
+ function UnknownPrologue(state) {
4871
+ if (state.verbose)
4872
+ console.log("ENTER:", "UnknownPrologue");
4873
+ if (state.tokenize) {
4874
+ return $TOKEN("UnknownPrologue", state, UnknownPrologue$0(state));
4875
+ } else {
4876
+ return UnknownPrologue$0(state);
4877
+ }
4878
+ }
4879
+ var DirectivePrologue$0 = CivetPrologue;
4880
+ var DirectivePrologue$1 = UnknownPrologue;
4881
+ function DirectivePrologue(state) {
4882
+ if (state.tokenize) {
4883
+ return $TOKEN("DirectivePrologue", state, DirectivePrologue$0(state) || DirectivePrologue$1(state));
4884
+ } else {
4885
+ return DirectivePrologue$0(state) || DirectivePrologue$1(state);
4713
4886
  }
4714
4887
  }
4715
4888
  var EOS$0 = $P(RestOfLine);
@@ -4722,7 +4895,7 @@ var Civet = (() => {
4722
4895
  return EOS$0(state);
4723
4896
  }
4724
4897
  }
4725
- var EOL$0 = $R$0($EXPECT($R36, fail, "EOL /\\r\\n|\\n|\\r|$/"));
4898
+ var EOL$0 = $R$0($EXPECT($R38, fail, "EOL /\\r\\n|\\n|\\r|$/"));
4726
4899
  function EOL(state) {
4727
4900
  if (state.verbose)
4728
4901
  console.log("ENTER:", "EOL");
@@ -4732,7 +4905,7 @@ var Civet = (() => {
4732
4905
  return EOL$0(state);
4733
4906
  }
4734
4907
  }
4735
- var EOF$0 = $R$0($EXPECT($R37, fail, "EOF /$/"));
4908
+ var EOF$0 = $R$0($EXPECT($R39, fail, "EOF /$/"));
4736
4909
  function EOF(state) {
4737
4910
  if (state.verbose)
4738
4911
  console.log("ENTER:", "EOF");
@@ -4886,12 +5059,65 @@ var Civet = (() => {
4886
5059
  return InsertBreak$0(state);
4887
5060
  }
4888
5061
  }
5062
+ var CoffeeCommentEnabled$0 = $TV($EXPECT($L1, fail, 'CoffeeCommentEnabled ""'), function($skip, $loc, $0, $1) {
5063
+ if (module.config.coffeeComment)
5064
+ return;
5065
+ return $skip;
5066
+ });
5067
+ function CoffeeCommentEnabled(state) {
5068
+ if (state.verbose)
5069
+ console.log("ENTER:", "CoffeeCommentEnabled");
5070
+ if (state.tokenize) {
5071
+ return $TOKEN("CoffeeCommentEnabled", state, CoffeeCommentEnabled$0(state));
5072
+ } else {
5073
+ return CoffeeCommentEnabled$0(state);
5074
+ }
5075
+ }
5076
+ var CoffeeInterpolationEnabled$0 = $TV($EXPECT($L1, fail, 'CoffeeInterpolationEnabled ""'), function($skip, $loc, $0, $1) {
5077
+ if (module.config.coffeeInterpolation)
5078
+ return;
5079
+ return $skip;
5080
+ });
5081
+ function CoffeeInterpolationEnabled(state) {
5082
+ if (state.verbose)
5083
+ console.log("ENTER:", "CoffeeInterpolationEnabled");
5084
+ if (state.tokenize) {
5085
+ return $TOKEN("CoffeeInterpolationEnabled", state, CoffeeInterpolationEnabled$0(state));
5086
+ } else {
5087
+ return CoffeeInterpolationEnabled$0(state);
5088
+ }
5089
+ }
4889
5090
  var Reset$0 = $TV($EXPECT($L1, fail, 'Reset ""'), function($skip, $loc, $0, $1) {
4890
5091
  module.currentIndent = 0;
4891
5092
  module.indentLevels = [0];
4892
5093
  module.verbose = false;
4893
- module.coffeeCompat = false;
4894
- module.implicitReturns = true;
5094
+ module.config = {
5095
+ autoVar: false,
5096
+ coffeeComment: false,
5097
+ coffeeEq: false,
5098
+ coffeeInterpolation: false,
5099
+ implicitReturns: true
5100
+ };
5101
+ Object.defineProperty(module.config, "coffeeCompat", {
5102
+ set(b) {
5103
+ if (b) {
5104
+ this.autoVar = true;
5105
+ this.coffeeComment = true;
5106
+ this.coffeeEq = true;
5107
+ this.coffeeInterpolation = true;
5108
+ this.implicitReturns = true;
5109
+ } else {
5110
+ this.autoVar = false;
5111
+ this.coffeeComment = false;
5112
+ this.coffeeEq = false;
5113
+ this.coffeeInterpolation = false;
5114
+ this.implicitReturns = false;
5115
+ }
5116
+ }
5117
+ });
5118
+ module.modifyString = function(str) {
5119
+ return str.replace(/(?<!\\)(\\\\)*\n/g, "$1\\n");
5120
+ };
4895
5121
  });
4896
5122
  function Reset(state) {
4897
5123
  if (state.verbose)
@@ -4902,12 +5128,13 @@ var Civet = (() => {
4902
5128
  return Reset$0(state);
4903
5129
  }
4904
5130
  }
4905
- var Init$0 = $TS($S($E(Shebang), DirectivePrologue, $EXPECT($L1, fail, 'Init ""')), function($skip, $loc, $0, $1, $2, $3) {
5131
+ var Init$0 = $TS($S($E(Shebang), $Q(DirectivePrologue), $EXPECT($L1, fail, 'Init ""')), function($skip, $loc, $0, $1, $2, $3) {
4906
5132
  var directives = $2;
4907
- if (directives) {
4908
- const compatRe = /use coffee-compat/;
4909
- module.coffeeCompat = directives.some((d) => d[1].token?.match(compatRe));
4910
- }
5133
+ directives.forEach((directive) => {
5134
+ if (directive.type === "CivetPrologue") {
5135
+ Object.assign(module.config, directive.config);
5136
+ }
5137
+ });
4911
5138
  function hasReturnStatement(node) {
4912
5139
  if (!node)
4913
5140
  return false;
@@ -4949,7 +5176,6 @@ var Civet = (() => {
4949
5176
  if (!Array.isArray(node))
4950
5177
  return;
4951
5178
  const [, exp] = node;
4952
- debugger;
4953
5179
  if (!exp)
4954
5180
  return;
4955
5181
  switch (exp.type) {
@@ -4961,8 +5187,10 @@ var Civet = (() => {
4961
5187
  case "ThrowStatement":
4962
5188
  case "VariableDeclaration":
4963
5189
  return;
5190
+ case "BlockStatement":
5191
+ insertReturn(exp.expressions[exp.expressions.length - 1]);
5192
+ return;
4964
5193
  case "IfStatement":
4965
- debugger;
4966
5194
  insertReturn(exp.children[2]);
4967
5195
  if (exp.children[3])
4968
5196
  insertReturn(exp.children[3][2]);
@@ -5019,9 +5247,6 @@ var Civet = (() => {
5019
5247
  }
5020
5248
  return spacing;
5021
5249
  };
5022
- module.modifyString = function(str) {
5023
- return str.replace(/(?<!\\)(\\\\)*\n/g, "$1\\n");
5024
- };
5025
5250
  module.dedentBlockSubstitutions = function($02) {
5026
5251
  const [s, strWithSubstitutions, e] = $02;
5027
5252
  if (strWithSubstitutions.length === 0) {
@@ -5082,7 +5307,7 @@ var Civet = (() => {
5082
5307
  return Init$0(state);
5083
5308
  }
5084
5309
  }
5085
- var Indent$0 = $TV($Q($C($EXPECT($L141, fail, 'Indent " "'), $EXPECT($L142, fail, 'Indent "\\\\t"'))), function($skip, $loc, $0, $1) {
5310
+ var Indent$0 = $TV($Q($C($EXPECT($L142, fail, 'Indent " "'), $EXPECT($L143, fail, 'Indent "\\\\t"'))), function($skip, $loc, $0, $1) {
5086
5311
  const level = $1.length;
5087
5312
  return {
5088
5313
  $loc,