@danielx/civet 0.5.17 → 0.5.19

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/README.md CHANGED
@@ -239,6 +239,7 @@ Things Added that CoffeeScript didn't
239
239
  `"civet solid server"` for server-only code (SSR only), or
240
240
  `"civet solid client server"` for isomorphic code that runs on
241
241
  client and server (SSR + hydration).
242
+ - XML comments: `<!-- ... -->` → `{/* ... */}`
242
243
  - CoffeeScript improvements
243
244
  - Postfix loop `run() loop` → `while(true) run()`
244
245
  - Character range literals `["a".."z"]`, `['f'..'a']`, `['0'..'9']`
package/dist/browser.js CHANGED
@@ -799,6 +799,8 @@ ${input.slice(result.pos)}
799
799
  JSXChildren,
800
800
  JSXNestedChildren,
801
801
  JSXChild,
802
+ JSXComment,
803
+ JSXCommentContent,
802
804
  JSXText,
803
805
  JSXChildExpression,
804
806
  TypeDeclaration,
@@ -1045,15 +1047,17 @@ ${input.slice(result.pos)}
1045
1047
  var $L154 = $L("</");
1046
1048
  var $L155 = $L("<>");
1047
1049
  var $L156 = $L("</>");
1048
- var $L157 = $L("declare");
1049
- var $L158 = $L("type");
1050
- var $L159 = $L("interface");
1051
- var $L160 = $L("namespace");
1052
- var $L161 = $L("asserts");
1053
- var $L162 = $L("keyof");
1054
- var $L163 = $L("infer");
1055
- var $L164 = $L("[]");
1056
- var $L165 = $L("civet");
1050
+ var $L157 = $L("<!--");
1051
+ var $L158 = $L("-->");
1052
+ var $L159 = $L("declare");
1053
+ var $L160 = $L("type");
1054
+ var $L161 = $L("interface");
1055
+ var $L162 = $L("namespace");
1056
+ var $L163 = $L("asserts");
1057
+ var $L164 = $L("keyof");
1058
+ var $L165 = $L("infer");
1059
+ var $L166 = $L("[]");
1060
+ var $L167 = $L("civet");
1057
1061
  var $R0 = $R(new RegExp("(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
1058
1062
  var $R1 = $R(new RegExp("[&]", "suy"));
1059
1063
  var $R2 = $R(new RegExp("[!~+-]+", "suy"));
@@ -1101,14 +1105,15 @@ ${input.slice(result.pos)}
1101
1105
  var $R44 = $R(new RegExp("\\s", "suy"));
1102
1106
  var $R45 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$-])*", "suy"));
1103
1107
  var $R46 = $R(new RegExp("(?:[\\w\\-:]+|\\([^()]*\\)|\\[[^\\[\\]]*\\])+", "suy"));
1104
- var $R47 = $R(new RegExp("[^{}<>\\r\\n]+", "suy"));
1105
- var $R48 = $R(new RegExp("[+-]?", "suy"));
1106
- var $R49 = $R(new RegExp("#![^\\r\\n]*", "suy"));
1107
- var $R50 = $R(new RegExp("[\\t ]*", "suy"));
1108
- var $R51 = $R(new RegExp("[\\s]*", "suy"));
1109
- var $R52 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
1110
- var $R53 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
1111
- var $R54 = $R(new RegExp("[ \\t]*", "suy"));
1108
+ var $R47 = $R(new RegExp("(?:-[^-]|[^-]*)*", "suy"));
1109
+ var $R48 = $R(new RegExp("[^{}<>\\r\\n]+", "suy"));
1110
+ var $R49 = $R(new RegExp("[+-]?", "suy"));
1111
+ var $R50 = $R(new RegExp("#![^\\r\\n]*", "suy"));
1112
+ var $R51 = $R(new RegExp("[\\t ]*", "suy"));
1113
+ var $R52 = $R(new RegExp("[\\s]*", "suy"));
1114
+ var $R53 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
1115
+ var $R54 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
1116
+ var $R55 = $R(new RegExp("[ \\t]*", "suy"));
1112
1117
  var Program$0 = $TS($S(Reset, Init, __, $Q(TopLevelStatement), __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
1113
1118
  var statements = $4;
1114
1119
  module.processProgram(statements);
@@ -11113,8 +11118,10 @@ ${input.slice(result.pos)}
11113
11118
  return true;
11114
11119
  });
11115
11120
  if (classes.length) {
11116
- let braced = function(c) {
11121
+ let isBraced = function(c) {
11117
11122
  return c[0] === "{" || c[0]?.token === "{";
11123
+ }, unbrace = function(c) {
11124
+ return c.slice(1, -1);
11118
11125
  }, parseClass = function(c) {
11119
11126
  c = c.token || c;
11120
11127
  if (c.startsWith("'")) {
@@ -11132,21 +11139,25 @@ ${input.slice(result.pos)}
11132
11139
  }
11133
11140
  return true;
11134
11141
  });
11142
+ const strings = [], exprs = [];
11143
+ classes.forEach((c) => {
11144
+ if (isBraced(c)) {
11145
+ exprs.push(unbrace(c));
11146
+ exprs.push(", ");
11147
+ } else {
11148
+ strings.push(parseClass(c));
11149
+ }
11150
+ });
11151
+ const stringPart = strings.filter(Boolean).join(" ");
11135
11152
  let classValue;
11136
- if (classes.some(braced)) {
11137
- classValue = ["{`"];
11138
- classes.forEach((c, i) => {
11139
- if (i > 0)
11140
- classValue.push(" ");
11141
- if (braced(c)) {
11142
- classValue.push("$", c);
11143
- } else {
11144
- classValue.push(parseClass(c));
11145
- }
11146
- });
11147
- classValue.push("`}");
11153
+ if (exprs.length) {
11154
+ exprs.pop();
11155
+ if (stringPart) {
11156
+ exprs.unshift(JSON.stringify(stringPart), ", ");
11157
+ }
11158
+ classValue = ["{[", ...exprs, '].filter(Boolean).join(" ")}'];
11148
11159
  } else {
11149
- classValue = JSON.stringify(classes.map(parseClass).join(" "));
11160
+ classValue = JSON.stringify(stringPart);
11150
11161
  }
11151
11162
  attrs.splice(0, 0, [" ", [className, ["=", classValue]]]);
11152
11163
  }
@@ -11700,7 +11711,8 @@ ${input.slice(result.pos)}
11700
11711
  }
11701
11712
  var JSXChild$0 = JSXElement;
11702
11713
  var JSXChild$1 = JSXFragment;
11703
- var JSXChild$2 = $TS($S(OpenBrace, $E(JSXChildExpression), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4) {
11714
+ var JSXChild$2 = JSXComment;
11715
+ var JSXChild$3 = $TS($S(OpenBrace, $E(JSXChildExpression), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4) {
11704
11716
  var expression = $2;
11705
11717
  return {
11706
11718
  type: "JSXChildExpression",
@@ -11708,7 +11720,7 @@ ${input.slice(result.pos)}
11708
11720
  expression
11709
11721
  };
11710
11722
  });
11711
- var JSXChild$3 = $TS($S(InsertInlineOpenBrace, ArrowFunction, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3) {
11723
+ var JSXChild$4 = $TS($S(InsertInlineOpenBrace, ArrowFunction, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3) {
11712
11724
  var expression = $2;
11713
11725
  return {
11714
11726
  type: "JSXChildExpression",
@@ -11716,7 +11728,7 @@ ${input.slice(result.pos)}
11716
11728
  expression
11717
11729
  };
11718
11730
  });
11719
- var JSXChild$4 = JSXText;
11731
+ var JSXChild$5 = JSXText;
11720
11732
  function JSXChild(state) {
11721
11733
  if (state.events) {
11722
11734
  const result = state.events.enter?.("JSXChild", state);
@@ -11724,18 +11736,60 @@ ${input.slice(result.pos)}
11724
11736
  return result.cache;
11725
11737
  }
11726
11738
  if (state.tokenize) {
11727
- const result = $TOKEN("JSXChild", state, JSXChild$0(state) || JSXChild$1(state) || JSXChild$2(state) || JSXChild$3(state) || JSXChild$4(state));
11739
+ const result = $TOKEN("JSXChild", state, JSXChild$0(state) || JSXChild$1(state) || JSXChild$2(state) || JSXChild$3(state) || JSXChild$4(state) || JSXChild$5(state));
11728
11740
  if (state.events)
11729
11741
  state.events.exit?.("JSXChild", state, result);
11730
11742
  return result;
11731
11743
  } else {
11732
- const result = JSXChild$0(state) || JSXChild$1(state) || JSXChild$2(state) || JSXChild$3(state) || JSXChild$4(state);
11744
+ const result = JSXChild$0(state) || JSXChild$1(state) || JSXChild$2(state) || JSXChild$3(state) || JSXChild$4(state) || JSXChild$5(state);
11733
11745
  if (state.events)
11734
11746
  state.events.exit?.("JSXChild", state, result);
11735
11747
  return result;
11736
11748
  }
11737
11749
  }
11738
- var JSXText$0 = $TR($EXPECT($R47, fail, "JSXText /[^{}<>\\r\\n]+/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11750
+ var JSXComment$0 = $TS($S($EXPECT($L157, fail, 'JSXComment "<!--"'), JSXCommentContent, $EXPECT($L158, fail, 'JSXComment "-->"')), function($skip, $loc, $0, $1, $2, $3) {
11751
+ return ["{/*", $2, "*/}"];
11752
+ });
11753
+ function JSXComment(state) {
11754
+ if (state.events) {
11755
+ const result = state.events.enter?.("JSXComment", state);
11756
+ if (result)
11757
+ return result.cache;
11758
+ }
11759
+ if (state.tokenize) {
11760
+ const result = $TOKEN("JSXComment", state, JSXComment$0(state));
11761
+ if (state.events)
11762
+ state.events.exit?.("JSXComment", state, result);
11763
+ return result;
11764
+ } else {
11765
+ const result = JSXComment$0(state);
11766
+ if (state.events)
11767
+ state.events.exit?.("JSXComment", state, result);
11768
+ return result;
11769
+ }
11770
+ }
11771
+ var JSXCommentContent$0 = $TR($EXPECT($R47, fail, "JSXCommentContent /(?:-[^-]|[^-]*)*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11772
+ return { $loc, token: $0.replace(/\*\//g, "* /") };
11773
+ });
11774
+ function JSXCommentContent(state) {
11775
+ if (state.events) {
11776
+ const result = state.events.enter?.("JSXCommentContent", state);
11777
+ if (result)
11778
+ return result.cache;
11779
+ }
11780
+ if (state.tokenize) {
11781
+ const result = $TOKEN("JSXCommentContent", state, JSXCommentContent$0(state));
11782
+ if (state.events)
11783
+ state.events.exit?.("JSXCommentContent", state, result);
11784
+ return result;
11785
+ } else {
11786
+ const result = JSXCommentContent$0(state);
11787
+ if (state.events)
11788
+ state.events.exit?.("JSXCommentContent", state, result);
11789
+ return result;
11790
+ }
11791
+ }
11792
+ var JSXText$0 = $TR($EXPECT($R48, fail, "JSXText /[^{}<>\\r\\n]+/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11739
11793
  return {
11740
11794
  type: "JSXText",
11741
11795
  token: $0,
@@ -11800,7 +11854,7 @@ ${input.slice(result.pos)}
11800
11854
  return result;
11801
11855
  }
11802
11856
  }
11803
- var TypeDeclarationModifier$0 = $S($EXPECT($L157, fail, 'TypeDeclarationModifier "declare"'), NonIdContinue);
11857
+ var TypeDeclarationModifier$0 = $S($EXPECT($L159, fail, 'TypeDeclarationModifier "declare"'), NonIdContinue);
11804
11858
  var TypeDeclarationModifier$1 = Export;
11805
11859
  function TypeDeclarationModifier(state) {
11806
11860
  if (state.events) {
@@ -11842,7 +11896,7 @@ ${input.slice(result.pos)}
11842
11896
  return result;
11843
11897
  }
11844
11898
  }
11845
- var TypeKeyword$0 = $S($EXPECT($L158, fail, 'TypeKeyword "type"'), NonIdContinue);
11899
+ var TypeKeyword$0 = $S($EXPECT($L160, fail, 'TypeKeyword "type"'), NonIdContinue);
11846
11900
  function TypeKeyword(state) {
11847
11901
  if (state.events) {
11848
11902
  const result = state.events.enter?.("TypeKeyword", state);
@@ -11861,7 +11915,7 @@ ${input.slice(result.pos)}
11861
11915
  return result;
11862
11916
  }
11863
11917
  }
11864
- var Interface$0 = $S($EXPECT($L159, fail, 'Interface "interface"'), NonIdContinue);
11918
+ var Interface$0 = $S($EXPECT($L161, fail, 'Interface "interface"'), NonIdContinue);
11865
11919
  function Interface(state) {
11866
11920
  if (state.events) {
11867
11921
  const result = state.events.enter?.("Interface", state);
@@ -11880,7 +11934,7 @@ ${input.slice(result.pos)}
11880
11934
  return result;
11881
11935
  }
11882
11936
  }
11883
- var Namespace$0 = $S($EXPECT($L160, fail, 'Namespace "namespace"'), NonIdContinue);
11937
+ var Namespace$0 = $S($EXPECT($L162, fail, 'Namespace "namespace"'), NonIdContinue);
11884
11938
  function Namespace(state) {
11885
11939
  if (state.events) {
11886
11940
  const result = state.events.enter?.("Namespace", state);
@@ -12069,7 +12123,7 @@ ${input.slice(result.pos)}
12069
12123
  return result;
12070
12124
  }
12071
12125
  }
12072
- var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R48, fail, "TypeIndexSignature /[+-]?/")), $EXPECT($L129, fail, 'TypeIndexSignature "readonly"'), __)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R4, fail, "TypeIndexSignature /[+-]/")), QuestionMark)));
12126
+ var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R49, fail, "TypeIndexSignature /[+-]?/")), $EXPECT($L129, fail, 'TypeIndexSignature "readonly"'), __)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R4, fail, "TypeIndexSignature /[+-]/")), QuestionMark)));
12073
12127
  function TypeIndexSignature(state) {
12074
12128
  if (state.events) {
12075
12129
  const result = state.events.enter?.("TypeIndexSignature", state);
@@ -12129,7 +12183,7 @@ ${input.slice(result.pos)}
12129
12183
  return result;
12130
12184
  }
12131
12185
  }
12132
- var ReturnTypeSuffix$0 = $TS($S(__, Colon, $E($S(__, $EXPECT($L161, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2, $3, $4) {
12186
+ var ReturnTypeSuffix$0 = $TS($S(__, Colon, $E($S(__, $EXPECT($L163, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2, $3, $4) {
12133
12187
  const children = [...$1, $2];
12134
12188
  if ($3)
12135
12189
  children.push($3);
@@ -12264,9 +12318,9 @@ ${input.slice(result.pos)}
12264
12318
  return result;
12265
12319
  }
12266
12320
  }
12267
- var TypeUnaryOp$0 = $EXPECT($L162, fail, 'TypeUnaryOp "keyof"');
12321
+ var TypeUnaryOp$0 = $EXPECT($L164, fail, 'TypeUnaryOp "keyof"');
12268
12322
  var TypeUnaryOp$1 = $EXPECT($L145, fail, 'TypeUnaryOp "typeof"');
12269
- var TypeUnaryOp$2 = $EXPECT($L163, fail, 'TypeUnaryOp "infer"');
12323
+ var TypeUnaryOp$2 = $EXPECT($L165, fail, 'TypeUnaryOp "infer"');
12270
12324
  var TypeUnaryOp$3 = $EXPECT($L129, fail, 'TypeUnaryOp "readonly"');
12271
12325
  function TypeUnaryOp(state) {
12272
12326
  if (state.events) {
@@ -12439,7 +12493,7 @@ ${input.slice(result.pos)}
12439
12493
  var TypeLiteral$2 = $TV($EXPECT($L149, fail, 'TypeLiteral "void"'), function($skip, $loc, $0, $1) {
12440
12494
  return { $loc, token: "void" };
12441
12495
  });
12442
- var TypeLiteral$3 = $TV($EXPECT($L164, fail, 'TypeLiteral "[]"'), function($skip, $loc, $0, $1) {
12496
+ var TypeLiteral$3 = $TV($EXPECT($L166, fail, 'TypeLiteral "[]"'), function($skip, $loc, $0, $1) {
12443
12497
  return { $loc, token: "[]" };
12444
12498
  });
12445
12499
  function TypeLiteral(state) {
@@ -12671,7 +12725,7 @@ ${input.slice(result.pos)}
12671
12725
  return result;
12672
12726
  }
12673
12727
  }
12674
- var Shebang$0 = $S($R$0($EXPECT($R49, fail, "Shebang /#![^\\r\\n]*/")), EOL);
12728
+ var Shebang$0 = $S($R$0($EXPECT($R50, fail, "Shebang /#![^\\r\\n]*/")), EOL);
12675
12729
  function Shebang(state) {
12676
12730
  if (state.events) {
12677
12731
  const result = state.events.enter?.("Shebang", state);
@@ -12690,11 +12744,11 @@ ${input.slice(result.pos)}
12690
12744
  return result;
12691
12745
  }
12692
12746
  }
12693
- var CivetPrologue$0 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
12747
+ var CivetPrologue$0 = $T($S($EXPECT($R51, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), $E(EOS)), function(value) {
12694
12748
  var content = value[2];
12695
12749
  return content;
12696
12750
  });
12697
- var CivetPrologue$1 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
12751
+ var CivetPrologue$1 = $T($S($EXPECT($R51, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), $E(EOS)), function(value) {
12698
12752
  var content = value[2];
12699
12753
  return content;
12700
12754
  });
@@ -12716,7 +12770,7 @@ ${input.slice(result.pos)}
12716
12770
  return result;
12717
12771
  }
12718
12772
  }
12719
- var CivetPrologueContent$0 = $TS($S($EXPECT($L165, fail, 'CivetPrologueContent "civet"'), $Q(CivetOption), $EXPECT($R51, fail, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3) {
12773
+ var CivetPrologueContent$0 = $TS($S($EXPECT($L167, fail, 'CivetPrologueContent "civet"'), $Q(CivetOption), $EXPECT($R52, fail, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3) {
12720
12774
  var options = $2;
12721
12775
  return {
12722
12776
  type: "CivetPrologue",
@@ -12742,7 +12796,7 @@ ${input.slice(result.pos)}
12742
12796
  return result;
12743
12797
  }
12744
12798
  }
12745
- var CivetOption$0 = $TR($EXPECT($R52, fail, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12799
+ var CivetOption$0 = $TR($EXPECT($R53, fail, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12746
12800
  const optionName = $2.replace(/-+([a-z]?)/g, (_2, l) => {
12747
12801
  if (l)
12748
12802
  return l.toUpperCase();
@@ -12774,7 +12828,7 @@ ${input.slice(result.pos)}
12774
12828
  return result;
12775
12829
  }
12776
12830
  }
12777
- var UnknownPrologue$0 = $S($R$0($EXPECT($R50, fail, "UnknownPrologue /[\\t ]*/")), BasicStringLiteral, $TEXT(StatementDelimiter), EOS);
12831
+ var UnknownPrologue$0 = $S($R$0($EXPECT($R51, fail, "UnknownPrologue /[\\t ]*/")), BasicStringLiteral, $TEXT(StatementDelimiter), EOS);
12778
12832
  function UnknownPrologue(state) {
12779
12833
  if (state.events) {
12780
12834
  const result = state.events.enter?.("UnknownPrologue", state);
@@ -12832,7 +12886,7 @@ ${input.slice(result.pos)}
12832
12886
  return result;
12833
12887
  }
12834
12888
  }
12835
- var EOL$0 = $TR($EXPECT($R53, fail, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12889
+ var EOL$0 = $TR($EXPECT($R54, fail, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12836
12890
  return { $loc, token: $0 };
12837
12891
  });
12838
12892
  function EOL(state) {
@@ -14617,7 +14671,7 @@ ${input.slice(result.pos)}
14617
14671
  return result;
14618
14672
  }
14619
14673
  }
14620
- var Indent$0 = $TR($EXPECT($R54, fail, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
14674
+ var Indent$0 = $TR($EXPECT($R55, fail, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
14621
14675
  let level;
14622
14676
  if (module.config.tab) {
14623
14677
  const tabs = $0.match(/\t/g);
@@ -15246,6 +15300,9 @@ ${input.slice(result.pos)}
15246
15300
  compile: function(src, options = defaultOptions) {
15247
15301
  var ast, code, events, filename, sm, srcMapJSON;
15248
15302
  filename = options.filename || "unknown";
15303
+ if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
15304
+ src = `"civet coffeeCompat"; ${src}`;
15305
+ }
15249
15306
  if (!options.noCache) {
15250
15307
  events = makeCache();
15251
15308
  }
package/dist/civet CHANGED
@@ -1,8 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
- var compile, encoding, fs, generate, parse, prune, readLines, readline;
3
+ var cli, compile, encoding, fs, generate, parse, parseArgs, path, prune, readFiles, repl, version, splice = [].splice;
4
+ version = function() {
5
+ return require("../package.json").version;
6
+ };
4
7
  if (process.argv.includes("--version")) {
5
- process.stdout.write(require("../package.json").version + "\n");
8
+ console.log(version());
6
9
  process.exit(0);
7
10
  }
8
11
  if (process.argv.includes("--help")) {
@@ -15,14 +18,24 @@ if (process.argv.includes("--help")) {
15
18
 
16
19
  Usage:
17
20
 
18
- civet [options] < input.civet > output.ts
21
+ civet [options] # REPL
22
+ civet [options] -c input.civet # -> input.civet.tsx
23
+ civet [options] -c input.civet -o .ts # -> input.ts
24
+ civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
25
+ civet [options] -c input.civet -o dir/.ts # -> dir/input.ts
26
+ civet [options] -c input.civet -o output.ts # -> output.ts
27
+ civet [options] < input.civet > output.ts # pipe form
19
28
 
20
29
  Options:
21
- --help Show this help message
22
- --version Show the version number
23
- --ast Output the AST instead of the compiled code
24
- --inline-map Generate a sourcemap
25
- --js Strip out all type annotations
30
+ --help Show this help message
31
+ --version Show the version number
32
+ -o / --output XX Specify output directory and/or extension, or filename
33
+ -c / --compile Compile input files to TypeScript (or JavaScript)
34
+ --js Strip out all type annotations; default to .jsx extension
35
+ --ast Print the AST instead of the compiled code
36
+ --inline-map Generate a sourcemap
37
+
38
+ You can use - to read from stdin or (prefixed by -o) write to stdout.
26
39
 
27
40
  `);
28
41
  process.exit(0);
@@ -30,47 +43,221 @@ Options:
30
43
  ({ parse, compile, generate } = require("./main"));
31
44
  ({ prune } = generate);
32
45
  encoding = "utf8";
33
- process.stdin.setEncoding(encoding);
34
- fs = require("fs");
35
- readline = function() {
36
- try {
37
- return require("node:readline");
38
- } catch (error) {
39
- return require("readline");
46
+ fs = require("fs/promises");
47
+ path = require("path");
48
+ parseArgs = function(args = process.argv.slice(2)) {
49
+ var arg, char, filenames, i, options, ref;
50
+ options = {};
51
+ filenames = [];
52
+ i = 0;
53
+ while (i < args.length) {
54
+ arg = args[i];
55
+ if (/^-\w{2,}$/.test(arg)) {
56
+ splice.apply(args, [i, i - i + 1].concat(ref = function() {
57
+ var j, len, ref1, results;
58
+ ref1 = arg.slice(1);
59
+ results = [];
60
+ for (j = 0, len = ref1.length; j < len; j++) {
61
+ char = ref1[j];
62
+ results.push(`-${char}`);
63
+ }
64
+ return results;
65
+ }())), ref;
66
+ continue;
67
+ }
68
+ switch (arg) {
69
+ case "-c":
70
+ case "--compile":
71
+ options.compile = true;
72
+ break;
73
+ case "-o":
74
+ case "--output":
75
+ options.output = args[++i];
76
+ break;
77
+ case "--ast":
78
+ options.ast = true;
79
+ break;
80
+ case "--no-cache":
81
+ options.noCache = true;
82
+ break;
83
+ case "--inline-map":
84
+ options.inlineMap = true;
85
+ break;
86
+ case "--js":
87
+ options.js = true;
88
+ break;
89
+ case "--":
90
+ filenames.push(...args.slice(++i));
91
+ i = args.length;
92
+ break;
93
+ default:
94
+ filenames.push(arg);
95
+ }
96
+ i++;
40
97
  }
41
- }();
42
- readLines = function(rl) {
43
- return new Promise(function(resolve, reject) {
44
- var parts;
45
- parts = [];
46
- rl.on("line", function(buffer) {
47
- return parts.push(buffer + "\n");
48
- });
49
- rl.on("SIGINT", function() {
50
- return reject("^C");
51
- });
52
- return rl.on("close", function() {
53
- return resolve(parts.join(""));
54
- });
98
+ return { filenames, options };
99
+ };
100
+ readFiles = async function* (filenames, options) {
101
+ var content, error, filename, j, len, lines, results, rl, stdin;
102
+ results = [];
103
+ for (j = 0, len = filenames.length; j < len; j++) {
104
+ filename = filenames[j];
105
+ stdin = filename === "-";
106
+ try {
107
+ if (stdin) {
108
+ process.stdin.setEncoding(encoding);
109
+ filename = "<stdin>";
110
+ try {
111
+ filename = await fs.realpath("/dev/stdin");
112
+ } catch (error1) {
113
+ }
114
+ lines = [];
115
+ rl = require("readline").createInterface(process.stdin, process.stdout);
116
+ rl.on("line", function(buffer) {
117
+ return lines.push(buffer + "\n");
118
+ });
119
+ content = await new Promise(function(resolve, reject) {
120
+ rl.on("SIGINT", function() {
121
+ return reject("^C");
122
+ });
123
+ return rl.on("close", function() {
124
+ return resolve(lines.join(""));
125
+ });
126
+ });
127
+ } else {
128
+ content = await fs.readFile(filename, { encoding });
129
+ }
130
+ results.push(yield { filename, content, stdin });
131
+ } catch (error1) {
132
+ error = error1;
133
+ results.push(yield { filename, error, stdin });
134
+ }
135
+ }
136
+ return results;
137
+ };
138
+ repl = function(options) {
139
+ var nodeRepl, r, vm;
140
+ console.log(`Civet ${version()} REPL. Enter a blank line to execute code.`);
141
+ global.quit = global.exit = function() {
142
+ return process.exit(0);
143
+ };
144
+ nodeRepl = require("repl");
145
+ vm = require("vm");
146
+ return r = nodeRepl.start({
147
+ prompt: "\u{1F431}> ",
148
+ eval: function(input, context, filename, callback) {
149
+ var error, output, result;
150
+ if (input === "\n") {
151
+ return callback(null);
152
+ } else if (input === "quit\n" || input === "exit\n" || input === "quit()\n" || input === "exit()\n") {
153
+ return process.exit(0);
154
+ } else if (input.endsWith("\n\n")) {
155
+ try {
156
+ output = compile(input, { ...options, filename });
157
+ } catch (error1) {
158
+ error = error1;
159
+ return callback(error);
160
+ }
161
+ try {
162
+ result = vm.runInContext(output, context, { filename });
163
+ } catch (error1) {
164
+ error = error1;
165
+ return callback(error);
166
+ }
167
+ return callback(null, result);
168
+ } else {
169
+ return callback(new nodeRepl.Recoverable("Enter a blank line to execute code."));
170
+ }
171
+ }
55
172
  });
56
173
  };
57
- readLines(readline.createInterface(process.stdin, process.stdout)).then(function(input) {
58
- var ast, filename, inlineMap, js, noCache, output;
59
- ast = process.argv.includes("--ast");
60
- noCache = process.argv.includes("--no-cache");
61
- inlineMap = process.argv.includes("--inline-map");
62
- js = process.argv.includes("--js");
63
- filename = "unknown";
64
- try {
65
- filename = fs.realpathSync("/dev/stdin");
66
- } catch (error) {
174
+ cli = async function() {
175
+ var content, error, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, stat, stdin, x;
176
+ ({ filenames, options } = parseArgs());
177
+ if (!filenames.length) {
178
+ options.compile = true;
179
+ if (process.stdin.isTTY) {
180
+ options.repl = true;
181
+ } else {
182
+ filenames = ["-"];
183
+ }
67
184
  }
68
- output = compile(input, { ast, noCache, filename, inlineMap, js });
69
- if (ast) {
70
- output = JSON.stringify(output, null, 2);
185
+ options.run = !(options.ast || options.compile);
186
+ if (options.run) {
187
+ options.js = true;
188
+ options.inlineMap = true;
71
189
  }
72
- return process.stdout.write(output);
73
- }).catch(function(e) {
74
- console.error(e);
75
- return process.exit(1);
76
- });
190
+ if (options.repl) {
191
+ return repl(options);
192
+ }
193
+ ref = readFiles(filenames, options);
194
+ results = [];
195
+ for await (x of ref) {
196
+ ({ filename, error, content, stdin } = x);
197
+ if (error) {
198
+ console.error(`${filename} failed to load:`);
199
+ console.error(error);
200
+ continue;
201
+ }
202
+ try {
203
+ output = compile(content, { ...options, filename });
204
+ } catch (error1) {
205
+ error = error1;
206
+ console.error(error);
207
+ continue;
208
+ }
209
+ if (options.ast) {
210
+ results.push(process.stdout.write(JSON.stringify(output, null, 2)));
211
+ } else if (options.compile) {
212
+ if (stdin && !options.output || options.output === "-") {
213
+ results.push(process.stdout.write(output));
214
+ } else {
215
+ outputPath = path.parse(filename);
216
+ delete outputPath.base;
217
+ if (options.js) {
218
+ outputPath.ext += ".jsx";
219
+ } else {
220
+ outputPath.ext += ".tsx";
221
+ }
222
+ if (options.output) {
223
+ optionsPath = path.parse(options.output);
224
+ try {
225
+ stat = await fs.stat(options.output);
226
+ } catch (error1) {
227
+ stat = null;
228
+ }
229
+ if (stat != null ? stat.isDirectory() : void 0) {
230
+ outputPath.dir = options.output;
231
+ } else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
232
+ outputPath.ext = optionsPath.base;
233
+ if (optionsPath.dir) {
234
+ outputPath.dir = optionsPath.dir;
235
+ }
236
+ } else {
237
+ outputPath = optionsPath;
238
+ }
239
+ }
240
+ outputFilename = path.format(outputPath);
241
+ try {
242
+ results.push(await fs.writeFile(outputFilename, output));
243
+ } catch (error1) {
244
+ error = error1;
245
+ console.error(`${outputFilename} failed to write:`);
246
+ results.push(console.error(error));
247
+ }
248
+ }
249
+ } else {
250
+ try {
251
+ results.push(require.main._compile(output, filename));
252
+ } catch (error1) {
253
+ error = error1;
254
+ console.error(`${filename} crashed while running:`);
255
+ results.push(console.error(error));
256
+ }
257
+ }
258
+ }
259
+ return results;
260
+ };
261
+ if (require.main === module) {
262
+ cli();
263
+ }
package/dist/main.js CHANGED
@@ -798,6 +798,8 @@ ${input.slice(result.pos)}
798
798
  JSXChildren,
799
799
  JSXNestedChildren,
800
800
  JSXChild,
801
+ JSXComment,
802
+ JSXCommentContent,
801
803
  JSXText,
802
804
  JSXChildExpression,
803
805
  TypeDeclaration,
@@ -1044,15 +1046,17 @@ ${input.slice(result.pos)}
1044
1046
  var $L154 = $L("</");
1045
1047
  var $L155 = $L("<>");
1046
1048
  var $L156 = $L("</>");
1047
- var $L157 = $L("declare");
1048
- var $L158 = $L("type");
1049
- var $L159 = $L("interface");
1050
- var $L160 = $L("namespace");
1051
- var $L161 = $L("asserts");
1052
- var $L162 = $L("keyof");
1053
- var $L163 = $L("infer");
1054
- var $L164 = $L("[]");
1055
- var $L165 = $L("civet");
1049
+ var $L157 = $L("<!--");
1050
+ var $L158 = $L("-->");
1051
+ var $L159 = $L("declare");
1052
+ var $L160 = $L("type");
1053
+ var $L161 = $L("interface");
1054
+ var $L162 = $L("namespace");
1055
+ var $L163 = $L("asserts");
1056
+ var $L164 = $L("keyof");
1057
+ var $L165 = $L("infer");
1058
+ var $L166 = $L("[]");
1059
+ var $L167 = $L("civet");
1056
1060
  var $R0 = $R(new RegExp("(for|of|then|when)(?!\\p{ID_Continue}|[\\u200C\\u200D$])", "suy"));
1057
1061
  var $R1 = $R(new RegExp("[&]", "suy"));
1058
1062
  var $R2 = $R(new RegExp("[!~+-]+", "suy"));
@@ -1100,14 +1104,15 @@ ${input.slice(result.pos)}
1100
1104
  var $R44 = $R(new RegExp("\\s", "suy"));
1101
1105
  var $R45 = $R(new RegExp("(?:\\p{ID_Start}|[_$])(?:\\p{ID_Continue}|[\\u200C\\u200D$-])*", "suy"));
1102
1106
  var $R46 = $R(new RegExp("(?:[\\w\\-:]+|\\([^()]*\\)|\\[[^\\[\\]]*\\])+", "suy"));
1103
- var $R47 = $R(new RegExp("[^{}<>\\r\\n]+", "suy"));
1104
- var $R48 = $R(new RegExp("[+-]?", "suy"));
1105
- var $R49 = $R(new RegExp("#![^\\r\\n]*", "suy"));
1106
- var $R50 = $R(new RegExp("[\\t ]*", "suy"));
1107
- var $R51 = $R(new RegExp("[\\s]*", "suy"));
1108
- var $R52 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
1109
- var $R53 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
1110
- var $R54 = $R(new RegExp("[ \\t]*", "suy"));
1107
+ var $R47 = $R(new RegExp("(?:-[^-]|[^-]*)*", "suy"));
1108
+ var $R48 = $R(new RegExp("[^{}<>\\r\\n]+", "suy"));
1109
+ var $R49 = $R(new RegExp("[+-]?", "suy"));
1110
+ var $R50 = $R(new RegExp("#![^\\r\\n]*", "suy"));
1111
+ var $R51 = $R(new RegExp("[\\t ]*", "suy"));
1112
+ var $R52 = $R(new RegExp("[\\s]*", "suy"));
1113
+ var $R53 = $R(new RegExp("\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?", "suy"));
1114
+ var $R54 = $R(new RegExp("\\r\\n|\\n|\\r|$", "suy"));
1115
+ var $R55 = $R(new RegExp("[ \\t]*", "suy"));
1111
1116
  var Program$0 = $TS($S(Reset, Init, __, $Q(TopLevelStatement), __), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
1112
1117
  var statements = $4;
1113
1118
  module2.processProgram(statements);
@@ -11112,8 +11117,10 @@ ${input.slice(result.pos)}
11112
11117
  return true;
11113
11118
  });
11114
11119
  if (classes.length) {
11115
- let braced = function(c) {
11120
+ let isBraced = function(c) {
11116
11121
  return c[0] === "{" || c[0]?.token === "{";
11122
+ }, unbrace = function(c) {
11123
+ return c.slice(1, -1);
11117
11124
  }, parseClass = function(c) {
11118
11125
  c = c.token || c;
11119
11126
  if (c.startsWith("'")) {
@@ -11131,21 +11138,25 @@ ${input.slice(result.pos)}
11131
11138
  }
11132
11139
  return true;
11133
11140
  });
11141
+ const strings = [], exprs = [];
11142
+ classes.forEach((c) => {
11143
+ if (isBraced(c)) {
11144
+ exprs.push(unbrace(c));
11145
+ exprs.push(", ");
11146
+ } else {
11147
+ strings.push(parseClass(c));
11148
+ }
11149
+ });
11150
+ const stringPart = strings.filter(Boolean).join(" ");
11134
11151
  let classValue;
11135
- if (classes.some(braced)) {
11136
- classValue = ["{`"];
11137
- classes.forEach((c, i) => {
11138
- if (i > 0)
11139
- classValue.push(" ");
11140
- if (braced(c)) {
11141
- classValue.push("$", c);
11142
- } else {
11143
- classValue.push(parseClass(c));
11144
- }
11145
- });
11146
- classValue.push("`}");
11152
+ if (exprs.length) {
11153
+ exprs.pop();
11154
+ if (stringPart) {
11155
+ exprs.unshift(JSON.stringify(stringPart), ", ");
11156
+ }
11157
+ classValue = ["{[", ...exprs, '].filter(Boolean).join(" ")}'];
11147
11158
  } else {
11148
- classValue = JSON.stringify(classes.map(parseClass).join(" "));
11159
+ classValue = JSON.stringify(stringPart);
11149
11160
  }
11150
11161
  attrs.splice(0, 0, [" ", [className, ["=", classValue]]]);
11151
11162
  }
@@ -11699,7 +11710,8 @@ ${input.slice(result.pos)}
11699
11710
  }
11700
11711
  var JSXChild$0 = JSXElement;
11701
11712
  var JSXChild$1 = JSXFragment;
11702
- var JSXChild$2 = $TS($S(OpenBrace, $E(JSXChildExpression), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4) {
11713
+ var JSXChild$2 = JSXComment;
11714
+ var JSXChild$3 = $TS($S(OpenBrace, $E(JSXChildExpression), __, CloseBrace), function($skip, $loc, $0, $1, $2, $3, $4) {
11703
11715
  var expression = $2;
11704
11716
  return {
11705
11717
  type: "JSXChildExpression",
@@ -11707,7 +11719,7 @@ ${input.slice(result.pos)}
11707
11719
  expression
11708
11720
  };
11709
11721
  });
11710
- var JSXChild$3 = $TS($S(InsertInlineOpenBrace, ArrowFunction, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3) {
11722
+ var JSXChild$4 = $TS($S(InsertInlineOpenBrace, ArrowFunction, InsertCloseBrace), function($skip, $loc, $0, $1, $2, $3) {
11711
11723
  var expression = $2;
11712
11724
  return {
11713
11725
  type: "JSXChildExpression",
@@ -11715,7 +11727,7 @@ ${input.slice(result.pos)}
11715
11727
  expression
11716
11728
  };
11717
11729
  });
11718
- var JSXChild$4 = JSXText;
11730
+ var JSXChild$5 = JSXText;
11719
11731
  function JSXChild(state) {
11720
11732
  if (state.events) {
11721
11733
  const result = state.events.enter?.("JSXChild", state);
@@ -11723,18 +11735,60 @@ ${input.slice(result.pos)}
11723
11735
  return result.cache;
11724
11736
  }
11725
11737
  if (state.tokenize) {
11726
- const result = $TOKEN("JSXChild", state, JSXChild$0(state) || JSXChild$1(state) || JSXChild$2(state) || JSXChild$3(state) || JSXChild$4(state));
11738
+ const result = $TOKEN("JSXChild", state, JSXChild$0(state) || JSXChild$1(state) || JSXChild$2(state) || JSXChild$3(state) || JSXChild$4(state) || JSXChild$5(state));
11727
11739
  if (state.events)
11728
11740
  state.events.exit?.("JSXChild", state, result);
11729
11741
  return result;
11730
11742
  } else {
11731
- const result = JSXChild$0(state) || JSXChild$1(state) || JSXChild$2(state) || JSXChild$3(state) || JSXChild$4(state);
11743
+ const result = JSXChild$0(state) || JSXChild$1(state) || JSXChild$2(state) || JSXChild$3(state) || JSXChild$4(state) || JSXChild$5(state);
11732
11744
  if (state.events)
11733
11745
  state.events.exit?.("JSXChild", state, result);
11734
11746
  return result;
11735
11747
  }
11736
11748
  }
11737
- var JSXText$0 = $TR($EXPECT($R47, fail, "JSXText /[^{}<>\\r\\n]+/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11749
+ var JSXComment$0 = $TS($S($EXPECT($L157, fail, 'JSXComment "<!--"'), JSXCommentContent, $EXPECT($L158, fail, 'JSXComment "-->"')), function($skip, $loc, $0, $1, $2, $3) {
11750
+ return ["{/*", $2, "*/}"];
11751
+ });
11752
+ function JSXComment(state) {
11753
+ if (state.events) {
11754
+ const result = state.events.enter?.("JSXComment", state);
11755
+ if (result)
11756
+ return result.cache;
11757
+ }
11758
+ if (state.tokenize) {
11759
+ const result = $TOKEN("JSXComment", state, JSXComment$0(state));
11760
+ if (state.events)
11761
+ state.events.exit?.("JSXComment", state, result);
11762
+ return result;
11763
+ } else {
11764
+ const result = JSXComment$0(state);
11765
+ if (state.events)
11766
+ state.events.exit?.("JSXComment", state, result);
11767
+ return result;
11768
+ }
11769
+ }
11770
+ var JSXCommentContent$0 = $TR($EXPECT($R47, fail, "JSXCommentContent /(?:-[^-]|[^-]*)*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11771
+ return { $loc, token: $0.replace(/\*\//g, "* /") };
11772
+ });
11773
+ function JSXCommentContent(state) {
11774
+ if (state.events) {
11775
+ const result = state.events.enter?.("JSXCommentContent", state);
11776
+ if (result)
11777
+ return result.cache;
11778
+ }
11779
+ if (state.tokenize) {
11780
+ const result = $TOKEN("JSXCommentContent", state, JSXCommentContent$0(state));
11781
+ if (state.events)
11782
+ state.events.exit?.("JSXCommentContent", state, result);
11783
+ return result;
11784
+ } else {
11785
+ const result = JSXCommentContent$0(state);
11786
+ if (state.events)
11787
+ state.events.exit?.("JSXCommentContent", state, result);
11788
+ return result;
11789
+ }
11790
+ }
11791
+ var JSXText$0 = $TR($EXPECT($R48, fail, "JSXText /[^{}<>\\r\\n]+/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
11738
11792
  return {
11739
11793
  type: "JSXText",
11740
11794
  token: $0,
@@ -11799,7 +11853,7 @@ ${input.slice(result.pos)}
11799
11853
  return result;
11800
11854
  }
11801
11855
  }
11802
- var TypeDeclarationModifier$0 = $S($EXPECT($L157, fail, 'TypeDeclarationModifier "declare"'), NonIdContinue);
11856
+ var TypeDeclarationModifier$0 = $S($EXPECT($L159, fail, 'TypeDeclarationModifier "declare"'), NonIdContinue);
11803
11857
  var TypeDeclarationModifier$1 = Export;
11804
11858
  function TypeDeclarationModifier(state) {
11805
11859
  if (state.events) {
@@ -11841,7 +11895,7 @@ ${input.slice(result.pos)}
11841
11895
  return result;
11842
11896
  }
11843
11897
  }
11844
- var TypeKeyword$0 = $S($EXPECT($L158, fail, 'TypeKeyword "type"'), NonIdContinue);
11898
+ var TypeKeyword$0 = $S($EXPECT($L160, fail, 'TypeKeyword "type"'), NonIdContinue);
11845
11899
  function TypeKeyword(state) {
11846
11900
  if (state.events) {
11847
11901
  const result = state.events.enter?.("TypeKeyword", state);
@@ -11860,7 +11914,7 @@ ${input.slice(result.pos)}
11860
11914
  return result;
11861
11915
  }
11862
11916
  }
11863
- var Interface$0 = $S($EXPECT($L159, fail, 'Interface "interface"'), NonIdContinue);
11917
+ var Interface$0 = $S($EXPECT($L161, fail, 'Interface "interface"'), NonIdContinue);
11864
11918
  function Interface(state) {
11865
11919
  if (state.events) {
11866
11920
  const result = state.events.enter?.("Interface", state);
@@ -11879,7 +11933,7 @@ ${input.slice(result.pos)}
11879
11933
  return result;
11880
11934
  }
11881
11935
  }
11882
- var Namespace$0 = $S($EXPECT($L160, fail, 'Namespace "namespace"'), NonIdContinue);
11936
+ var Namespace$0 = $S($EXPECT($L162, fail, 'Namespace "namespace"'), NonIdContinue);
11883
11937
  function Namespace(state) {
11884
11938
  if (state.events) {
11885
11939
  const result = state.events.enter?.("Namespace", state);
@@ -12068,7 +12122,7 @@ ${input.slice(result.pos)}
12068
12122
  return result;
12069
12123
  }
12070
12124
  }
12071
- var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R48, fail, "TypeIndexSignature /[+-]?/")), $EXPECT($L129, fail, 'TypeIndexSignature "readonly"'), __)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R4, fail, "TypeIndexSignature /[+-]/")), QuestionMark)));
12125
+ var TypeIndexSignature$0 = $S($E($S($R$0($EXPECT($R49, fail, "TypeIndexSignature /[+-]?/")), $EXPECT($L129, fail, 'TypeIndexSignature "readonly"'), __)), OpenBracket, TypeIndex, CloseBracket, $E($S(__, $R$0($EXPECT($R4, fail, "TypeIndexSignature /[+-]/")), QuestionMark)));
12072
12126
  function TypeIndexSignature(state) {
12073
12127
  if (state.events) {
12074
12128
  const result = state.events.enter?.("TypeIndexSignature", state);
@@ -12128,7 +12182,7 @@ ${input.slice(result.pos)}
12128
12182
  return result;
12129
12183
  }
12130
12184
  }
12131
- var ReturnTypeSuffix$0 = $TS($S(__, Colon, $E($S(__, $EXPECT($L161, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2, $3, $4) {
12185
+ var ReturnTypeSuffix$0 = $TS($S(__, Colon, $E($S(__, $EXPECT($L163, fail, 'ReturnTypeSuffix "asserts"'), NonIdContinue)), TypePredicate), function($skip, $loc, $0, $1, $2, $3, $4) {
12132
12186
  const children = [...$1, $2];
12133
12187
  if ($3)
12134
12188
  children.push($3);
@@ -12263,9 +12317,9 @@ ${input.slice(result.pos)}
12263
12317
  return result;
12264
12318
  }
12265
12319
  }
12266
- var TypeUnaryOp$0 = $EXPECT($L162, fail, 'TypeUnaryOp "keyof"');
12320
+ var TypeUnaryOp$0 = $EXPECT($L164, fail, 'TypeUnaryOp "keyof"');
12267
12321
  var TypeUnaryOp$1 = $EXPECT($L145, fail, 'TypeUnaryOp "typeof"');
12268
- var TypeUnaryOp$2 = $EXPECT($L163, fail, 'TypeUnaryOp "infer"');
12322
+ var TypeUnaryOp$2 = $EXPECT($L165, fail, 'TypeUnaryOp "infer"');
12269
12323
  var TypeUnaryOp$3 = $EXPECT($L129, fail, 'TypeUnaryOp "readonly"');
12270
12324
  function TypeUnaryOp(state) {
12271
12325
  if (state.events) {
@@ -12438,7 +12492,7 @@ ${input.slice(result.pos)}
12438
12492
  var TypeLiteral$2 = $TV($EXPECT($L149, fail, 'TypeLiteral "void"'), function($skip, $loc, $0, $1) {
12439
12493
  return { $loc, token: "void" };
12440
12494
  });
12441
- var TypeLiteral$3 = $TV($EXPECT($L164, fail, 'TypeLiteral "[]"'), function($skip, $loc, $0, $1) {
12495
+ var TypeLiteral$3 = $TV($EXPECT($L166, fail, 'TypeLiteral "[]"'), function($skip, $loc, $0, $1) {
12442
12496
  return { $loc, token: "[]" };
12443
12497
  });
12444
12498
  function TypeLiteral(state) {
@@ -12670,7 +12724,7 @@ ${input.slice(result.pos)}
12670
12724
  return result;
12671
12725
  }
12672
12726
  }
12673
- var Shebang$0 = $S($R$0($EXPECT($R49, fail, "Shebang /#![^\\r\\n]*/")), EOL);
12727
+ var Shebang$0 = $S($R$0($EXPECT($R50, fail, "Shebang /#![^\\r\\n]*/")), EOL);
12674
12728
  function Shebang(state) {
12675
12729
  if (state.events) {
12676
12730
  const result = state.events.enter?.("Shebang", state);
@@ -12689,11 +12743,11 @@ ${input.slice(result.pos)}
12689
12743
  return result;
12690
12744
  }
12691
12745
  }
12692
- var CivetPrologue$0 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
12746
+ var CivetPrologue$0 = $T($S($EXPECT($R51, fail, "CivetPrologue /[\\t ]*/"), DoubleQuote, CivetPrologueContent, DoubleQuote, $TEXT(StatementDelimiter), $E(EOS)), function(value) {
12693
12747
  var content = value[2];
12694
12748
  return content;
12695
12749
  });
12696
- var CivetPrologue$1 = $T($S($EXPECT($R50, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), EOS), function(value) {
12750
+ var CivetPrologue$1 = $T($S($EXPECT($R51, fail, "CivetPrologue /[\\t ]*/"), SingleQuote, CivetPrologueContent, SingleQuote, $TEXT(StatementDelimiter), $E(EOS)), function(value) {
12697
12751
  var content = value[2];
12698
12752
  return content;
12699
12753
  });
@@ -12715,7 +12769,7 @@ ${input.slice(result.pos)}
12715
12769
  return result;
12716
12770
  }
12717
12771
  }
12718
- var CivetPrologueContent$0 = $TS($S($EXPECT($L165, fail, 'CivetPrologueContent "civet"'), $Q(CivetOption), $EXPECT($R51, fail, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3) {
12772
+ var CivetPrologueContent$0 = $TS($S($EXPECT($L167, fail, 'CivetPrologueContent "civet"'), $Q(CivetOption), $EXPECT($R52, fail, "CivetPrologueContent /[\\s]*/")), function($skip, $loc, $0, $1, $2, $3) {
12719
12773
  var options = $2;
12720
12774
  return {
12721
12775
  type: "CivetPrologue",
@@ -12741,7 +12795,7 @@ ${input.slice(result.pos)}
12741
12795
  return result;
12742
12796
  }
12743
12797
  }
12744
- var CivetOption$0 = $TR($EXPECT($R52, fail, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12798
+ var CivetOption$0 = $TR($EXPECT($R53, fail, "CivetOption /\\s+([+-]?)([a-zA-Z0-9-]+)(\\s*=\\s*([a-zA-Z0-9.+-]*))?/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12745
12799
  const optionName = $2.replace(/-+([a-z]?)/g, (_2, l) => {
12746
12800
  if (l)
12747
12801
  return l.toUpperCase();
@@ -12773,7 +12827,7 @@ ${input.slice(result.pos)}
12773
12827
  return result;
12774
12828
  }
12775
12829
  }
12776
- var UnknownPrologue$0 = $S($R$0($EXPECT($R50, fail, "UnknownPrologue /[\\t ]*/")), BasicStringLiteral, $TEXT(StatementDelimiter), EOS);
12830
+ var UnknownPrologue$0 = $S($R$0($EXPECT($R51, fail, "UnknownPrologue /[\\t ]*/")), BasicStringLiteral, $TEXT(StatementDelimiter), EOS);
12777
12831
  function UnknownPrologue(state) {
12778
12832
  if (state.events) {
12779
12833
  const result = state.events.enter?.("UnknownPrologue", state);
@@ -12831,7 +12885,7 @@ ${input.slice(result.pos)}
12831
12885
  return result;
12832
12886
  }
12833
12887
  }
12834
- var EOL$0 = $TR($EXPECT($R53, fail, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12888
+ var EOL$0 = $TR($EXPECT($R54, fail, "EOL /\\r\\n|\\n|\\r|$/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12835
12889
  return { $loc, token: $0 };
12836
12890
  });
12837
12891
  function EOL(state) {
@@ -14616,7 +14670,7 @@ ${input.slice(result.pos)}
14616
14670
  return result;
14617
14671
  }
14618
14672
  }
14619
- var Indent$0 = $TR($EXPECT($R54, fail, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
14673
+ var Indent$0 = $TR($EXPECT($R55, fail, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
14620
14674
  let level;
14621
14675
  if (module2.config.tab) {
14622
14676
  const tabs = $0.match(/\t/g);
@@ -15243,6 +15297,9 @@ module.exports = {
15243
15297
  compile: function(src, options = defaultOptions) {
15244
15298
  var ast, code, events, filename, sm, srcMapJSON;
15245
15299
  filename = options.filename || "unknown";
15300
+ if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
15301
+ src = `"civet coffeeCompat"; ${src}`;
15302
+ }
15246
15303
  if (!options.noCache) {
15247
15304
  events = makeCache();
15248
15305
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@danielx/civet",
3
- "version": "0.5.17",
3
+ "version": "0.5.19",
4
4
  "description": "CoffeeScript style syntax for TypeScript",
5
5
  "main": "dist/main.js",
6
6
  "exports": {