@danielx/civet 0.4.8 → 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.
Files changed (3) hide show
  1. package/dist/browser.js +168 -58
  2. package/dist/main.js +168 -58
  3. package/package.json +1 -1
package/dist/browser.js CHANGED
@@ -589,9 +589,8 @@ var Civet = (() => {
589
589
  TripleDoubleStringCharacters,
590
590
  TripleSingleStringCharacters,
591
591
  CoffeeStringSubstitution,
592
- CoffeeCompat,
593
- CoffeeCompatDoubleQuotedString,
594
- CoffeeCompatDoubleQuotedStringCharacters,
592
+ CoffeeInterpolatedDoubleQuotedString,
593
+ CoffeeDoubleQuotedStringCharacters,
595
594
  RegularExpressionLiteral,
596
595
  RegularExpressionBody,
597
596
  RegExpCharacter,
@@ -719,6 +718,10 @@ var Civet = (() => {
719
718
  TypeConstraint,
720
719
  TypeParameterDelimiter,
721
720
  Shebang,
721
+ CivetPrologue,
722
+ CivetPrologueContent,
723
+ CivetOption,
724
+ UnknownPrologue,
722
725
  DirectivePrologue,
723
726
  EOS,
724
727
  EOL,
@@ -735,6 +738,8 @@ var Civet = (() => {
735
738
  InsertSpace,
736
739
  InsertDot,
737
740
  InsertBreak,
741
+ CoffeeCommentEnabled,
742
+ CoffeeInterpolationEnabled,
738
743
  Reset,
739
744
  Init,
740
745
  Indent,
@@ -886,8 +891,9 @@ var Civet = (() => {
886
891
  var $L138 = $L("keyof");
887
892
  var $L139 = $L("infer");
888
893
  var $L140 = $L("[]");
889
- var $L141 = $L(" ");
890
- var $L142 = $L(" ");
894
+ var $L141 = $L("civet");
895
+ var $L142 = $L(" ");
896
+ var $L143 = $L(" ");
891
897
  var $R0 = $R(new RegExp("(of)(?!\\p{ID_Continue})", "suy"));
892
898
  var $R1 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
893
899
  var $R2 = $R(new RegExp("[!~+-]", "suy"));
@@ -924,8 +930,10 @@ var Civet = (() => {
924
930
  var $R33 = $R(new RegExp("[+-]", "suy"));
925
931
  var $R34 = $R(new RegExp("#![^\\r\\n]*", "suy"));
926
932
  var $R35 = $R(new RegExp("[\\t ]*", "suy"));
927
- var $R36 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
928
- 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"));
929
937
  var Program$0 = $S(Reset, Init, __, $Q(TopLevelStatement), __);
930
938
  function Program(state) {
931
939
  if (state.verbose)
@@ -1186,7 +1194,7 @@ var Civet = (() => {
1186
1194
  var expOrBlock = $4;
1187
1195
  const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1188
1196
  const isBlock = expOrBlock.type === "BlockStatement";
1189
- if (module.implicitReturns && !isVoid && isBlock) {
1197
+ if (module.config.implicitReturns && !isVoid && isBlock) {
1190
1198
  module.addImplicitReturns(expOrBlock);
1191
1199
  }
1192
1200
  return {
@@ -1735,7 +1743,7 @@ var Civet = (() => {
1735
1743
  var suffix = $7;
1736
1744
  var block = $8;
1737
1745
  const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1738
- if (module.implicitReturns && !isVoid) {
1746
+ if (module.config.implicitReturns && !isVoid) {
1739
1747
  module.addImplicitReturns(block);
1740
1748
  }
1741
1749
  return {
@@ -1756,7 +1764,7 @@ var Civet = (() => {
1756
1764
  var arrow = $4;
1757
1765
  var block = $5;
1758
1766
  const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1759
- if (module.implicitReturns && !isVoid) {
1767
+ if (module.config.implicitReturns && !isVoid) {
1760
1768
  block = module.addImplicitReturns(block);
1761
1769
  }
1762
1770
  return {
@@ -2157,7 +2165,7 @@ var Civet = (() => {
2157
2165
  const isConstructor = sig.name === "constructor";
2158
2166
  const isVoid = sig.returnType === "void";
2159
2167
  const isSet = sig.modifier === "set";
2160
- if (module.implicitReturns && !isConstructor && !isSet && !isVoid) {
2168
+ if (module.config.implicitReturns && !isConstructor && !isSet && !isVoid) {
2161
2169
  block = module.addImplicitReturns(block);
2162
2170
  }
2163
2171
  return $0;
@@ -2298,7 +2306,7 @@ var Civet = (() => {
2298
2306
  var BinaryOpSymbol$12 = $EXPECT($L53, fail, 'BinaryOpSymbol ">"');
2299
2307
  var BinaryOpSymbol$13 = $EXPECT($L54, fail, 'BinaryOpSymbol "!=="');
2300
2308
  var BinaryOpSymbol$14 = $TV($EXPECT($L55, fail, 'BinaryOpSymbol "!="'), function($skip, $loc, $0, $1) {
2301
- if (module.coffeeCompat)
2309
+ if (module.config.coffeeEq)
2302
2310
  return "!==";
2303
2311
  return $1;
2304
2312
  });
@@ -2307,7 +2315,7 @@ var Civet = (() => {
2307
2315
  });
2308
2316
  var BinaryOpSymbol$16 = $EXPECT($L57, fail, 'BinaryOpSymbol "==="');
2309
2317
  var BinaryOpSymbol$17 = $TV($EXPECT($L58, fail, 'BinaryOpSymbol "=="'), function($skip, $loc, $0, $1) {
2310
- if (module.coffeeCompat)
2318
+ if (module.config.coffeeEq)
2311
2319
  return "===";
2312
2320
  return $1;
2313
2321
  });
@@ -2428,7 +2436,10 @@ var Civet = (() => {
2428
2436
  return EmptyStatement$0(state);
2429
2437
  }
2430
2438
  }
2431
- 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
+ });
2432
2443
  function BlockStatement(state) {
2433
2444
  if (state.verbose)
2434
2445
  console.log("ENTER:", "BlockStatement");
@@ -3218,7 +3229,7 @@ var Civet = (() => {
3218
3229
  var e = $3;
3219
3230
  return [s, module.dedentBlockString(str), e];
3220
3231
  });
3221
- var StringLiteral$2 = CoffeeCompatDoubleQuotedString;
3232
+ var StringLiteral$2 = CoffeeInterpolatedDoubleQuotedString;
3222
3233
  var StringLiteral$3 = BasicStringLiteral;
3223
3234
  function StringLiteral(state) {
3224
3235
  if (state.tokenize) {
@@ -3306,21 +3317,7 @@ var Civet = (() => {
3306
3317
  return CoffeeStringSubstitution$0(state);
3307
3318
  }
3308
3319
  }
3309
- var CoffeeCompat$0 = $TV($EXPECT($L1, fail, 'CoffeeCompat ""'), function($skip, $loc, $0, $1) {
3310
- if (module.coffeeCompat)
3311
- return;
3312
- return $skip;
3313
- });
3314
- function CoffeeCompat(state) {
3315
- if (state.verbose)
3316
- console.log("ENTER:", "CoffeeCompat");
3317
- if (state.tokenize) {
3318
- return $TOKEN("CoffeeCompat", state, CoffeeCompat$0(state));
3319
- } else {
3320
- return CoffeeCompat$0(state);
3321
- }
3322
- }
3323
- 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) {
3324
3321
  var s = $2;
3325
3322
  var parts = $3;
3326
3323
  var e = $4;
@@ -3340,25 +3337,25 @@ var Civet = (() => {
3340
3337
  s.token = e.token = "`";
3341
3338
  return [s, parts, e];
3342
3339
  });
3343
- function CoffeeCompatDoubleQuotedString(state) {
3340
+ function CoffeeInterpolatedDoubleQuotedString(state) {
3344
3341
  if (state.verbose)
3345
- console.log("ENTER:", "CoffeeCompatDoubleQuotedString");
3342
+ console.log("ENTER:", "CoffeeInterpolatedDoubleQuotedString");
3346
3343
  if (state.tokenize) {
3347
- return $TOKEN("CoffeeCompatDoubleQuotedString", state, CoffeeCompatDoubleQuotedString$0(state));
3344
+ return $TOKEN("CoffeeInterpolatedDoubleQuotedString", state, CoffeeInterpolatedDoubleQuotedString$0(state));
3348
3345
  } else {
3349
- return CoffeeCompatDoubleQuotedString$0(state);
3346
+ return CoffeeInterpolatedDoubleQuotedString$0(state);
3350
3347
  }
3351
3348
  }
3352
- 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) {
3353
3350
  return { $loc, token: $0 };
3354
3351
  });
3355
- function CoffeeCompatDoubleQuotedStringCharacters(state) {
3352
+ function CoffeeDoubleQuotedStringCharacters(state) {
3356
3353
  if (state.verbose)
3357
- console.log("ENTER:", "CoffeeCompatDoubleQuotedStringCharacters");
3354
+ console.log("ENTER:", "CoffeeDoubleQuotedStringCharacters");
3358
3355
  if (state.tokenize) {
3359
- return $TOKEN("CoffeeCompatDoubleQuotedStringCharacters", state, CoffeeCompatDoubleQuotedStringCharacters$0(state));
3356
+ return $TOKEN("CoffeeDoubleQuotedStringCharacters", state, CoffeeDoubleQuotedStringCharacters$0(state));
3360
3357
  } else {
3361
- return CoffeeCompatDoubleQuotedStringCharacters$0(state);
3358
+ return CoffeeDoubleQuotedStringCharacters$0(state);
3362
3359
  }
3363
3360
  }
3364
3361
  var RegularExpressionLiteral$0 = $TV($TEXT($S($EXPECT($L44, fail, 'RegularExpressionLiteral "/"'), RegularExpressionBody, $EXPECT($L44, fail, 'RegularExpressionLiteral "/"'), RegularExpressionFlags)), function($skip, $loc, $0, $1) {
@@ -3470,7 +3467,7 @@ var Civet = (() => {
3470
3467
  var SingleLineComment$0 = $TR($EXPECT($R20, fail, "SingleLineComment /\\/\\/[^\\r\\n]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3471
3468
  return { $loc, token: $0 };
3472
3469
  });
3473
- var SingleLineComment$1 = $S(CoffeeCompat, CoffeeSingleLineComment);
3470
+ var SingleLineComment$1 = $S(CoffeeCommentEnabled, CoffeeSingleLineComment);
3474
3471
  function SingleLineComment(state) {
3475
3472
  if (state.tokenize) {
3476
3473
  return $TOKEN("SingleLineComment", state, SingleLineComment$0(state) || SingleLineComment$1(state));
@@ -4819,14 +4816,73 @@ var Civet = (() => {
4819
4816
  return Shebang$0(state);
4820
4817
  }
4821
4818
  }
4822
- var DirectivePrologue$0 = $Q($S($R$0($EXPECT($R35, fail, "DirectivePrologue /[\\t ]*/")), StringLiteral, $TEXT(StatementDelimiter), EOS));
4823
- 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) {
4824
4843
  if (state.verbose)
4825
- console.log("ENTER:", "DirectivePrologue");
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) {
4861
+ if (state.verbose)
4862
+ console.log("ENTER:", "CivetOption");
4863
+ if (state.tokenize) {
4864
+ return $TOKEN("CivetOption", state, CivetOption$0(state));
4865
+ } else {
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) {
4826
4882
  if (state.tokenize) {
4827
- return $TOKEN("DirectivePrologue", state, DirectivePrologue$0(state));
4883
+ return $TOKEN("DirectivePrologue", state, DirectivePrologue$0(state) || DirectivePrologue$1(state));
4828
4884
  } else {
4829
- return DirectivePrologue$0(state);
4885
+ return DirectivePrologue$0(state) || DirectivePrologue$1(state);
4830
4886
  }
4831
4887
  }
4832
4888
  var EOS$0 = $P(RestOfLine);
@@ -4839,7 +4895,7 @@ var Civet = (() => {
4839
4895
  return EOS$0(state);
4840
4896
  }
4841
4897
  }
4842
- 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|$/"));
4843
4899
  function EOL(state) {
4844
4900
  if (state.verbose)
4845
4901
  console.log("ENTER:", "EOL");
@@ -4849,7 +4905,7 @@ var Civet = (() => {
4849
4905
  return EOL$0(state);
4850
4906
  }
4851
4907
  }
4852
- var EOF$0 = $R$0($EXPECT($R37, fail, "EOF /$/"));
4908
+ var EOF$0 = $R$0($EXPECT($R39, fail, "EOF /$/"));
4853
4909
  function EOF(state) {
4854
4910
  if (state.verbose)
4855
4911
  console.log("ENTER:", "EOF");
@@ -5003,12 +5059,65 @@ var Civet = (() => {
5003
5059
  return InsertBreak$0(state);
5004
5060
  }
5005
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
+ }
5006
5090
  var Reset$0 = $TV($EXPECT($L1, fail, 'Reset ""'), function($skip, $loc, $0, $1) {
5007
5091
  module.currentIndent = 0;
5008
5092
  module.indentLevels = [0];
5009
5093
  module.verbose = false;
5010
- module.coffeeCompat = false;
5011
- 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
+ };
5012
5121
  });
5013
5122
  function Reset(state) {
5014
5123
  if (state.verbose)
@@ -5019,12 +5128,13 @@ var Civet = (() => {
5019
5128
  return Reset$0(state);
5020
5129
  }
5021
5130
  }
5022
- 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) {
5023
5132
  var directives = $2;
5024
- if (directives) {
5025
- const compatRe = /use coffee-compat/;
5026
- module.coffeeCompat = directives.some((d) => d[1].token?.match(compatRe));
5027
- }
5133
+ directives.forEach((directive) => {
5134
+ if (directive.type === "CivetPrologue") {
5135
+ Object.assign(module.config, directive.config);
5136
+ }
5137
+ });
5028
5138
  function hasReturnStatement(node) {
5029
5139
  if (!node)
5030
5140
  return false;
@@ -5077,6 +5187,9 @@ var Civet = (() => {
5077
5187
  case "ThrowStatement":
5078
5188
  case "VariableDeclaration":
5079
5189
  return;
5190
+ case "BlockStatement":
5191
+ insertReturn(exp.expressions[exp.expressions.length - 1]);
5192
+ return;
5080
5193
  case "IfStatement":
5081
5194
  insertReturn(exp.children[2]);
5082
5195
  if (exp.children[3])
@@ -5134,9 +5247,6 @@ var Civet = (() => {
5134
5247
  }
5135
5248
  return spacing;
5136
5249
  };
5137
- module.modifyString = function(str) {
5138
- return str.replace(/(?<!\\)(\\\\)*\n/g, "$1\\n");
5139
- };
5140
5250
  module.dedentBlockSubstitutions = function($02) {
5141
5251
  const [s, strWithSubstitutions, e] = $02;
5142
5252
  if (strWithSubstitutions.length === 0) {
@@ -5197,7 +5307,7 @@ var Civet = (() => {
5197
5307
  return Init$0(state);
5198
5308
  }
5199
5309
  }
5200
- 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) {
5201
5311
  const level = $1.length;
5202
5312
  return {
5203
5313
  $loc,
package/dist/main.js CHANGED
@@ -588,9 +588,8 @@ var require_parser = __commonJS({
588
588
  TripleDoubleStringCharacters,
589
589
  TripleSingleStringCharacters,
590
590
  CoffeeStringSubstitution,
591
- CoffeeCompat,
592
- CoffeeCompatDoubleQuotedString,
593
- CoffeeCompatDoubleQuotedStringCharacters,
591
+ CoffeeInterpolatedDoubleQuotedString,
592
+ CoffeeDoubleQuotedStringCharacters,
594
593
  RegularExpressionLiteral,
595
594
  RegularExpressionBody,
596
595
  RegExpCharacter,
@@ -718,6 +717,10 @@ var require_parser = __commonJS({
718
717
  TypeConstraint,
719
718
  TypeParameterDelimiter,
720
719
  Shebang,
720
+ CivetPrologue,
721
+ CivetPrologueContent,
722
+ CivetOption,
723
+ UnknownPrologue,
721
724
  DirectivePrologue,
722
725
  EOS,
723
726
  EOL,
@@ -734,6 +737,8 @@ var require_parser = __commonJS({
734
737
  InsertSpace,
735
738
  InsertDot,
736
739
  InsertBreak,
740
+ CoffeeCommentEnabled,
741
+ CoffeeInterpolationEnabled,
737
742
  Reset,
738
743
  Init,
739
744
  Indent,
@@ -885,8 +890,9 @@ var require_parser = __commonJS({
885
890
  var $L138 = $L("keyof");
886
891
  var $L139 = $L("infer");
887
892
  var $L140 = $L("[]");
888
- var $L141 = $L(" ");
889
- var $L142 = $L(" ");
893
+ var $L141 = $L("civet");
894
+ var $L142 = $L(" ");
895
+ var $L143 = $L(" ");
890
896
  var $R0 = $R(new RegExp("(of)(?!\\p{ID_Continue})", "suy"));
891
897
  var $R1 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$])*", "suy"));
892
898
  var $R2 = $R(new RegExp("[!~+-]", "suy"));
@@ -923,8 +929,10 @@ var require_parser = __commonJS({
923
929
  var $R33 = $R(new RegExp("[+-]", "suy"));
924
930
  var $R34 = $R(new RegExp("#![^\\r\\n]*", "suy"));
925
931
  var $R35 = $R(new RegExp("[\\t ]*", "suy"));
926
- var $R36 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
927
- var $R37 = $R(new RegExp("$", "suy"));
932
+ var $R36 = $R(new RegExp("[\\s]*", "suy"));
933
+ var $R37 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)", "suy"));
934
+ var $R38 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
935
+ var $R39 = $R(new RegExp("$", "suy"));
928
936
  var Program$0 = $S(Reset, Init, __, $Q(TopLevelStatement), __);
929
937
  function Program(state) {
930
938
  if (state.verbose)
@@ -1185,7 +1193,7 @@ var require_parser = __commonJS({
1185
1193
  var expOrBlock = $4;
1186
1194
  const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1187
1195
  const isBlock = expOrBlock.type === "BlockStatement";
1188
- if (module2.implicitReturns && !isVoid && isBlock) {
1196
+ if (module2.config.implicitReturns && !isVoid && isBlock) {
1189
1197
  module2.addImplicitReturns(expOrBlock);
1190
1198
  }
1191
1199
  return {
@@ -1734,7 +1742,7 @@ var require_parser = __commonJS({
1734
1742
  var suffix = $7;
1735
1743
  var block = $8;
1736
1744
  const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1737
- if (module2.implicitReturns && !isVoid) {
1745
+ if (module2.config.implicitReturns && !isVoid) {
1738
1746
  module2.addImplicitReturns(block);
1739
1747
  }
1740
1748
  return {
@@ -1755,7 +1763,7 @@ var require_parser = __commonJS({
1755
1763
  var arrow = $4;
1756
1764
  var block = $5;
1757
1765
  const isVoid = suffix?.children?.[1]?.[0]?.[1]?.token === "void";
1758
- if (module2.implicitReturns && !isVoid) {
1766
+ if (module2.config.implicitReturns && !isVoid) {
1759
1767
  block = module2.addImplicitReturns(block);
1760
1768
  }
1761
1769
  return {
@@ -2156,7 +2164,7 @@ var require_parser = __commonJS({
2156
2164
  const isConstructor = sig.name === "constructor";
2157
2165
  const isVoid = sig.returnType === "void";
2158
2166
  const isSet = sig.modifier === "set";
2159
- if (module2.implicitReturns && !isConstructor && !isSet && !isVoid) {
2167
+ if (module2.config.implicitReturns && !isConstructor && !isSet && !isVoid) {
2160
2168
  block = module2.addImplicitReturns(block);
2161
2169
  }
2162
2170
  return $0;
@@ -2297,7 +2305,7 @@ var require_parser = __commonJS({
2297
2305
  var BinaryOpSymbol$12 = $EXPECT($L53, fail, 'BinaryOpSymbol ">"');
2298
2306
  var BinaryOpSymbol$13 = $EXPECT($L54, fail, 'BinaryOpSymbol "!=="');
2299
2307
  var BinaryOpSymbol$14 = $TV($EXPECT($L55, fail, 'BinaryOpSymbol "!="'), function($skip, $loc, $0, $1) {
2300
- if (module2.coffeeCompat)
2308
+ if (module2.config.coffeeEq)
2301
2309
  return "!==";
2302
2310
  return $1;
2303
2311
  });
@@ -2306,7 +2314,7 @@ var require_parser = __commonJS({
2306
2314
  });
2307
2315
  var BinaryOpSymbol$16 = $EXPECT($L57, fail, 'BinaryOpSymbol "==="');
2308
2316
  var BinaryOpSymbol$17 = $TV($EXPECT($L58, fail, 'BinaryOpSymbol "=="'), function($skip, $loc, $0, $1) {
2309
- if (module2.coffeeCompat)
2317
+ if (module2.config.coffeeEq)
2310
2318
  return "===";
2311
2319
  return $1;
2312
2320
  });
@@ -2427,7 +2435,10 @@ var require_parser = __commonJS({
2427
2435
  return EmptyStatement$0(state);
2428
2436
  }
2429
2437
  }
2430
- var BlockStatement$0 = $S(__, OpenBrace, EOS, NestedBlockExpressions, __, CloseBrace);
2438
+ var BlockStatement$0 = $T($S(__, OpenBrace, EOS, NestedBlockExpressions, __, CloseBrace), function(value) {
2439
+ var exps = value[3];
2440
+ return { "type": "BlockStatement", "children": value, "expressions": exps };
2441
+ });
2431
2442
  function BlockStatement(state) {
2432
2443
  if (state.verbose)
2433
2444
  console.log("ENTER:", "BlockStatement");
@@ -3217,7 +3228,7 @@ var require_parser = __commonJS({
3217
3228
  var e = $3;
3218
3229
  return [s, module2.dedentBlockString(str), e];
3219
3230
  });
3220
- var StringLiteral$2 = CoffeeCompatDoubleQuotedString;
3231
+ var StringLiteral$2 = CoffeeInterpolatedDoubleQuotedString;
3221
3232
  var StringLiteral$3 = BasicStringLiteral;
3222
3233
  function StringLiteral(state) {
3223
3234
  if (state.tokenize) {
@@ -3305,21 +3316,7 @@ var require_parser = __commonJS({
3305
3316
  return CoffeeStringSubstitution$0(state);
3306
3317
  }
3307
3318
  }
3308
- var CoffeeCompat$0 = $TV($EXPECT($L1, fail, 'CoffeeCompat ""'), function($skip, $loc, $0, $1) {
3309
- if (module2.coffeeCompat)
3310
- return;
3311
- return $skip;
3312
- });
3313
- function CoffeeCompat(state) {
3314
- if (state.verbose)
3315
- console.log("ENTER:", "CoffeeCompat");
3316
- if (state.tokenize) {
3317
- return $TOKEN("CoffeeCompat", state, CoffeeCompat$0(state));
3318
- } else {
3319
- return CoffeeCompat$0(state);
3320
- }
3321
- }
3322
- var CoffeeCompatDoubleQuotedString$0 = $TS($S(CoffeeCompat, DoubleQuote, $Q($C(CoffeeCompatDoubleQuotedStringCharacters, CoffeeStringSubstitution)), DoubleQuote), function($skip, $loc, $0, $1, $2, $3, $4) {
3319
+ var CoffeeInterpolatedDoubleQuotedString$0 = $TS($S(CoffeeInterpolationEnabled, DoubleQuote, $Q($C(CoffeeDoubleQuotedStringCharacters, CoffeeStringSubstitution)), DoubleQuote), function($skip, $loc, $0, $1, $2, $3, $4) {
3323
3320
  var s = $2;
3324
3321
  var parts = $3;
3325
3322
  var e = $4;
@@ -3339,25 +3336,25 @@ var require_parser = __commonJS({
3339
3336
  s.token = e.token = "`";
3340
3337
  return [s, parts, e];
3341
3338
  });
3342
- function CoffeeCompatDoubleQuotedString(state) {
3339
+ function CoffeeInterpolatedDoubleQuotedString(state) {
3343
3340
  if (state.verbose)
3344
- console.log("ENTER:", "CoffeeCompatDoubleQuotedString");
3341
+ console.log("ENTER:", "CoffeeInterpolatedDoubleQuotedString");
3345
3342
  if (state.tokenize) {
3346
- return $TOKEN("CoffeeCompatDoubleQuotedString", state, CoffeeCompatDoubleQuotedString$0(state));
3343
+ return $TOKEN("CoffeeInterpolatedDoubleQuotedString", state, CoffeeInterpolatedDoubleQuotedString$0(state));
3347
3344
  } else {
3348
- return CoffeeCompatDoubleQuotedString$0(state);
3345
+ return CoffeeInterpolatedDoubleQuotedString$0(state);
3349
3346
  }
3350
3347
  }
3351
- var CoffeeCompatDoubleQuotedStringCharacters$0 = $TR($EXPECT($R13, fail, 'CoffeeCompatDoubleQuotedStringCharacters /(?:\\\\.|#(?!\\{)|[^"#])+/'), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3348
+ var CoffeeDoubleQuotedStringCharacters$0 = $TR($EXPECT($R13, fail, 'CoffeeDoubleQuotedStringCharacters /(?:\\\\.|#(?!\\{)|[^"#])+/'), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3352
3349
  return { $loc, token: $0 };
3353
3350
  });
3354
- function CoffeeCompatDoubleQuotedStringCharacters(state) {
3351
+ function CoffeeDoubleQuotedStringCharacters(state) {
3355
3352
  if (state.verbose)
3356
- console.log("ENTER:", "CoffeeCompatDoubleQuotedStringCharacters");
3353
+ console.log("ENTER:", "CoffeeDoubleQuotedStringCharacters");
3357
3354
  if (state.tokenize) {
3358
- return $TOKEN("CoffeeCompatDoubleQuotedStringCharacters", state, CoffeeCompatDoubleQuotedStringCharacters$0(state));
3355
+ return $TOKEN("CoffeeDoubleQuotedStringCharacters", state, CoffeeDoubleQuotedStringCharacters$0(state));
3359
3356
  } else {
3360
- return CoffeeCompatDoubleQuotedStringCharacters$0(state);
3357
+ return CoffeeDoubleQuotedStringCharacters$0(state);
3361
3358
  }
3362
3359
  }
3363
3360
  var RegularExpressionLiteral$0 = $TV($TEXT($S($EXPECT($L44, fail, 'RegularExpressionLiteral "/"'), RegularExpressionBody, $EXPECT($L44, fail, 'RegularExpressionLiteral "/"'), RegularExpressionFlags)), function($skip, $loc, $0, $1) {
@@ -3469,7 +3466,7 @@ var require_parser = __commonJS({
3469
3466
  var SingleLineComment$0 = $TR($EXPECT($R20, fail, "SingleLineComment /\\/\\/[^\\r\\n]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
3470
3467
  return { $loc, token: $0 };
3471
3468
  });
3472
- var SingleLineComment$1 = $S(CoffeeCompat, CoffeeSingleLineComment);
3469
+ var SingleLineComment$1 = $S(CoffeeCommentEnabled, CoffeeSingleLineComment);
3473
3470
  function SingleLineComment(state) {
3474
3471
  if (state.tokenize) {
3475
3472
  return $TOKEN("SingleLineComment", state, SingleLineComment$0(state) || SingleLineComment$1(state));
@@ -4818,14 +4815,73 @@ var require_parser = __commonJS({
4818
4815
  return Shebang$0(state);
4819
4816
  }
4820
4817
  }
4821
- var DirectivePrologue$0 = $Q($S($R$0($EXPECT($R35, fail, "DirectivePrologue /[\\t ]*/")), StringLiteral, $TEXT(StatementDelimiter), EOS));
4822
- function DirectivePrologue(state) {
4818
+ var CivetPrologue$0 = $T($S($EXPECT($R35, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
4819
+ var content = value[2];
4820
+ return content;
4821
+ });
4822
+ var CivetPrologue$1 = $T($S($EXPECT($R35, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
4823
+ var content = value[2];
4824
+ return content;
4825
+ });
4826
+ function CivetPrologue(state) {
4827
+ if (state.tokenize) {
4828
+ return $TOKEN("CivetPrologue", state, CivetPrologue$0(state) || CivetPrologue$1(state));
4829
+ } else {
4830
+ return CivetPrologue$0(state) || CivetPrologue$1(state);
4831
+ }
4832
+ }
4833
+ var CivetPrologueContent$0 = $TS($S($EXPECT($L141, fail, 'CivetPrologueContent "civet"'), $Q(CivetOption), $EXPECT($R36, fail, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3) {
4834
+ var options = $2;
4835
+ return {
4836
+ type: "CivetPrologue",
4837
+ children: [],
4838
+ config: Object.fromEntries(options)
4839
+ };
4840
+ });
4841
+ function CivetPrologueContent(state) {
4823
4842
  if (state.verbose)
4824
- console.log("ENTER:", "DirectivePrologue");
4843
+ console.log("ENTER:", "CivetPrologueContent");
4844
+ if (state.tokenize) {
4845
+ return $TOKEN("CivetPrologueContent", state, CivetPrologueContent$0(state));
4846
+ } else {
4847
+ return CivetPrologueContent$0(state);
4848
+ }
4849
+ }
4850
+ 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) {
4851
+ const optionName = $2.toLowerCase().replace(/-+([a-z]?)/g, (_2, l) => {
4852
+ if (l)
4853
+ return l.toUpperCase();
4854
+ return "";
4855
+ });
4856
+ const value = $1 === "-" ? false : true;
4857
+ return [optionName, value];
4858
+ });
4859
+ function CivetOption(state) {
4860
+ if (state.verbose)
4861
+ console.log("ENTER:", "CivetOption");
4862
+ if (state.tokenize) {
4863
+ return $TOKEN("CivetOption", state, CivetOption$0(state));
4864
+ } else {
4865
+ return CivetOption$0(state);
4866
+ }
4867
+ }
4868
+ var UnknownPrologue$0 = $S($R$0($EXPECT($R35, fail, "UnknownPrologue /[\\t ]*/")), BasicStringLiteral, $TEXT(StatementDelimiter), EOS);
4869
+ function UnknownPrologue(state) {
4870
+ if (state.verbose)
4871
+ console.log("ENTER:", "UnknownPrologue");
4872
+ if (state.tokenize) {
4873
+ return $TOKEN("UnknownPrologue", state, UnknownPrologue$0(state));
4874
+ } else {
4875
+ return UnknownPrologue$0(state);
4876
+ }
4877
+ }
4878
+ var DirectivePrologue$0 = CivetPrologue;
4879
+ var DirectivePrologue$1 = UnknownPrologue;
4880
+ function DirectivePrologue(state) {
4825
4881
  if (state.tokenize) {
4826
- return $TOKEN("DirectivePrologue", state, DirectivePrologue$0(state));
4882
+ return $TOKEN("DirectivePrologue", state, DirectivePrologue$0(state) || DirectivePrologue$1(state));
4827
4883
  } else {
4828
- return DirectivePrologue$0(state);
4884
+ return DirectivePrologue$0(state) || DirectivePrologue$1(state);
4829
4885
  }
4830
4886
  }
4831
4887
  var EOS$0 = $P(RestOfLine);
@@ -4838,7 +4894,7 @@ var require_parser = __commonJS({
4838
4894
  return EOS$0(state);
4839
4895
  }
4840
4896
  }
4841
- var EOL$0 = $R$0($EXPECT($R36, fail, "EOL /\\r\\n|\\n|\\r|$/"));
4897
+ var EOL$0 = $R$0($EXPECT($R38, fail, "EOL /\\r\\n|\\n|\\r|$/"));
4842
4898
  function EOL(state) {
4843
4899
  if (state.verbose)
4844
4900
  console.log("ENTER:", "EOL");
@@ -4848,7 +4904,7 @@ var require_parser = __commonJS({
4848
4904
  return EOL$0(state);
4849
4905
  }
4850
4906
  }
4851
- var EOF$0 = $R$0($EXPECT($R37, fail, "EOF /$/"));
4907
+ var EOF$0 = $R$0($EXPECT($R39, fail, "EOF /$/"));
4852
4908
  function EOF(state) {
4853
4909
  if (state.verbose)
4854
4910
  console.log("ENTER:", "EOF");
@@ -5002,12 +5058,65 @@ var require_parser = __commonJS({
5002
5058
  return InsertBreak$0(state);
5003
5059
  }
5004
5060
  }
5061
+ var CoffeeCommentEnabled$0 = $TV($EXPECT($L1, fail, 'CoffeeCommentEnabled ""'), function($skip, $loc, $0, $1) {
5062
+ if (module2.config.coffeeComment)
5063
+ return;
5064
+ return $skip;
5065
+ });
5066
+ function CoffeeCommentEnabled(state) {
5067
+ if (state.verbose)
5068
+ console.log("ENTER:", "CoffeeCommentEnabled");
5069
+ if (state.tokenize) {
5070
+ return $TOKEN("CoffeeCommentEnabled", state, CoffeeCommentEnabled$0(state));
5071
+ } else {
5072
+ return CoffeeCommentEnabled$0(state);
5073
+ }
5074
+ }
5075
+ var CoffeeInterpolationEnabled$0 = $TV($EXPECT($L1, fail, 'CoffeeInterpolationEnabled ""'), function($skip, $loc, $0, $1) {
5076
+ if (module2.config.coffeeInterpolation)
5077
+ return;
5078
+ return $skip;
5079
+ });
5080
+ function CoffeeInterpolationEnabled(state) {
5081
+ if (state.verbose)
5082
+ console.log("ENTER:", "CoffeeInterpolationEnabled");
5083
+ if (state.tokenize) {
5084
+ return $TOKEN("CoffeeInterpolationEnabled", state, CoffeeInterpolationEnabled$0(state));
5085
+ } else {
5086
+ return CoffeeInterpolationEnabled$0(state);
5087
+ }
5088
+ }
5005
5089
  var Reset$0 = $TV($EXPECT($L1, fail, 'Reset ""'), function($skip, $loc, $0, $1) {
5006
5090
  module2.currentIndent = 0;
5007
5091
  module2.indentLevels = [0];
5008
5092
  module2.verbose = false;
5009
- module2.coffeeCompat = false;
5010
- module2.implicitReturns = true;
5093
+ module2.config = {
5094
+ autoVar: false,
5095
+ coffeeComment: false,
5096
+ coffeeEq: false,
5097
+ coffeeInterpolation: false,
5098
+ implicitReturns: true
5099
+ };
5100
+ Object.defineProperty(module2.config, "coffeeCompat", {
5101
+ set(b) {
5102
+ if (b) {
5103
+ this.autoVar = true;
5104
+ this.coffeeComment = true;
5105
+ this.coffeeEq = true;
5106
+ this.coffeeInterpolation = true;
5107
+ this.implicitReturns = true;
5108
+ } else {
5109
+ this.autoVar = false;
5110
+ this.coffeeComment = false;
5111
+ this.coffeeEq = false;
5112
+ this.coffeeInterpolation = false;
5113
+ this.implicitReturns = false;
5114
+ }
5115
+ }
5116
+ });
5117
+ module2.modifyString = function(str) {
5118
+ return str.replace(/(?<!\\)(\\\\)*\n/g, "$1\\n");
5119
+ };
5011
5120
  });
5012
5121
  function Reset(state) {
5013
5122
  if (state.verbose)
@@ -5018,12 +5127,13 @@ var require_parser = __commonJS({
5018
5127
  return Reset$0(state);
5019
5128
  }
5020
5129
  }
5021
- var Init$0 = $TS($S($E(Shebang), DirectivePrologue, $EXPECT($L1, fail, 'Init ""')), function($skip, $loc, $0, $1, $2, $3) {
5130
+ var Init$0 = $TS($S($E(Shebang), $Q(DirectivePrologue), $EXPECT($L1, fail, 'Init ""')), function($skip, $loc, $0, $1, $2, $3) {
5022
5131
  var directives = $2;
5023
- if (directives) {
5024
- const compatRe = /use coffee-compat/;
5025
- module2.coffeeCompat = directives.some((d) => d[1].token?.match(compatRe));
5026
- }
5132
+ directives.forEach((directive) => {
5133
+ if (directive.type === "CivetPrologue") {
5134
+ Object.assign(module2.config, directive.config);
5135
+ }
5136
+ });
5027
5137
  function hasReturnStatement(node) {
5028
5138
  if (!node)
5029
5139
  return false;
@@ -5076,6 +5186,9 @@ var require_parser = __commonJS({
5076
5186
  case "ThrowStatement":
5077
5187
  case "VariableDeclaration":
5078
5188
  return;
5189
+ case "BlockStatement":
5190
+ insertReturn(exp.expressions[exp.expressions.length - 1]);
5191
+ return;
5079
5192
  case "IfStatement":
5080
5193
  insertReturn(exp.children[2]);
5081
5194
  if (exp.children[3])
@@ -5133,9 +5246,6 @@ var require_parser = __commonJS({
5133
5246
  }
5134
5247
  return spacing;
5135
5248
  };
5136
- module2.modifyString = function(str) {
5137
- return str.replace(/(?<!\\)(\\\\)*\n/g, "$1\\n");
5138
- };
5139
5249
  module2.dedentBlockSubstitutions = function($02) {
5140
5250
  const [s, strWithSubstitutions, e] = $02;
5141
5251
  if (strWithSubstitutions.length === 0) {
@@ -5196,7 +5306,7 @@ var require_parser = __commonJS({
5196
5306
  return Init$0(state);
5197
5307
  }
5198
5308
  }
5199
- var Indent$0 = $TV($Q($C($EXPECT($L141, fail, 'Indent " "'), $EXPECT($L142, fail, 'Indent "\\\\t"'))), function($skip, $loc, $0, $1) {
5309
+ var Indent$0 = $TV($Q($C($EXPECT($L142, fail, 'Indent " "'), $EXPECT($L143, fail, 'Indent "\\\\t"'))), function($skip, $loc, $0, $1) {
5200
5310
  const level = $1.length;
5201
5311
  return {
5202
5312
  $loc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.4.8",
3
+ "version": "0.4.9",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {