@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 +201 -82
- package/dist/civet +8 -0
- package/dist/config.js +1 -1
- package/dist/main.js +194 -82
- package/dist/main.mjs +194 -82
- package/dist/ts-diagnostic.js +5 -2
- package/dist/ts-diagnostic.mjs +5 -2
- package/package.json +2 -2
package/dist/main.js
CHANGED
|
@@ -729,57 +729,107 @@ var require_lib = __commonJS({
|
|
|
729
729
|
}
|
|
730
730
|
return [constructInvocation(fn, arg), null];
|
|
731
731
|
}
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
str
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
732
|
+
function getIndentLevel(str, tab) {
|
|
733
|
+
if (tab != null && tab != 1) {
|
|
734
|
+
const tabs = str.match(/\t/g);
|
|
735
|
+
const numTabs = tabs ? tabs.length : 0;
|
|
736
|
+
return numTabs * tab + /*spaces*/
|
|
737
|
+
(str.length - numTabs);
|
|
738
|
+
} else {
|
|
739
|
+
return str.length;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
function reduceIndentLevel(str, dedent, tab) {
|
|
743
|
+
if (tab != null && tab != 1) {
|
|
744
|
+
for (let i1 = 0, len1 = str.length; i1 < len1; i1++) {
|
|
745
|
+
const i = i1;
|
|
746
|
+
const char = str[i1];
|
|
747
|
+
if (!dedent) {
|
|
748
|
+
return str.slice(i);
|
|
749
|
+
}
|
|
750
|
+
if (char == " ") {
|
|
751
|
+
dedent -= tab;
|
|
752
|
+
if (dedent < 0) {
|
|
753
|
+
return "".padStart(-dedent, " ") + str.slice(i + 1);
|
|
754
|
+
}
|
|
755
|
+
} else {
|
|
756
|
+
dedent--;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
return "";
|
|
760
|
+
} else {
|
|
761
|
+
return str.slice(dedent);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
var indentRe = /\n([ \t]*)(?![ \t]|\r?\n|$)/g;
|
|
765
|
+
function getIndentOfBlockString(str, tab) {
|
|
766
|
+
let minLevel = Infinity;
|
|
767
|
+
let ref1;
|
|
768
|
+
while (ref1 = indentRe.exec(str)) {
|
|
769
|
+
const match = ref1;
|
|
770
|
+
const level = getIndentLevel(match[1], tab);
|
|
771
|
+
if (level < minLevel) {
|
|
772
|
+
minLevel = level;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
if (minLevel == Infinity) {
|
|
776
|
+
minLevel = 0;
|
|
777
|
+
}
|
|
778
|
+
return minLevel;
|
|
779
|
+
}
|
|
780
|
+
function dedentBlockString({ $loc, token: str }, tab, dedent, trimStart = true, trimEnd = true) {
|
|
781
|
+
if (dedent == null && /^[ \t]*\r?\n/.test(str)) {
|
|
782
|
+
dedent = getIndentOfBlockString(str, tab);
|
|
783
|
+
}
|
|
784
|
+
if (dedent) {
|
|
785
|
+
str = str.replace(/(\n)([ \t]*)/g, (_, newline, indent) => {
|
|
786
|
+
return newline + reduceIndentLevel(indent, dedent, tab);
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
if (trimStart) {
|
|
790
|
+
str = str.replace(/^[ \t]*\r?\n/, "");
|
|
791
|
+
}
|
|
792
|
+
if (trimEnd) {
|
|
793
|
+
str = str.replace(/(\r?\n|\n)[ \t]*$/, "");
|
|
744
794
|
}
|
|
745
795
|
str = str.replace(/(\\.|`|\$\{)/g, (s) => {
|
|
746
796
|
if (s[0] === "\\") {
|
|
747
797
|
return s;
|
|
798
|
+
} else {
|
|
799
|
+
return `\\${s}`;
|
|
748
800
|
}
|
|
749
|
-
return `\\${s}`;
|
|
750
801
|
});
|
|
751
|
-
return {
|
|
752
|
-
$loc,
|
|
753
|
-
token: str
|
|
754
|
-
};
|
|
802
|
+
return { $loc, token: str };
|
|
755
803
|
}
|
|
756
|
-
function dedentBlockSubstitutions($0) {
|
|
804
|
+
function dedentBlockSubstitutions($0, tab) {
|
|
757
805
|
const [s, strWithSubstitutions, e] = $0;
|
|
758
|
-
if (strWithSubstitutions.length
|
|
806
|
+
if (!strWithSubstitutions.length) {
|
|
759
807
|
return $0;
|
|
760
808
|
}
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
initialSpacing = false;
|
|
767
|
-
}
|
|
768
|
-
while (i < l) {
|
|
769
|
-
let segment = strWithSubstitutions[i];
|
|
770
|
-
if (segment.token) {
|
|
771
|
-
segment = dedentBlockString(segment, initialSpacing, false);
|
|
772
|
-
if (i === 0) {
|
|
773
|
-
segment.token = segment.token.replace(/^(\r?\n|\n)/, "");
|
|
774
|
-
}
|
|
775
|
-
if (i === l - 1) {
|
|
776
|
-
segment.token = segment.token.replace(/(\r?\n|\n)[ \t]*$/, "");
|
|
777
|
-
}
|
|
778
|
-
results.push(segment);
|
|
779
|
-
} else {
|
|
780
|
-
results.push(segment);
|
|
809
|
+
const stringPart = (() => {
|
|
810
|
+
const results1 = [];
|
|
811
|
+
for (let i2 = 0, len2 = strWithSubstitutions.length; i2 < len2; i2++) {
|
|
812
|
+
const part = strWithSubstitutions[i2];
|
|
813
|
+
results1.push(part.token ?? "s");
|
|
781
814
|
}
|
|
782
|
-
|
|
815
|
+
;
|
|
816
|
+
return results1;
|
|
817
|
+
})().join("");
|
|
818
|
+
const dedent = /^[ \t]*\r?\n/.test(stringPart) ? getIndentOfBlockString(stringPart, tab) : false;
|
|
819
|
+
let results = [s];
|
|
820
|
+
for (let i3 = 0, len3 = strWithSubstitutions.length; i3 < len3; i3++) {
|
|
821
|
+
const i = i3;
|
|
822
|
+
let part = strWithSubstitutions[i3];
|
|
823
|
+
if (part.token != null) {
|
|
824
|
+
part = dedentBlockString(
|
|
825
|
+
part,
|
|
826
|
+
tab,
|
|
827
|
+
dedent,
|
|
828
|
+
i === 0,
|
|
829
|
+
i === strWithSubstitutions.length - 1
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
results.push(part);
|
|
783
833
|
}
|
|
784
834
|
results.push(e);
|
|
785
835
|
return {
|
|
@@ -1308,17 +1358,17 @@ var require_lib = __commonJS({
|
|
|
1308
1358
|
}
|
|
1309
1359
|
function arrayRecurse(array) {
|
|
1310
1360
|
const len2 = array.length;
|
|
1311
|
-
const
|
|
1361
|
+
const results2 = [];
|
|
1312
1362
|
for (let i = 0; i < len2; i++) {
|
|
1313
1363
|
const c = array[i];
|
|
1314
1364
|
if (c === child || Array.isArray(c) && arrayRecurse(c)) {
|
|
1315
1365
|
return true;
|
|
1316
1366
|
} else {
|
|
1317
|
-
|
|
1367
|
+
results2.push(void 0);
|
|
1318
1368
|
}
|
|
1319
1369
|
}
|
|
1320
1370
|
;
|
|
1321
|
-
return
|
|
1371
|
+
return results2;
|
|
1322
1372
|
}
|
|
1323
1373
|
return -1;
|
|
1324
1374
|
}
|
|
@@ -2312,9 +2362,11 @@ var require_lib = __commonJS({
|
|
|
2312
2362
|
}
|
|
2313
2363
|
if (expr.type === "AssignmentExpression" || expr.type === "UpdateExpression") {
|
|
2314
2364
|
if (expr.type === "UpdateExpression" && expr.children[0] === expr.assigned) {
|
|
2315
|
-
|
|
2365
|
+
pre.push("(");
|
|
2366
|
+
post.push([", ", lhs, ")"]);
|
|
2316
2367
|
} else {
|
|
2317
|
-
pre.push([lhs, ", "]);
|
|
2368
|
+
pre.push(["(", lhs, ", "]);
|
|
2369
|
+
post.push(")");
|
|
2318
2370
|
}
|
|
2319
2371
|
return expr.assigned;
|
|
2320
2372
|
}
|
|
@@ -3460,7 +3512,7 @@ var require_lib = __commonJS({
|
|
|
3460
3512
|
gatherRecursive,
|
|
3461
3513
|
gatherRecursiveAll,
|
|
3462
3514
|
gatherRecursiveWithinFunction,
|
|
3463
|
-
|
|
3515
|
+
getIndentLevel,
|
|
3464
3516
|
getTrimmingSpace,
|
|
3465
3517
|
hasAwait,
|
|
3466
3518
|
hasYield,
|
|
@@ -4469,7 +4521,7 @@ var require_parser = __commonJS({
|
|
|
4469
4521
|
var $R43 = $R(new RegExp("#(?!##(?!#))([^\\r\\n]*)", "suy"));
|
|
4470
4522
|
var $R44 = $R(new RegExp("[^]*?###", "suy"));
|
|
4471
4523
|
var $R45 = $R(new RegExp("###(?!#)", "suy"));
|
|
4472
|
-
var $R46 = $R(new RegExp("[^\\r\\n]", "suy"));
|
|
4524
|
+
var $R46 = $R(new RegExp("\\/\\*(?:(?!\\*\\/)[^\\r\\n])*\\*\\/", "suy"));
|
|
4473
4525
|
var $R47 = $R(new RegExp("[ \\t]+", "suy"));
|
|
4474
4526
|
var $R48 = $R(new RegExp("(?!\\p{ID_Continue})", "suy"));
|
|
4475
4527
|
var $R49 = $R(new RegExp("['\u2019]s", "suy"));
|
|
@@ -5517,7 +5569,7 @@ var require_parser = __commonJS({
|
|
|
5517
5569
|
function CallExpressionRest(ctx, state) {
|
|
5518
5570
|
return $EVENT_C(ctx, state, "CallExpressionRest", CallExpressionRest$$);
|
|
5519
5571
|
}
|
|
5520
|
-
var OptionalShorthand$0 = $TS($S($Q(
|
|
5572
|
+
var OptionalShorthand$0 = $TS($S($Q(InlineComment), QuestionMark, OptionalDot), function($skip, $loc, $0, $1, $2, $3) {
|
|
5521
5573
|
return {
|
|
5522
5574
|
type: "Optional",
|
|
5523
5575
|
children: $0
|
|
@@ -5526,8 +5578,8 @@ var require_parser = __commonJS({
|
|
|
5526
5578
|
function OptionalShorthand(ctx, state) {
|
|
5527
5579
|
return $EVENT(ctx, state, "OptionalShorthand", OptionalShorthand$0);
|
|
5528
5580
|
}
|
|
5529
|
-
var OptionalDot$0 = $S($Q(
|
|
5530
|
-
var OptionalDot$1 = $S(InsertDot, $Q(
|
|
5581
|
+
var OptionalDot$0 = $S($Q(InlineComment), Dot);
|
|
5582
|
+
var OptionalDot$1 = $S(InsertDot, $Q(InlineComment));
|
|
5531
5583
|
var OptionalDot$$ = [OptionalDot$0, OptionalDot$1];
|
|
5532
5584
|
function OptionalDot(ctx, state) {
|
|
5533
5585
|
return $EVENT_C(ctx, state, "OptionalDot", OptionalDot$$);
|
|
@@ -5558,7 +5610,7 @@ var require_parser = __commonJS({
|
|
|
5558
5610
|
function MemberBase(ctx, state) {
|
|
5559
5611
|
return $EVENT_C(ctx, state, "MemberBase", MemberBase$$);
|
|
5560
5612
|
}
|
|
5561
|
-
var MemberExpressionRest$0 = $TS($S($Q(
|
|
5613
|
+
var MemberExpressionRest$0 = $TS($S($Q(InlineComment), MemberExpressionRestBody), function($skip, $loc, $0, $1, $2) {
|
|
5562
5614
|
var comments = $1;
|
|
5563
5615
|
var body = $2;
|
|
5564
5616
|
if (Array.isArray(body))
|
|
@@ -5571,7 +5623,7 @@ var require_parser = __commonJS({
|
|
|
5571
5623
|
function MemberExpressionRest(ctx, state) {
|
|
5572
5624
|
return $EVENT(ctx, state, "MemberExpressionRest", MemberExpressionRest$0);
|
|
5573
5625
|
}
|
|
5574
|
-
var MemberExpressionRestBody$0 = $TS($S($E($C(OptionalShorthand, NonNullAssertion)), $Q(
|
|
5626
|
+
var MemberExpressionRestBody$0 = $TS($S($E($C(OptionalShorthand, NonNullAssertion)), $Q(InlineComment), MemberBracketContent), function($skip, $loc, $0, $1, $2, $3) {
|
|
5575
5627
|
var dot = $1;
|
|
5576
5628
|
var comments = $2;
|
|
5577
5629
|
var content = $3;
|
|
@@ -5729,7 +5781,7 @@ var require_parser = __commonJS({
|
|
|
5729
5781
|
function AccessStart(ctx, state) {
|
|
5730
5782
|
return $EVENT(ctx, state, "AccessStart", AccessStart$0);
|
|
5731
5783
|
}
|
|
5732
|
-
var PropertyAccess$0 = $TS($S(AccessStart, $Q(
|
|
5784
|
+
var PropertyAccess$0 = $TS($S(AccessStart, $Q(InlineComment), $C(IdentifierName, PrivateIdentifier)), function($skip, $loc, $0, $1, $2, $3) {
|
|
5733
5785
|
var access = $1;
|
|
5734
5786
|
var comments = $2;
|
|
5735
5787
|
var id = $3;
|
|
@@ -5761,7 +5813,7 @@ var require_parser = __commonJS({
|
|
|
5761
5813
|
function PropertyAccess(ctx, state) {
|
|
5762
5814
|
return $EVENT_C(ctx, state, "PropertyAccess", PropertyAccess$$);
|
|
5763
5815
|
}
|
|
5764
|
-
var PropertyGlob$0 = $TS($S($S($E($C(QuestionMark, NonNullAssertion)), OptionalDot), $Q(
|
|
5816
|
+
var PropertyGlob$0 = $TS($S($S($E($C(QuestionMark, NonNullAssertion)), OptionalDot), $Q(InlineComment), BracedObjectLiteral), function($skip, $loc, $0, $1, $2, $3) {
|
|
5765
5817
|
var dot = $1;
|
|
5766
5818
|
var object = $3;
|
|
5767
5819
|
return {
|
|
@@ -7118,7 +7170,7 @@ var require_parser = __commonJS({
|
|
|
7118
7170
|
names: exp.names
|
|
7119
7171
|
};
|
|
7120
7172
|
});
|
|
7121
|
-
var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)),
|
|
7173
|
+
var ArrayElementExpression$2 = $TS($S($E($S($E($S(__, DotDotDot, __)), PostfixedExpression)), $Y(ArrayElementDelimiter)), function($skip, $loc, $0, $1, $2) {
|
|
7122
7174
|
var expMaybeSpread = $1;
|
|
7123
7175
|
if (expMaybeSpread) {
|
|
7124
7176
|
const [spread, exp] = expMaybeSpread;
|
|
@@ -8672,7 +8724,7 @@ var require_parser = __commonJS({
|
|
|
8672
8724
|
children: $0
|
|
8673
8725
|
};
|
|
8674
8726
|
});
|
|
8675
|
-
var ForStatementParameters$1 = $TS($S(InsertOpenParen, __, $C(LexicalDeclaration, VariableStatement, $E(Expression)), __, Semicolon, $E(Expression), Semicolon, $E($S($N(EOS),
|
|
8727
|
+
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) {
|
|
8676
8728
|
var declaration = $3;
|
|
8677
8729
|
return {
|
|
8678
8730
|
declaration,
|
|
@@ -9967,7 +10019,7 @@ var require_parser = __commonJS({
|
|
|
9967
10019
|
return $EVENT(ctx, state, "RegularExpressionFlags", RegularExpressionFlags$0);
|
|
9968
10020
|
}
|
|
9969
10021
|
var TemplateLiteral$0 = $TS($S(TripleTick, $Q($C(TemplateBlockCharacters, TemplateSubstitution)), TripleTick), function($skip, $loc, $0, $1, $2, $3) {
|
|
9970
|
-
return dedentBlockSubstitutions($0);
|
|
10022
|
+
return dedentBlockSubstitutions($0, module2.config.tab);
|
|
9971
10023
|
});
|
|
9972
10024
|
var TemplateLiteral$1 = $TS($S(Backtick, $Q($C(TemplateCharacters, TemplateSubstitution)), Backtick), function($skip, $loc, $0, $1, $2, $3) {
|
|
9973
10025
|
return {
|
|
@@ -9976,7 +10028,7 @@ var require_parser = __commonJS({
|
|
|
9976
10028
|
};
|
|
9977
10029
|
});
|
|
9978
10030
|
var TemplateLiteral$2 = $TS($S(TripleDoubleQuote, $Q($C(TripleDoubleStringCharacters, CoffeeStringSubstitution)), TripleDoubleQuote), function($skip, $loc, $0, $1, $2, $3) {
|
|
9979
|
-
return dedentBlockSubstitutions($0);
|
|
10031
|
+
return dedentBlockSubstitutions($0, module2.config.tab);
|
|
9980
10032
|
});
|
|
9981
10033
|
var TemplateLiteral$3 = $TS($S(TripleSingleQuote, TripleSingleStringCharacters, TripleSingleQuote), function($skip, $loc, $0, $1, $2, $3) {
|
|
9982
10034
|
var s = $1;
|
|
@@ -9984,7 +10036,7 @@ var require_parser = __commonJS({
|
|
|
9984
10036
|
var e = $3;
|
|
9985
10037
|
return {
|
|
9986
10038
|
type: "TemplateLiteral",
|
|
9987
|
-
children: [s, dedentBlockString(str), e]
|
|
10039
|
+
children: [s, dedentBlockString(str, module2.config.tab), e]
|
|
9988
10040
|
};
|
|
9989
10041
|
});
|
|
9990
10042
|
var TemplateLiteral$4 = CoffeeInterpolatedDoubleQuotedString;
|
|
@@ -10064,13 +10116,13 @@ var require_parser = __commonJS({
|
|
|
10064
10116
|
function CoffeeHereCommentStart(ctx, state) {
|
|
10065
10117
|
return $EVENT(ctx, state, "CoffeeHereCommentStart", CoffeeHereCommentStart$0);
|
|
10066
10118
|
}
|
|
10067
|
-
var InlineComment$0 = $
|
|
10068
|
-
return { $loc, token: $
|
|
10119
|
+
var InlineComment$0 = $TR($EXPECT($R46, "InlineComment /\\/\\*(?:(?!\\*\\/)[^\\r\\n])*\\*\\//"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
|
|
10120
|
+
return { $loc, token: $0 };
|
|
10069
10121
|
});
|
|
10070
10122
|
function InlineComment(ctx, state) {
|
|
10071
10123
|
return $EVENT(ctx, state, "InlineComment", InlineComment$0);
|
|
10072
10124
|
}
|
|
10073
|
-
var RestOfLine$0 = $S($Q($C(NonNewlineWhitespace,
|
|
10125
|
+
var RestOfLine$0 = $S($Q($C(NonNewlineWhitespace, Comment)), EOL);
|
|
10074
10126
|
function RestOfLine(ctx, state) {
|
|
10075
10127
|
return $EVENT(ctx, state, "RestOfLine", RestOfLine$0);
|
|
10076
10128
|
}
|
|
@@ -12480,7 +12532,7 @@ var require_parser = __commonJS({
|
|
|
12480
12532
|
indexOf(indexOfRef) {
|
|
12481
12533
|
const typeSuffix = {
|
|
12482
12534
|
ts: true,
|
|
12483
|
-
children: [": <T>(this: T[], searchElement: T) =>
|
|
12535
|
+
children: [": <T>(this: T[], searchElement: T) => number"]
|
|
12484
12536
|
};
|
|
12485
12537
|
module2.prelude.push(["", [preludeVar, indexOfRef, typeSuffix, " = [].indexOf", asAny, ";\n"]]);
|
|
12486
12538
|
},
|
|
@@ -12618,8 +12670,8 @@ var require_parser = __commonJS({
|
|
|
12618
12670
|
function Reset(ctx, state) {
|
|
12619
12671
|
return $EVENT(ctx, state, "Reset", Reset$0);
|
|
12620
12672
|
}
|
|
12621
|
-
var Init$0 = $TS($S($E(Shebang), $Q(TripleSlashDirective
|
|
12622
|
-
var directives = $
|
|
12673
|
+
var Init$0 = $TS($S($E(Shebang), $Q($C(TripleSlashDirective, $S($C(JSSingleLineComment, JSMultiLineComment), EOS), DirectivePrologue))), function($skip, $loc, $0, $1, $2) {
|
|
12674
|
+
var directives = $2;
|
|
12623
12675
|
directives.forEach((directive) => {
|
|
12624
12676
|
if (directive.type === "CivetPrologue") {
|
|
12625
12677
|
Object.assign(module2.config, directive.config);
|
|
@@ -12631,15 +12683,7 @@ var require_parser = __commonJS({
|
|
|
12631
12683
|
return $EVENT(ctx, state, "Init", Init$0);
|
|
12632
12684
|
}
|
|
12633
12685
|
var Indent$0 = $TR($EXPECT($R67, "Indent /[ \\t]*/"), function($skip, $loc, $0, $1, $2, $3, $4, $5, $6, $7, $8, $9) {
|
|
12634
|
-
|
|
12635
|
-
if (module2.config.tab) {
|
|
12636
|
-
const tabs = $0.match(/\t/g);
|
|
12637
|
-
const numTabs = tabs ? tabs.length : 0;
|
|
12638
|
-
level = numTabs * module2.config.tab + /*spaces*/
|
|
12639
|
-
($0.length - numTabs);
|
|
12640
|
-
} else {
|
|
12641
|
-
level = $0.length;
|
|
12642
|
-
}
|
|
12686
|
+
const level = getIndentLevel($0, module2.config.tab);
|
|
12643
12687
|
return {
|
|
12644
12688
|
$loc,
|
|
12645
12689
|
token: $0,
|
|
@@ -13437,6 +13481,7 @@ var require_parser = __commonJS({
|
|
|
13437
13481
|
expressionizeIfClause,
|
|
13438
13482
|
forRange,
|
|
13439
13483
|
gatherBindingCode,
|
|
13484
|
+
getIndentLevel,
|
|
13440
13485
|
getTrimmingSpace,
|
|
13441
13486
|
hasAwait,
|
|
13442
13487
|
hasYield,
|
|
@@ -13991,15 +14036,55 @@ function compile(src, options) {
|
|
|
13991
14036
|
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
13992
14037
|
options.parseOptions.coffeeCompat = true;
|
|
13993
14038
|
}
|
|
14039
|
+
;
|
|
14040
|
+
const { hits, trace, noCache } = options;
|
|
13994
14041
|
let events;
|
|
13995
|
-
if (!
|
|
13996
|
-
events = makeCache(
|
|
14042
|
+
if (!noCache) {
|
|
14043
|
+
events = makeCache({
|
|
14044
|
+
hits: !!hits,
|
|
14045
|
+
trace: !!trace
|
|
14046
|
+
});
|
|
14047
|
+
}
|
|
14048
|
+
let ast;
|
|
14049
|
+
try {
|
|
14050
|
+
parse.config = options.parseOptions || {};
|
|
14051
|
+
ast = prune(parse(src, {
|
|
14052
|
+
filename,
|
|
14053
|
+
events
|
|
14054
|
+
}));
|
|
14055
|
+
} finally {
|
|
14056
|
+
if (hits || trace) {
|
|
14057
|
+
import("fs").then(function({ writeFileSync }) {
|
|
14058
|
+
let ref;
|
|
14059
|
+
if ((ref = events?.meta) && "logs" in ref) {
|
|
14060
|
+
const { logs } = ref;
|
|
14061
|
+
if (trace) {
|
|
14062
|
+
writeFileSync(trace, logs.join("\n"));
|
|
14063
|
+
}
|
|
14064
|
+
}
|
|
14065
|
+
if (hits) {
|
|
14066
|
+
let ref1;
|
|
14067
|
+
if (ref1 = events?.meta.hits) {
|
|
14068
|
+
const hitData = ref1;
|
|
14069
|
+
let total = 0;
|
|
14070
|
+
const data = [...hitData.entries()];
|
|
14071
|
+
const counts = data.sort(([, a], [, b]) => b - a).map(([k, v]) => {
|
|
14072
|
+
total += v;
|
|
14073
|
+
return `${k}: ${v}`;
|
|
14074
|
+
}).join("\n");
|
|
14075
|
+
const hitSummary = `Total: ${total}
|
|
14076
|
+
|
|
14077
|
+
${counts}`;
|
|
14078
|
+
return writeFileSync(hits, hitSummary);
|
|
14079
|
+
}
|
|
14080
|
+
;
|
|
14081
|
+
return;
|
|
14082
|
+
}
|
|
14083
|
+
;
|
|
14084
|
+
return;
|
|
14085
|
+
});
|
|
14086
|
+
}
|
|
13997
14087
|
}
|
|
13998
|
-
parse.config = options.parseOptions || {};
|
|
13999
|
-
const ast = prune(parse(src, {
|
|
14000
|
-
filename,
|
|
14001
|
-
events
|
|
14002
|
-
}));
|
|
14003
14088
|
if (options.ast) {
|
|
14004
14089
|
return ast;
|
|
14005
14090
|
}
|
|
@@ -14022,22 +14107,45 @@ function compile(src, options) {
|
|
|
14022
14107
|
}
|
|
14023
14108
|
return result;
|
|
14024
14109
|
}
|
|
14025
|
-
function makeCache() {
|
|
14110
|
+
function makeCache({ hits, trace } = {}) {
|
|
14111
|
+
const meta = {};
|
|
14112
|
+
let hitCount;
|
|
14113
|
+
if (hits) {
|
|
14114
|
+
hitCount = /* @__PURE__ */ new Map();
|
|
14115
|
+
meta.hits = hitCount;
|
|
14116
|
+
}
|
|
14117
|
+
let logs;
|
|
14118
|
+
if (trace) {
|
|
14119
|
+
logs = [];
|
|
14120
|
+
meta.logs = logs;
|
|
14121
|
+
}
|
|
14026
14122
|
const stateCache = new StateCache();
|
|
14027
14123
|
let getStateKey = null;
|
|
14124
|
+
const stack = [];
|
|
14028
14125
|
const events = {
|
|
14126
|
+
meta,
|
|
14029
14127
|
enter: function(ruleName, state) {
|
|
14128
|
+
if (hits) {
|
|
14129
|
+
hitCount.set(ruleName, (hitCount.get(ruleName) || 0) + 1);
|
|
14130
|
+
}
|
|
14030
14131
|
if (uncacheable.has(ruleName)) {
|
|
14031
14132
|
return;
|
|
14032
14133
|
}
|
|
14033
14134
|
;
|
|
14034
14135
|
const key = [ruleName, state.pos, ...getStateKey()];
|
|
14035
14136
|
if (stateCache.has(key)) {
|
|
14137
|
+
if (trace) {
|
|
14138
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u{1F4B0}");
|
|
14139
|
+
}
|
|
14036
14140
|
const result = stateCache.get(key);
|
|
14037
14141
|
return {
|
|
14038
14142
|
cache: result ? { ...result } : void 0
|
|
14039
14143
|
};
|
|
14040
14144
|
}
|
|
14145
|
+
if (trace) {
|
|
14146
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + "\u2192");
|
|
14147
|
+
stack.push(ruleName);
|
|
14148
|
+
}
|
|
14041
14149
|
return;
|
|
14042
14150
|
},
|
|
14043
14151
|
exit: function(ruleName, state, result) {
|
|
@@ -14055,6 +14163,10 @@ function makeCache() {
|
|
|
14055
14163
|
if (parse.config.verbose && result) {
|
|
14056
14164
|
console.log(`Parsed ${JSON.stringify(state.input.slice(state.pos, result.pos))} [pos ${state.pos}-${result.pos}] as ${ruleName}`);
|
|
14057
14165
|
}
|
|
14166
|
+
if (trace) {
|
|
14167
|
+
stack.pop();
|
|
14168
|
+
logs.push("".padStart(stack.length * 2, " ") + ruleName + ":" + state.pos + " " + (result ? "\u2705" : "\u274C"));
|
|
14169
|
+
}
|
|
14058
14170
|
return;
|
|
14059
14171
|
}
|
|
14060
14172
|
};
|