@danielx/civet 0.6.38 → 0.6.40

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
@@ -7,7 +7,14 @@ var Civet = (() => {
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
- var __commonJS = (cb, mod) => function __require() {
10
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
11
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
12
+ }) : x)(function(x) {
13
+ if (typeof require !== "undefined")
14
+ return require.apply(this, arguments);
15
+ throw new Error('Dynamic require of "' + x + '" is not supported');
16
+ });
17
+ var __commonJS = (cb, mod) => function __require2() {
11
18
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
19
  };
13
20
  var __export = (target, all) => {
@@ -730,57 +737,107 @@ ${input.slice(result.pos)}
730
737
  }
731
738
  return [constructInvocation(fn, arg), null];
732
739
  }
733
- var initialSpacingRe = /^(?:\r?\n|\n)*((?:\r?\n|\n)\s+)/;
734
- function dedentBlockString({ $loc, token: str }, spacing, trim = true) {
735
- if (spacing == null)
736
- spacing = str.match(initialSpacingRe);
737
- if (spacing) {
738
- str = str.replaceAll(spacing[1], "\n");
739
- const l = spacing.length;
740
- $loc.pos += l;
741
- $loc.length -= l;
740
+ function getIndentLevel(str, tab) {
741
+ if (tab != null && tab != 1) {
742
+ const tabs = str.match(/\t/g);
743
+ const numTabs = tabs ? tabs.length : 0;
744
+ return numTabs * tab + /*spaces*/
745
+ (str.length - numTabs);
746
+ } else {
747
+ return str.length;
742
748
  }
743
- if (trim) {
744
- str = str.replace(/^(\r?\n|\n)/, "").replace(/(\r?\n|\n)[ \t]*$/, "");
749
+ }
750
+ function reduceIndentLevel(str, dedent, tab) {
751
+ if (tab != null && tab != 1) {
752
+ for (let i1 = 0, len1 = str.length; i1 < len1; i1++) {
753
+ const i = i1;
754
+ const char = str[i1];
755
+ if (!dedent) {
756
+ return str.slice(i);
757
+ }
758
+ if (char == " ") {
759
+ dedent -= tab;
760
+ if (dedent < 0) {
761
+ return "".padStart(-dedent, " ") + str.slice(i + 1);
762
+ }
763
+ } else {
764
+ dedent--;
765
+ }
766
+ }
767
+ return "";
768
+ } else {
769
+ return str.slice(dedent);
770
+ }
771
+ }
772
+ var indentRe = /\n([ \t]*)(?![ \t]|\r?\n|$)/g;
773
+ function getIndentOfBlockString(str, tab) {
774
+ let minLevel = Infinity;
775
+ let ref1;
776
+ while (ref1 = indentRe.exec(str)) {
777
+ const match = ref1;
778
+ const level = getIndentLevel(match[1], tab);
779
+ if (level < minLevel) {
780
+ minLevel = level;
781
+ }
782
+ }
783
+ if (minLevel == Infinity) {
784
+ minLevel = 0;
785
+ }
786
+ return minLevel;
787
+ }
788
+ function dedentBlockString({ $loc, token: str }, tab, dedent, trimStart = true, trimEnd = true) {
789
+ if (dedent == null && /^[ \t]*\r?\n/.test(str)) {
790
+ dedent = getIndentOfBlockString(str, tab);
791
+ }
792
+ if (dedent) {
793
+ str = str.replace(/(\n)([ \t]*)/g, (_, newline, indent) => {
794
+ return newline + reduceIndentLevel(indent, dedent, tab);
795
+ });
796
+ }
797
+ if (trimStart) {
798
+ str = str.replace(/^[ \t]*\r?\n/, "");
799
+ }
800
+ if (trimEnd) {
801
+ str = str.replace(/(\r?\n|\n)[ \t]*$/, "");
745
802
  }
746
803
  str = str.replace(/(\\.|`|\$\{)/g, (s) => {
747
804
  if (s[0] === "\\") {
748
805
  return s;
806
+ } else {
807
+ return `\\${s}`;
749
808
  }
750
- return `\\${s}`;
751
809
  });
752
- return {
753
- $loc,
754
- token: str
755
- };
810
+ return { $loc, token: str };
756
811
  }
757
- function dedentBlockSubstitutions($0) {
812
+ function dedentBlockSubstitutions($0, tab) {
758
813
  const [s, strWithSubstitutions, e] = $0;
759
- if (strWithSubstitutions.length === 0) {
814
+ if (!strWithSubstitutions.length) {
760
815
  return $0;
761
816
  }
762
- let initialSpacing, i = 0, l = strWithSubstitutions.length, results = [s];
763
- const { token } = strWithSubstitutions[0];
764
- if (token) {
765
- initialSpacing = token.match(initialSpacingRe);
766
- } else {
767
- initialSpacing = false;
768
- }
769
- while (i < l) {
770
- let segment = strWithSubstitutions[i];
771
- if (segment.token) {
772
- segment = dedentBlockString(segment, initialSpacing, false);
773
- if (i === 0) {
774
- segment.token = segment.token.replace(/^(\r?\n|\n)/, "");
775
- }
776
- if (i === l - 1) {
777
- segment.token = segment.token.replace(/(\r?\n|\n)[ \t]*$/, "");
778
- }
779
- results.push(segment);
780
- } else {
781
- results.push(segment);
817
+ const stringPart = (() => {
818
+ const results1 = [];
819
+ for (let i2 = 0, len2 = strWithSubstitutions.length; i2 < len2; i2++) {
820
+ const part = strWithSubstitutions[i2];
821
+ results1.push(part.token ?? "s");
782
822
  }
783
- i++;
823
+ ;
824
+ return results1;
825
+ })().join("");
826
+ const dedent = /^[ \t]*\r?\n/.test(stringPart) ? getIndentOfBlockString(stringPart, tab) : false;
827
+ let results = [s];
828
+ for (let i3 = 0, len3 = strWithSubstitutions.length; i3 < len3; i3++) {
829
+ const i = i3;
830
+ let part = strWithSubstitutions[i3];
831
+ if (part.token != null) {
832
+ part = dedentBlockString(
833
+ part,
834
+ tab,
835
+ dedent,
836
+ i === 0,
837
+ i === strWithSubstitutions.length - 1
838
+ );
839
+ }
840
+ results.push(part);
784
841
  }
785
842
  results.push(e);
786
843
  return {
@@ -1309,17 +1366,17 @@ ${input.slice(result.pos)}
1309
1366
  }
1310
1367
  function arrayRecurse(array) {
1311
1368
  const len2 = array.length;
1312
- const results1 = [];
1369
+ const results2 = [];
1313
1370
  for (let i = 0; i < len2; i++) {
1314
1371
  const c = array[i];
1315
1372
  if (c === child || Array.isArray(c) && arrayRecurse(c)) {
1316
1373
  return true;
1317
1374
  } else {
1318
- results1.push(void 0);
1375
+ results2.push(void 0);
1319
1376
  }
1320
1377
  }
1321
1378
  ;
1322
- return results1;
1379
+ return results2;
1323
1380
  }
1324
1381
  return -1;
1325
1382
  }
@@ -2313,9 +2370,11 @@ ${input.slice(result.pos)}
2313
2370
  }
2314
2371
  if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
2315
2372
  if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
2316
- post.push([", ", lhs]);
2373
+ pre.push("(");
2374
+ post.push([", ", lhs, ")"]);
2317
2375
  } else {
2318
- pre.push([lhs, ", "]);
2376
+ pre.push(["(", lhs, ", "]);
2377
+ post.push(")");
2319
2378
  }
2320
2379
  return expr.assigned;
2321
2380
  }
@@ -3461,7 +3520,7 @@ ${input.slice(result.pos)}
3461
3520
  gatherRecursive,
3462
3521
  gatherRecursiveAll,
3463
3522
  gatherRecursiveWithinFunction,
3464
- getIndent,
3523
+ getIndentLevel,
3465
3524
  getTrimmingSpace,
3466
3525
  hasAwait,
3467
3526
  hasYield,
@@ -4470,7 +4529,7 @@ ${input.slice(result.pos)}
4470
4529
  var $R43 = $R(new RegExp("#(?!##(?!#))([^\\r\\n]*)", "suy"));
4471
4530
  var $R44 = $R(new RegExp("[^]*?###", "suy"));
4472
4531
  var $R45 = $R(new RegExp("###(?!#)", "suy"));
4473
- var $R46 = $R(new RegExp("[^\\r\\n]", "suy"));
4532
+ var $R46 = $R(new RegExp("\\/\\*(?:(?!\\*\\/)[^\\r\\n])*\\*\\/", "suy"));
4474
4533
  var $R47 = $R(new RegExp("[ \\t]+", "suy"));
4475
4534
  var $R48 = $R(new RegExp("(?!\\p{ID_Continue})", "suy"));
4476
4535
  var $R49 = $R(new RegExp("['\u2019]s", "suy"));
@@ -5518,7 +5577,7 @@ ${input.slice(result.pos)}
5518
5577
  function CallExpressionRest(ctx, state) {
5519
5578
  return $EVENT_C(ctx, state, "CallExpressionRest", CallExpressionRest$$);
5520
5579
  }
5521
- var OptionalShorthand$0 = $TS($S($Q(MultiLineComment), QuestionMark, OptionalDot), function($skip, $loc, $0, $1, $2, $3) {
5580
+ var OptionalShorthand$0 = $TS($S($Q(InlineComment), QuestionMark, OptionalDot), function($skip, $loc, $0, $1, $2, $3) {
5522
5581
  return {
5523
5582
  type: "Optional",
5524
5583
  children: $0
@@ -5527,8 +5586,8 @@ ${input.slice(result.pos)}
5527
5586
  function OptionalShorthand(ctx, state) {
5528
5587
  return $EVENT(ctx, state, "OptionalShorthand", OptionalShorthand$0);
5529
5588
  }
5530
- var OptionalDot$0 = $S($Q(MultiLineComment), Dot);
5531
- var OptionalDot$1 = $S(InsertDot, $Q(MultiLineComment));
5589
+ var OptionalDot$0 = $S($Q(InlineComment), Dot);
5590
+ var OptionalDot$1 = $S(InsertDot, $Q(InlineComment));
5532
5591
  var OptionalDot$$ = [OptionalDot$0, OptionalDot$1];
5533
5592
  function OptionalDot(ctx, state) {
5534
5593
  return $EVENT_C(ctx, state, "OptionalDot", OptionalDot$$);
@@ -5559,7 +5618,7 @@ ${input.slice(result.pos)}
5559
5618
  function MemberBase(ctx, state) {
5560
5619
  return $EVENT_C(ctx, state, "MemberBase", MemberBase$$);
5561
5620
  }
5562
- var MemberExpressionRest$0 = $TS($S($Q(MultiLineComment), MemberExpressionRestBody), function($skip, $loc, $0, $1, $2) {
5621
+ var MemberExpressionRest$0 = $TS($S($Q(InlineComment), MemberExpressionRestBody), function($skip, $loc, $0, $1, $2) {
5563
5622
  var comments = $1;
5564
5623
  var body = $2;
5565
5624
  if (Array.isArray(body))
@@ -5572,7 +5631,7 @@ ${input.slice(result.pos)}
5572
5631
  function MemberExpressionRest(ctx, state) {
5573
5632
  return $EVENT(ctx, state, "MemberExpressionRest", MemberExpressionRest$0);
5574
5633
  }
5575
- var MemberExpressionRestBody$0 = $TS($S($E($C(OptionalShorthand, NonNullAssertion)), $Q(MultiLineComment), MemberBracketContent), function($skip, $loc, $0, $1, $2, $3) {
5634
+ var MemberExpressionRestBody$0 = $TS($S($E($C(OptionalShorthand, NonNullAssertion)), $Q(InlineComment), MemberBracketContent), function($skip, $loc, $0, $1, $2, $3) {
5576
5635
  var dot = $1;
5577
5636
  var comments = $2;
5578
5637
  var content = $3;
@@ -5730,7 +5789,7 @@ ${input.slice(result.pos)}
5730
5789
  function AccessStart(ctx, state) {
5731
5790
  return $EVENT(ctx, state, "AccessStart", AccessStart$0);
5732
5791
  }
5733
- var PropertyAccess$0 = $TS($S(AccessStart, $Q(MultiLineComment), $C(IdentifierName, PrivateIdentifier)), function($skip, $loc, $0, $1, $2, $3) {
5792
+ var PropertyAccess$0 = $TS($S(AccessStart, $Q(InlineComment), $C(IdentifierName, PrivateIdentifier)), function($skip, $loc, $0, $1, $2, $3) {
5734
5793
  var access = $1;
5735
5794
  var comments = $2;
5736
5795
  var id = $3;
@@ -5762,7 +5821,7 @@ ${input.slice(result.pos)}
5762
5821
  function PropertyAccess(ctx, state) {
5763
5822
  return $EVENT_C(ctx, state, "PropertyAccess", PropertyAccess$$);
5764
5823
  }
5765
- var PropertyGlob$0 = $TS($S($S($E($C(QuestionMark, NonNullAssertion)), OptionalDot), $Q(MultiLineComment), BracedObjectLiteral), function($skip, $loc, $0, $1, $2, $3) {
5824
+ var PropertyGlob$0 = $TS($S($S($E($C(QuestionMark, NonNullAssertion)), OptionalDot), $Q(InlineComment), BracedObjectLiteral), function($skip, $loc, $0, $1, $2, $3) {
5766
5825
  var dot = $1;
5767
5826
  var object = $3;
5768
5827
  return {
@@ -7119,7 +7178,7 @@ ${input.slice(result.pos)}
7119
7178
  names: exp.names
7120
7179
  };
7121
7180
  });
7122
- var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), ExtendedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
7181
+ var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), PostfixedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
7123
7182
  var expMaybeSpread = $1;
7124
7183
  if (expMaybeSpread) {
7125
7184
  const [spread, exp] = expMaybeSpread;
@@ -8673,7 +8732,7 @@ ${input.slice(result.pos)}
8673
8732
  children: $0
8674
8733
  };
8675
8734
  });
8676
- var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), Expression)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8735
+ var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS), ExpressionWithIndentedApplicationForbidden)), InsertCloseParen), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
8677
8736
  var declaration = $3;
8678
8737
  return {
8679
8738
  declaration,
@@ -9968,7 +10027,7 @@ ${input.slice(result.pos)}
9968
10027
  return $EVENT(ctx, state, "RegularExpressionFlags", RegularExpressionFlags$0);
9969
10028
  }
9970
10029
  var TemplateLiteral$0 = $TS($S(TripleTick, $Q($C(TemplateBlockCharacters, TemplateSubstitution)), TripleTick), function($skip, $loc, $0, $1, $2, $3) {
9971
- return dedentBlockSubstitutions($0);
10030
+ return dedentBlockSubstitutions($0, module.config.tab);
9972
10031
  });
9973
10032
  var TemplateLiteral$1 = $TS($S(Backtick, $Q($C(TemplateCharacters, TemplateSubstitution)), Backtick), function($skip, $loc, $0, $1, $2, $3) {
9974
10033
  return {
@@ -9977,7 +10036,7 @@ ${input.slice(result.pos)}
9977
10036
  };
9978
10037
  });
9979
10038
  var TemplateLiteral$2 = $TS($S(TripleDoubleQuote, $Q($C(TripleDoubleStringCharacters, CoffeeStringSubstitution)), TripleDoubleQuote), function($skip, $loc, $0, $1, $2, $3) {
9980
- return dedentBlockSubstitutions($0);
10039
+ return dedentBlockSubstitutions($0, module.config.tab);
9981
10040
  });
9982
10041
  var TemplateLiteral$3 = $TS($S(TripleSingleQuote, TripleSingleStringCharacters, TripleSingleQuote), function($skip, $loc, $0, $1, $2, $3) {
9983
10042
  var s = $1;
@@ -9985,7 +10044,7 @@ ${input.slice(result.pos)}
9985
10044
  var e = $3;
9986
10045
  return {
9987
10046
  type: "TemplateLiteral",
9988
- children: [s, dedentBlockString(str), e]
10047
+ children: [s, dedentBlockString(str, module.config.tab), e]
9989
10048
  };
9990
10049
  });
9991
10050
  var TemplateLiteral$4 = CoffeeInterpolatedDoubleQuotedString;
@@ -10065,13 +10124,13 @@ ${input.slice(result.pos)}
10065
10124
  function CoffeeHereCommentStart(ctx, state) {
10066
10125
  return $EVENT(ctx, state, "CoffeeHereCommentStart", CoffeeHereCommentStart$0);
10067
10126
  }
10068
- var InlineComment$0 = $TV($TEXT($S($EXPECT($L109, 'InlineComment "/*"'), $TEXT($Q($S($N($EXPECT($L110, 'InlineComment "*/"')), $EXPECT($R46, "InlineComment /[^\\r\\n]/")))), $EXPECT($L110, 'InlineComment "*/"'))), function($skip, $loc, $0, $1) {
10069
- return { $loc, token: $1 };
10127
+ var InlineComment$0 = $TR($EXPECT($R46, "InlineComment /\\/\\*(?:(?!\\*\\/)[^\\r\\n])*\\*\\//"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
10128
+ return { $loc, token: $0 };
10070
10129
  });
10071
10130
  function InlineComment(ctx, state) {
10072
10131
  return $EVENT(ctx, state, "InlineComment", InlineComment$0);
10073
10132
  }
10074
- var RestOfLine$0 = $S($Q($C(NonNewlineWhitespace, SingleLineComment, MultiLineComment)), EOL);
10133
+ var RestOfLine$0 = $S($Q($C(NonNewlineWhitespace, Comment)), EOL);
10075
10134
  function RestOfLine(ctx, state) {
10076
10135
  return $EVENT(ctx, state, "RestOfLine", RestOfLine$0);
10077
10136
  }
@@ -12481,7 +12540,7 @@ ${input.slice(result.pos)}
12481
12540
  indexOf(indexOfRef) {
12482
12541
  const typeSuffix = {
12483
12542
  ts: true,
12484
- children: [": <T>(this: T[], searchElement: T) => boolean"]
12543
+ children: [": <T>(this: T[], searchElement: T) => number"]
12485
12544
  };
12486
12545
  module.prelude.push(["", [preludeVar, indexOfRef, typeSuffix, " = [].indexOf", asAny, ";\n"]]);
12487
12546
  },
@@ -12619,8 +12678,8 @@ ${input.slice(result.pos)}
12619
12678
  function Reset(ctx, state) {
12620
12679
  return $EVENT(ctx, state, "Reset", Reset$0);
12621
12680
  }
12622
- var Init$0 = $TS($S($E(Shebang), $Q(TripleSlashDirective), $Q(DirectivePrologue)), function($skip, $loc, $0, $1, $2, $3) {
12623
- var directives = $3;
12681
+ var Init$0 = $TS($S($E(Shebang), $Q($C(TripleSlashDirective, $S($C(JSSingleLineComment, JSMultiLineComment), EOS), DirectivePrologue))), function($skip, $loc, $0, $1, $2) {
12682
+ var directives = $2;
12624
12683
  directives.forEach((directive) => {
12625
12684
  if (directive.type === "CivetPrologue") {
12626
12685
  Object.assign(module.config, directive.config);
@@ -12632,15 +12691,7 @@ ${input.slice(result.pos)}
12632
12691
  return $EVENT(ctx, state, "Init", Init$0);
12633
12692
  }
12634
12693
  var Indent$0 = $TR($EXPECT($R67, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
12635
- let level;
12636
- if (module.config.tab) {
12637
- const tabs = $0.match(/\t/g);
12638
- const numTabs = tabs ? tabs.length : 0;
12639
- level = numTabs * module.config.tab + /*spaces*/
12640
- ($0.length - numTabs);
12641
- } else {
12642
- level = $0.length;
12643
- }
12694
+ const level = getIndentLevel($0, module.config.tab);
12644
12695
  return {
12645
12696
  $loc,
12646
12697
  token: $0,
@@ -13438,6 +13489,7 @@ ${input.slice(result.pos)}
13438
13489
  expressionizeIfClause,
13439
13490
  forRange,
13440
13491
  gatherBindingCode,
13492
+ getIndentLevel,
13441
13493
  getTrimmingSpace,
13442
13494
  hasAwait,
13443
13495
  hasYield,
@@ -13991,15 +14043,55 @@ ${input.slice(result.pos)}
13991
14043
  if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
13992
14044
  options.parseOptions.coffeeCompat = true;
13993
14045
  }
14046
+ ;
14047
+ const { hits, trace, noCache } = options;
13994
14048
  let events;
13995
- if (!options.noCache) {
13996
- events = makeCache();
14049
+ if (!noCache) {
14050
+ events = makeCache({
14051
+ hits: !!hits,
14052
+ trace: !!trace
14053
+ });
14054
+ }
14055
+ let ast;
14056
+ try {
14057
+ parse.config = options.parseOptions || {};
14058
+ ast = prune(parse(src, {
14059
+ filename,
14060
+ events
14061
+ }));
14062
+ } finally {
14063
+ if (hits || trace) {
14064
+ import("fs").then(function({ writeFileSync }) {
14065
+ let ref;
14066
+ if ((ref = events?.meta) && "logs" in ref) {
14067
+ const { logs } = ref;
14068
+ if (trace) {
14069
+ writeFileSync(trace, logs.join("\n"));
14070
+ }
14071
+ }
14072
+ if (hits) {
14073
+ let ref1;
14074
+ if (ref1 = events?.meta.hits) {
14075
+ const hitData = ref1;
14076
+ let total = 0;
14077
+ const data = [...hitData.entries()];
14078
+ const counts = data.sort(([, a], [, b]) => b - a).map(([k, v]) => {
14079
+ total += v;
14080
+ return `${k}: ${v}`;
14081
+ }).join("\n");
14082
+ const hitSummary = `Total: ${total}
14083
+
14084
+ ${counts}`;
14085
+ return writeFileSync(hits, hitSummary);
14086
+ }
14087
+ ;
14088
+ return;
14089
+ }
14090
+ ;
14091
+ return;
14092
+ });
14093
+ }
13997
14094
  }
13998
- parse.config = options.parseOptions || {};
13999
- const ast = prune(parse(src, {
14000
- filename,
14001
- events
14002
- }));
14003
14095
  if (options.ast) {
14004
14096
  return ast;
14005
14097
  }
@@ -14022,22 +14114,45 @@ ${input.slice(result.pos)}
14022
14114
  }
14023
14115
  return result;
14024
14116
  }
14025
- function makeCache() {
14117
+ function makeCache({ hits, trace } = {}) {
14118
+ const meta = {};
14119
+ let hitCount;
14120
+ if (hits) {
14121
+ hitCount = /* @__PURE__ */ new Map();
14122
+ meta.hits = hitCount;
14123
+ }
14124
+ let logs;
14125
+ if (trace) {
14126
+ logs = [];
14127
+ meta.logs = logs;
14128
+ }
14026
14129
  const stateCache = new StateCache();
14027
14130
  let getStateKey = null;
14131
+ const stack = [];
14028
14132
  const events = {
14133
+ meta,
14029
14134
  enter: function(ruleName, state) {
14135
+ if (hits) {
14136
+ hitCount.set(ruleName, (hitCount.get(ruleName) || 0) + 1);
14137
+ }
14030
14138
  if (uncacheable.has(ruleName)) {
14031
14139
  return;
14032
14140
  }
14033
14141
  ;
14034
14142
  const key = [ruleName, state.pos, ...getStateKey()];
14035
14143
  if (stateCache.has(key)) {
14144
+ if (trace) {
14145
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u{1F4B0}");
14146
+ }
14036
14147
  const result = stateCache.get(key);
14037
14148
  return {
14038
14149
  cache: result ? { ...result } : void 0
14039
14150
  };
14040
14151
  }
14152
+ if (trace) {
14153
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u2192");
14154
+ stack.push(ruleName);
14155
+ }
14041
14156
  return;
14042
14157
  },
14043
14158
  exit: function(ruleName, state, result) {
@@ -14055,6 +14170,10 @@ ${input.slice(result.pos)}
14055
14170
  if (parse.config.verbose && result) {
14056
14171
  console.log(`Parsed ${JSON.stringify(state.input.slice(state.pos, result.pos))} [pos ${state.pos}-${result.pos}] as ${ruleName}`);
14057
14172
  }
14173
+ if (trace) {
14174
+ stack.pop();
14175
+ logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + " " + (result ? "\u2705" : "\u274C"));
14176
+ }
14058
14177
  return;
14059
14178
  }
14060
14179
  };
package/dist/civet CHANGED
@@ -153,6 +153,14 @@ parseArgs = function(args) {
153
153
  options.js = true;
154
154
  break;
155
155
  }
156
+ case "--hits": {
157
+ options.hits = args[++i];
158
+ break;
159
+ }
160
+ case "--trace": {
161
+ options.trace = args[++i];
162
+ break;
163
+ }
156
164
  case "--": {
157
165
  endOfArgs(++i);
158
166
  break;
package/dist/config.js CHANGED
@@ -84,7 +84,7 @@ async function loadConfig(path2) {
84
84
  const js = (0, import_main.compile)(config, { js: true });
85
85
  let exports;
86
86
  try {
87
- exports = await import(`data:text/javascript,${js}`);
87
+ exports = await import(`data:text/javascript,${encodeURIComponent(js)}`);
88
88
  } catch (e) {
89
89
  console.error("Error loading config file", path2, e);
90
90
  }