@rohal12/spindle 0.59.25 → 0.59.27
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/pkg/format.js +1 -1
- package/dist/pkg/headless.js +592 -341
- package/dist/pkg/story-variables.js +654 -170
- package/dist/pkg/tooling.js +1 -0
- package/package.json +23 -24
- package/src/automation/load-yaml.ts +1 -1
- package/src/components/macros/MacroError.tsx +1 -1
- package/src/components/macros/SaveManager.tsx +2 -2
- package/src/components/macros/macro-args.ts +1 -2
- package/src/execute-mutation.ts +4 -3
- package/src/hooks/use-modal-focus.ts +1 -1
- package/src/hooks/use-story-fields.ts +1 -1
- package/src/macro-discovery.ts +299 -0
- package/src/markup/ast.ts +1 -5
- package/src/markup/code-attributes.ts +1 -3
- package/src/markup/code-end.ts +1 -1
- package/src/markup/line-column.ts +1 -1
- package/src/markup/pair.ts +1 -4
- package/src/markup/render.tsx +10 -9
- package/src/markup/validate.ts +27 -6
- package/src/static-literal.ts +223 -56
- package/src/store.ts +1 -1
- package/src/story-variables.ts +134 -26
- package/src/tooling.ts +28 -5
- package/src/types-drift-check.ts +17 -0
- package/src/widgets/ast-scanner.ts +4 -1
- package/src/widgets/widget-def.ts +5 -4
- package/types/index.d.ts +2 -10
- package/types/tooling.d.ts +56 -21
|
@@ -34,7 +34,7 @@ var grammar_shared_default = {
|
|
|
34
34
|
var LB = String.fromCharCode(123);
|
|
35
35
|
var RB = String.fromCharCode(125);
|
|
36
36
|
var { SIGIL_SCOPES: SIGIL_SCOPES$1, withSelectors } = grammar_shared_default;
|
|
37
|
-
var VOID_TAGS = new Set([
|
|
37
|
+
var VOID_TAGS = /* @__PURE__ */ new Set([
|
|
38
38
|
"area",
|
|
39
39
|
"base",
|
|
40
40
|
"br",
|
|
@@ -696,7 +696,7 @@ function peg$parse(input, options) {
|
|
|
696
696
|
return withSelectors(node, s);
|
|
697
697
|
}
|
|
698
698
|
function peg$f35() {
|
|
699
|
-
fail("Unclosed " +
|
|
699
|
+
fail("Unclosed {" + input.substr(location().end.offset, 1) + "…: no } ends it", location(), "unclosed-expression");
|
|
700
700
|
}
|
|
701
701
|
function peg$f36(start) {
|
|
702
702
|
return skipTo(hooks.closeBrace(input, start, start));
|
|
@@ -728,13 +728,13 @@ function peg$parse(input, options) {
|
|
|
728
728
|
tag.nameStart = nameEnd - name.length;
|
|
729
729
|
tag.nameEnd = nameEnd;
|
|
730
730
|
tag.selectorSpan = selectorSpan(s, ss, start);
|
|
731
|
-
if (tail === null) fail("Unclosed " +
|
|
731
|
+
if (tail === null) fail("Unclosed {" + (close ? "/" : "") + name + "…: no } ends the macro", loc, "unclosed-macro");
|
|
732
732
|
tag.rawArgs = tail.trim();
|
|
733
733
|
tag.argsStart = tag.rawArgs ? nameEnd + tail.length - tail.trimStart().length : nameEnd;
|
|
734
734
|
tag.argsEnd = tag.argsStart + tag.rawArgs.length;
|
|
735
735
|
if (close) {
|
|
736
736
|
if (s !== NO_SELECTORS) fail("A closing tag takes no selectors: " + label(tag), loc, "closer-with-selectors");
|
|
737
|
-
if (tag.rawArgs) fail("A closing tag takes no arguments:
|
|
737
|
+
if (tag.rawArgs) fail("A closing tag takes no arguments: {/" + name + " " + tag.rawArgs + RB, loc, "closer-with-arguments");
|
|
738
738
|
tag.kind = "close";
|
|
739
739
|
} else {
|
|
740
740
|
withSelectors(tag, s);
|
|
@@ -743,7 +743,7 @@ function peg$parse(input, options) {
|
|
|
743
743
|
return tag;
|
|
744
744
|
}
|
|
745
745
|
function peg$f43(s) {
|
|
746
|
-
fail("A closing tag starts with a letter after
|
|
746
|
+
fail("A closing tag starts with a letter after {/", location(), "invalid-closer");
|
|
747
747
|
}
|
|
748
748
|
function peg$f44(value) {
|
|
749
749
|
return EMAIL_AUTOLINK.test(value);
|
|
@@ -1622,12 +1622,14 @@ function peg$parse(input, options) {
|
|
|
1622
1622
|
s3 = peg$FAILED;
|
|
1623
1623
|
if (peg$silentFails === 0) peg$fail(peg$e13);
|
|
1624
1624
|
}
|
|
1625
|
-
if (s3 === peg$FAILED)
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1625
|
+
if (s3 === peg$FAILED) {
|
|
1626
|
+
if (input.substr(peg$currPos, 2) === peg$c8) {
|
|
1627
|
+
s3 = peg$c8;
|
|
1628
|
+
peg$currPos += 2;
|
|
1629
|
+
} else {
|
|
1630
|
+
s3 = peg$FAILED;
|
|
1631
|
+
if (peg$silentFails === 0) peg$fail(peg$e12);
|
|
1632
|
+
}
|
|
1631
1633
|
}
|
|
1632
1634
|
peg$silentFails--;
|
|
1633
1635
|
if (s3 === peg$FAILED) s2 = void 0;
|
|
@@ -1666,12 +1668,14 @@ function peg$parse(input, options) {
|
|
|
1666
1668
|
s3 = peg$FAILED;
|
|
1667
1669
|
if (peg$silentFails === 0) peg$fail(peg$e13);
|
|
1668
1670
|
}
|
|
1669
|
-
if (s3 === peg$FAILED)
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1671
|
+
if (s3 === peg$FAILED) {
|
|
1672
|
+
if (input.substr(peg$currPos, 2) === peg$c8) {
|
|
1673
|
+
s3 = peg$c8;
|
|
1674
|
+
peg$currPos += 2;
|
|
1675
|
+
} else {
|
|
1676
|
+
s3 = peg$FAILED;
|
|
1677
|
+
if (peg$silentFails === 0) peg$fail(peg$e12);
|
|
1678
|
+
}
|
|
1675
1679
|
}
|
|
1676
1680
|
peg$silentFails--;
|
|
1677
1681
|
if (s3 === peg$FAILED) s2 = void 0;
|
|
@@ -3354,7 +3358,7 @@ var BLOCK_MACROS = new NameSet([
|
|
|
3354
3358
|
"nobr"
|
|
3355
3359
|
]);
|
|
3356
3360
|
/** Macros whose body is JavaScript source, kept verbatim. */
|
|
3357
|
-
var RAW_BODY_MACROS = new Set(["do"]);
|
|
3361
|
+
var RAW_BODY_MACROS = /* @__PURE__ */ new Set(["do"]);
|
|
3358
3362
|
/** Whether a macro's body is JavaScript, kept verbatim (`{do}`). */
|
|
3359
3363
|
function isRawMacro(name) {
|
|
3360
3364
|
return RAW_BODY_MACROS.has(name);
|
|
@@ -3364,7 +3368,7 @@ function isBlockMacro(name) {
|
|
|
3364
3368
|
return BLOCK_MACROS.has(name);
|
|
3365
3369
|
}
|
|
3366
3370
|
/** Macros whose branches render as one: the node holds one per branch. */
|
|
3367
|
-
var BRANCHING = new Set([
|
|
3371
|
+
var BRANCHING = /* @__PURE__ */ new Set([
|
|
3368
3372
|
"if",
|
|
3369
3373
|
"switch",
|
|
3370
3374
|
"timed"
|
|
@@ -4669,7 +4673,8 @@ function binop(name, prec) {
|
|
|
4669
4673
|
binop: prec
|
|
4670
4674
|
});
|
|
4671
4675
|
}
|
|
4672
|
-
var beforeExpr = { beforeExpr: true }
|
|
4676
|
+
var beforeExpr = { beforeExpr: true };
|
|
4677
|
+
var startsExpr = { startsExpr: true };
|
|
4673
4678
|
var keywords = {};
|
|
4674
4679
|
function kw(name, options) {
|
|
4675
4680
|
if (options === void 0) options = {};
|
|
@@ -4924,11 +4929,27 @@ function pushComment(options, array) {
|
|
|
4924
4929
|
array.push(comment);
|
|
4925
4930
|
};
|
|
4926
4931
|
}
|
|
4927
|
-
var SCOPE_TOP = 1
|
|
4932
|
+
var SCOPE_TOP = 1;
|
|
4933
|
+
var SCOPE_FUNCTION = 2;
|
|
4934
|
+
var SCOPE_ASYNC = 4;
|
|
4935
|
+
var SCOPE_GENERATOR = 8;
|
|
4936
|
+
var SCOPE_ARROW = 16;
|
|
4937
|
+
var SCOPE_SIMPLE_CATCH = 32;
|
|
4938
|
+
var SCOPE_SUPER = 64;
|
|
4939
|
+
var SCOPE_DIRECT_SUPER = 128;
|
|
4940
|
+
var SCOPE_CLASS_STATIC_BLOCK = 256;
|
|
4941
|
+
var SCOPE_CLASS_FIELD_INIT = 512;
|
|
4942
|
+
var SCOPE_SWITCH = 1024;
|
|
4943
|
+
var SCOPE_VAR = SCOPE_TOP | SCOPE_FUNCTION | SCOPE_CLASS_STATIC_BLOCK;
|
|
4928
4944
|
function functionFlags(async, generator) {
|
|
4929
4945
|
return SCOPE_FUNCTION | (async ? SCOPE_ASYNC : 0) | (generator ? SCOPE_GENERATOR : 0);
|
|
4930
4946
|
}
|
|
4931
|
-
var BIND_NONE = 0
|
|
4947
|
+
var BIND_NONE = 0;
|
|
4948
|
+
var BIND_VAR = 1;
|
|
4949
|
+
var BIND_LEXICAL = 2;
|
|
4950
|
+
var BIND_FUNCTION = 3;
|
|
4951
|
+
var BIND_SIMPLE_CATCH = 4;
|
|
4952
|
+
var BIND_OUTSIDE = 5;
|
|
4932
4953
|
var Parser = function Parser(options, input, startPos) {
|
|
4933
4954
|
this.options = options = getOptions(options);
|
|
4934
4955
|
this.sourceFile = options.sourceFile;
|
|
@@ -5183,7 +5204,8 @@ pp$8.parseTopLevel = function(node) {
|
|
|
5183
5204
|
node.sourceType = this.options.sourceType === "commonjs" ? "script" : this.options.sourceType;
|
|
5184
5205
|
return this.finishNode(node, "Program");
|
|
5185
5206
|
};
|
|
5186
|
-
var loopLabel = { kind: "loop" }
|
|
5207
|
+
var loopLabel = { kind: "loop" };
|
|
5208
|
+
var switchLabel = { kind: "switch" };
|
|
5187
5209
|
pp$8.isLet = function(context) {
|
|
5188
5210
|
if (this.options.ecmaVersion < 6 || !this.isContextual("let")) return false;
|
|
5189
5211
|
skipWhiteSpace.lastIndex = this.pos;
|
|
@@ -5612,7 +5634,9 @@ pp$8.parseVarId = function(decl, kind) {
|
|
|
5612
5634
|
decl.id = kind === "using" || kind === "await using" ? this.parseIdent() : this.parseBindingAtom();
|
|
5613
5635
|
this.checkLValPattern(decl.id, kind === "var" ? BIND_VAR : BIND_LEXICAL, false);
|
|
5614
5636
|
};
|
|
5615
|
-
var FUNC_STATEMENT = 1
|
|
5637
|
+
var FUNC_STATEMENT = 1;
|
|
5638
|
+
var FUNC_HANGING_STATEMENT = 2;
|
|
5639
|
+
var FUNC_NULLABLE_ID = 4;
|
|
5616
5640
|
pp$8.parseFunction = function(node, statement, allowExpressionBody, isAsync, forInit) {
|
|
5617
5641
|
this.initFunction(node);
|
|
5618
5642
|
if (this.options.ecmaVersion >= 9 || this.options.ecmaVersion >= 6 && !isAsync) {
|
|
@@ -5687,13 +5711,17 @@ pp$8.parseClassElement = function(constructorAllowsSuper) {
|
|
|
5687
5711
|
else keyName = "static";
|
|
5688
5712
|
}
|
|
5689
5713
|
node.static = isStatic;
|
|
5690
|
-
if (!keyName && ecmaVersion >= 8 && this.eatContextual("async"))
|
|
5691
|
-
|
|
5714
|
+
if (!keyName && ecmaVersion >= 8 && this.eatContextual("async")) {
|
|
5715
|
+
if ((this.isClassElementNameStart() || this.type === types$1.star) && !this.canInsertSemicolon()) isAsync = true;
|
|
5716
|
+
else keyName = "async";
|
|
5717
|
+
}
|
|
5692
5718
|
if (!keyName && (ecmaVersion >= 9 || !isAsync) && this.eat(types$1.star)) isGenerator = true;
|
|
5693
5719
|
if (!keyName && !isAsync && !isGenerator) {
|
|
5694
5720
|
var lastValue = this.value;
|
|
5695
|
-
if (this.eatContextual("get") || this.eatContextual("set"))
|
|
5696
|
-
|
|
5721
|
+
if (this.eatContextual("get") || this.eatContextual("set")) {
|
|
5722
|
+
if (this.isClassElementNameStart()) kind = lastValue;
|
|
5723
|
+
else keyName = lastValue;
|
|
5724
|
+
}
|
|
5697
5725
|
}
|
|
5698
5726
|
if (keyName) {
|
|
5699
5727
|
node.computed = false;
|
|
@@ -5786,8 +5814,10 @@ pp$8.exitClassBody = function() {
|
|
|
5786
5814
|
var parent = len === 0 ? null : this.privateNameStack[len - 1];
|
|
5787
5815
|
for (var i = 0; i < used.length; ++i) {
|
|
5788
5816
|
var id = used[i];
|
|
5789
|
-
if (!hasOwn(declared, id.name))
|
|
5790
|
-
|
|
5817
|
+
if (!hasOwn(declared, id.name)) {
|
|
5818
|
+
if (parent) parent.used.push(id);
|
|
5819
|
+
else this.raiseRecoverable(id.start, "Private field '#" + id.name + "' must be declared in an enclosing class");
|
|
5820
|
+
}
|
|
5791
5821
|
}
|
|
5792
5822
|
};
|
|
5793
5823
|
function isPrivateNameConflicted(privateNameMap, element) {
|
|
@@ -5809,10 +5839,12 @@ function checkKeyName(node, name) {
|
|
|
5809
5839
|
return !computed && (key.type === "Identifier" && key.name === name || key.type === "Literal" && key.value === name);
|
|
5810
5840
|
}
|
|
5811
5841
|
pp$8.parseExportAllDeclaration = function(node, exports$1) {
|
|
5812
|
-
if (this.options.ecmaVersion >= 11)
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5842
|
+
if (this.options.ecmaVersion >= 11) {
|
|
5843
|
+
if (this.eatContextual("as")) {
|
|
5844
|
+
node.exported = this.parseModuleExportName();
|
|
5845
|
+
this.checkExport(exports$1, node.exported, this.lastTokStart);
|
|
5846
|
+
} else node.exported = null;
|
|
5847
|
+
}
|
|
5816
5848
|
this.expectContextual("from");
|
|
5817
5849
|
if (this.type !== types$1.string) this.unexpected();
|
|
5818
5850
|
node.source = this.parseExprAtom();
|
|
@@ -6330,9 +6362,11 @@ pp$5.checkPropClash = function(prop, propHash, refDestructuringErrors) {
|
|
|
6330
6362
|
var kind = prop.kind;
|
|
6331
6363
|
if (this.options.ecmaVersion >= 6) {
|
|
6332
6364
|
if (name === "__proto__" && kind === "init") {
|
|
6333
|
-
if (propHash.proto)
|
|
6334
|
-
if (refDestructuringErrors
|
|
6335
|
-
|
|
6365
|
+
if (propHash.proto) {
|
|
6366
|
+
if (refDestructuringErrors) {
|
|
6367
|
+
if (refDestructuringErrors.doubleProto < 0) refDestructuringErrors.doubleProto = key.start;
|
|
6368
|
+
} else this.raiseRecoverable(key.start, "Redefinition of __proto__ property");
|
|
6369
|
+
}
|
|
6336
6370
|
propHash.proto = true;
|
|
6337
6371
|
}
|
|
6338
6372
|
return;
|
|
@@ -6366,8 +6400,10 @@ pp$5.parseExpression = function(forInit, refDestructuringErrors) {
|
|
|
6366
6400
|
});
|
|
6367
6401
|
};
|
|
6368
6402
|
pp$5.parseMaybeAssign = function(forInit, refDestructuringErrors, afterLeftParse) {
|
|
6369
|
-
if (this.isContextual("yield"))
|
|
6370
|
-
|
|
6403
|
+
if (this.isContextual("yield")) {
|
|
6404
|
+
if (this.inGenerator) return this.parseYield(forInit);
|
|
6405
|
+
else this.exprAllowed = false;
|
|
6406
|
+
}
|
|
6371
6407
|
var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1, oldDoubleProto = -1;
|
|
6372
6408
|
if (refDestructuringErrors) {
|
|
6373
6409
|
oldParenAssign = refDestructuringErrors.parenthesizedAssign;
|
|
@@ -6486,9 +6522,10 @@ pp$5.parseMaybeUnary = function(refDestructuringErrors, sawUnary, incDec, forIni
|
|
|
6486
6522
|
expr = this.finishNode(node$1, "UpdateExpression");
|
|
6487
6523
|
}
|
|
6488
6524
|
}
|
|
6489
|
-
if (!incDec && !(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(types$1.starstar))
|
|
6490
|
-
|
|
6491
|
-
|
|
6525
|
+
if (!incDec && !(expr.type === "ArrowFunctionExpression" && expr.start === startPos) && this.eat(types$1.starstar)) {
|
|
6526
|
+
if (sawUnary) this.unexpected(this.lastTokStart);
|
|
6527
|
+
else return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false, false, forInit), "**", false);
|
|
6528
|
+
} else return expr;
|
|
6492
6529
|
};
|
|
6493
6530
|
function isLocalVariableAccess(node) {
|
|
6494
6531
|
return node.type === "Identifier" || node.type === "ParenthesizedExpression" && isLocalVariableAccess(node.expression);
|
|
@@ -6686,17 +6723,18 @@ pp$5.parseExprImport = function(forNew) {
|
|
|
6686
6723
|
pp$5.parseDynamicImport = function(node) {
|
|
6687
6724
|
this.next();
|
|
6688
6725
|
node.source = this.parseMaybeAssign();
|
|
6689
|
-
if (this.options.ecmaVersion >= 16)
|
|
6690
|
-
this.
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
this.
|
|
6695
|
-
|
|
6696
|
-
|
|
6726
|
+
if (this.options.ecmaVersion >= 16) {
|
|
6727
|
+
if (!this.eat(types$1.parenR)) {
|
|
6728
|
+
this.expect(types$1.comma);
|
|
6729
|
+
if (!this.afterTrailingComma(types$1.parenR)) {
|
|
6730
|
+
node.options = this.parseMaybeAssign();
|
|
6731
|
+
if (!this.eat(types$1.parenR)) {
|
|
6732
|
+
this.expect(types$1.comma);
|
|
6733
|
+
if (!this.afterTrailingComma(types$1.parenR)) this.unexpected();
|
|
6734
|
+
}
|
|
6735
|
+
} else node.options = null;
|
|
6697
6736
|
} else node.options = null;
|
|
6698
|
-
} else
|
|
6699
|
-
else if (!this.eat(types$1.parenR)) {
|
|
6737
|
+
} else if (!this.eat(types$1.parenR)) {
|
|
6700
6738
|
var errorPos = this.start;
|
|
6701
6739
|
if (this.eat(types$1.comma) && this.eat(types$1.parenR)) this.raiseRecoverable(errorPos, "Trailing comma is not allowed in import()");
|
|
6702
6740
|
else this.unexpected(errorPos);
|
|
@@ -6930,12 +6968,14 @@ pp$5.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startP
|
|
|
6930
6968
|
} else this.unexpected();
|
|
6931
6969
|
};
|
|
6932
6970
|
pp$5.parsePropertyName = function(prop) {
|
|
6933
|
-
if (this.options.ecmaVersion >= 6)
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
6971
|
+
if (this.options.ecmaVersion >= 6) {
|
|
6972
|
+
if (this.eat(types$1.bracketL)) {
|
|
6973
|
+
prop.computed = true;
|
|
6974
|
+
prop.key = this.parseMaybeAssign();
|
|
6975
|
+
this.expect(types$1.bracketR);
|
|
6976
|
+
return prop.key;
|
|
6977
|
+
} else prop.computed = false;
|
|
6978
|
+
}
|
|
6939
6979
|
return prop.key = this.type === types$1.num || this.type === types$1.string ? this.parseExprAtom() : this.parseIdent(this.options.allowReserved !== "never");
|
|
6940
6980
|
};
|
|
6941
6981
|
pp$5.initFunction = function(node) {
|
|
@@ -7070,8 +7110,10 @@ pp$5.parsePrivateIdent = function() {
|
|
|
7070
7110
|
else this.unexpected();
|
|
7071
7111
|
this.next();
|
|
7072
7112
|
this.finishNode(node, "PrivateIdentifier");
|
|
7073
|
-
if (this.options.checkPrivateFields)
|
|
7074
|
-
|
|
7113
|
+
if (this.options.checkPrivateFields) {
|
|
7114
|
+
if (this.privateNameStack.length === 0) this.raise(node.start, "Private field '#" + node.name + "' must be declared in an enclosing class");
|
|
7115
|
+
else this.privateNameStack[this.privateNameStack.length - 1].used.push(node);
|
|
7116
|
+
}
|
|
7075
7117
|
return node;
|
|
7076
7118
|
};
|
|
7077
7119
|
pp$5.parseYield = function(forInit) {
|
|
@@ -7207,23 +7249,21 @@ var ecma10BinaryProperties = ecma9BinaryProperties + " Extended_Pictographic";
|
|
|
7207
7249
|
var ecma11BinaryProperties = ecma10BinaryProperties;
|
|
7208
7250
|
var ecma12BinaryProperties = ecma11BinaryProperties + " EBase EComp EMod EPres ExtPict";
|
|
7209
7251
|
var ecma13BinaryProperties = ecma12BinaryProperties;
|
|
7210
|
-
var ecma14BinaryProperties = ecma13BinaryProperties;
|
|
7211
7252
|
var unicodeBinaryProperties = {
|
|
7212
7253
|
9: ecma9BinaryProperties,
|
|
7213
7254
|
10: ecma10BinaryProperties,
|
|
7214
7255
|
11: ecma11BinaryProperties,
|
|
7215
7256
|
12: ecma12BinaryProperties,
|
|
7216
7257
|
13: ecma13BinaryProperties,
|
|
7217
|
-
14:
|
|
7258
|
+
14: ecma13BinaryProperties
|
|
7218
7259
|
};
|
|
7219
|
-
var ecma14BinaryPropertiesOfStrings = "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji";
|
|
7220
7260
|
var unicodeBinaryPropertiesOfStrings = {
|
|
7221
7261
|
9: "",
|
|
7222
7262
|
10: "",
|
|
7223
7263
|
11: "",
|
|
7224
7264
|
12: "",
|
|
7225
7265
|
13: "",
|
|
7226
|
-
14:
|
|
7266
|
+
14: "Basic_Emoji Emoji_Keycap_Sequence RGI_Emoji_Modifier_Sequence RGI_Emoji_Flag_Sequence RGI_Emoji_Tag_Sequence RGI_Emoji_ZWJ_Sequence RGI_Emoji"
|
|
7227
7267
|
};
|
|
7228
7268
|
var unicodeGeneralCategoryValues = "Cased_Letter LC Close_Punctuation Pe Connector_Punctuation Pc Control Cc cntrl Currency_Symbol Sc Dash_Punctuation Pd Decimal_Number Nd digit Enclosing_Mark Me Final_Punctuation Pf Format Cf Initial_Punctuation Pi Letter L Letter_Number Nl Line_Separator Zl Lowercase_Letter Ll Mark M Combining_Mark Math_Symbol Sm Modifier_Letter Lm Modifier_Symbol Sk Nonspacing_Mark Mn Number N Open_Punctuation Ps Other C Other_Letter Lo Other_Number No Other_Punctuation Po Other_Symbol So Paragraph_Separator Zp Private_Use Co Punctuation P punct Separator Z Space_Separator Zs Spacing_Mark Mc Surrogate Cs Symbol S Titlecase_Letter Lt Unassigned Cn Uppercase_Letter Lu";
|
|
7229
7269
|
var ecma9ScriptValues = "Adlam Adlm Ahom Anatolian_Hieroglyphs Hluw Arabic Arab Armenian Armn Avestan Avst Balinese Bali Bamum Bamu Bassa_Vah Bass Batak Batk Bengali Beng Bhaiksuki Bhks Bopomofo Bopo Brahmi Brah Braille Brai Buginese Bugi Buhid Buhd Canadian_Aboriginal Cans Carian Cari Caucasian_Albanian Aghb Chakma Cakm Cham Cham Cherokee Cher Common Zyyy Coptic Copt Qaac Cuneiform Xsux Cypriot Cprt Cyrillic Cyrl Deseret Dsrt Devanagari Deva Duployan Dupl Egyptian_Hieroglyphs Egyp Elbasan Elba Ethiopic Ethi Georgian Geor Glagolitic Glag Gothic Goth Grantha Gran Greek Grek Gujarati Gujr Gurmukhi Guru Han Hani Hangul Hang Hanunoo Hano Hatran Hatr Hebrew Hebr Hiragana Hira Imperial_Aramaic Armi Inherited Zinh Qaai Inscriptional_Pahlavi Phli Inscriptional_Parthian Prti Javanese Java Kaithi Kthi Kannada Knda Katakana Kana Kayah_Li Kali Kharoshthi Khar Khmer Khmr Khojki Khoj Khudawadi Sind Lao Laoo Latin Latn Lepcha Lepc Limbu Limb Linear_A Lina Linear_B Linb Lisu Lisu Lycian Lyci Lydian Lydi Mahajani Mahj Malayalam Mlym Mandaic Mand Manichaean Mani Marchen Marc Masaram_Gondi Gonm Meetei_Mayek Mtei Mende_Kikakui Mend Meroitic_Cursive Merc Meroitic_Hieroglyphs Mero Miao Plrd Modi Mongolian Mong Mro Mroo Multani Mult Myanmar Mymr Nabataean Nbat New_Tai_Lue Talu Newa Newa Nko Nkoo Nushu Nshu Ogham Ogam Ol_Chiki Olck Old_Hungarian Hung Old_Italic Ital Old_North_Arabian Narb Old_Permic Perm Old_Persian Xpeo Old_South_Arabian Sarb Old_Turkic Orkh Oriya Orya Osage Osge Osmanya Osma Pahawh_Hmong Hmng Palmyrene Palm Pau_Cin_Hau Pauc Phags_Pa Phag Phoenician Phnx Psalter_Pahlavi Phlp Rejang Rjng Runic Runr Samaritan Samr Saurashtra Saur Sharada Shrd Shavian Shaw Siddham Sidd SignWriting Sgnw Sinhala Sinh Sora_Sompeng Sora Soyombo Soyo Sundanese Sund Syloti_Nagri Sylo Syriac Syrc Tagalog Tglg Tagbanwa Tagb Tai_Le Tale Tai_Tham Lana Tai_Viet Tavt Takri Takr Tamil Taml Tangut Tang Telugu Telu Thaana Thaa Thai Thai Tibetan Tibt Tifinagh Tfng Tirhuta Tirh Ugaritic Ugar Vai Vaii Warang_Citi Wara Yi Yiii Zanabazar_Square Zanb";
|
|
@@ -7231,14 +7271,13 @@ var ecma10ScriptValues = ecma9ScriptValues + " Dogra Dogr Gunjala_Gondi Gong Han
|
|
|
7231
7271
|
var ecma11ScriptValues = ecma10ScriptValues + " Elymaic Elym Nandinagari Nand Nyiakeng_Puachue_Hmong Hmnp Wancho Wcho";
|
|
7232
7272
|
var ecma12ScriptValues = ecma11ScriptValues + " Chorasmian Chrs Diak Dives_Akuru Khitan_Small_Script Kits Yezi Yezidi";
|
|
7233
7273
|
var ecma13ScriptValues = ecma12ScriptValues + " Cypro_Minoan Cpmn Old_Uyghur Ougr Tangsa Tnsa Toto Vithkuqi Vith";
|
|
7234
|
-
var ecma14ScriptValues = ecma13ScriptValues + " " + scriptValuesAddedInUnicode;
|
|
7235
7274
|
var unicodeScriptValues = {
|
|
7236
7275
|
9: ecma9ScriptValues,
|
|
7237
7276
|
10: ecma10ScriptValues,
|
|
7238
7277
|
11: ecma11ScriptValues,
|
|
7239
7278
|
12: ecma12ScriptValues,
|
|
7240
7279
|
13: ecma13ScriptValues,
|
|
7241
|
-
14:
|
|
7280
|
+
14: ecma13ScriptValues + " " + scriptValuesAddedInUnicode
|
|
7242
7281
|
};
|
|
7243
7282
|
var data = {};
|
|
7244
7283
|
function buildUnicodeData(ecmaVersion) {
|
|
@@ -7609,9 +7648,11 @@ pp$1.regexp_groupSpecifier = function(state) {
|
|
|
7609
7648
|
if (!this.regexp_eatGroupName(state)) state.raise("Invalid group");
|
|
7610
7649
|
var trackDisjunction = this.options.ecmaVersion >= 16;
|
|
7611
7650
|
var known = state.groupNames[state.lastStringValue];
|
|
7612
|
-
if (known)
|
|
7613
|
-
|
|
7614
|
-
|
|
7651
|
+
if (known) {
|
|
7652
|
+
if (trackDisjunction) {
|
|
7653
|
+
for (var i = 0, list = known; i < list.length; i += 1) if (!list[i].separatedFrom(state.branchID)) state.raise("Duplicate capture group name");
|
|
7654
|
+
} else state.raise("Duplicate capture group name");
|
|
7655
|
+
}
|
|
7615
7656
|
if (trackDisjunction) (known || (state.groupNames[state.lastStringValue] = [])).push(state.branchID);
|
|
7616
7657
|
else state.groupNames[state.lastStringValue] = true;
|
|
7617
7658
|
}
|
|
@@ -8625,12 +8666,14 @@ pp.readTmplToken = function() {
|
|
|
8625
8666
|
if (this.pos >= this.input.length) this.raise(this.start, "Unterminated template");
|
|
8626
8667
|
var ch = this.input.charCodeAt(this.pos);
|
|
8627
8668
|
if (ch === 96 || ch === 36 && this.input.charCodeAt(this.pos + 1) === 123) {
|
|
8628
|
-
if (this.pos === this.start && (this.type === types$1.template || this.type === types$1.invalidTemplate))
|
|
8629
|
-
|
|
8630
|
-
|
|
8631
|
-
|
|
8632
|
-
|
|
8633
|
-
|
|
8669
|
+
if (this.pos === this.start && (this.type === types$1.template || this.type === types$1.invalidTemplate)) {
|
|
8670
|
+
if (ch === 36) {
|
|
8671
|
+
this.pos += 2;
|
|
8672
|
+
return this.finishToken(types$1.dollarBraceL);
|
|
8673
|
+
} else {
|
|
8674
|
+
++this.pos;
|
|
8675
|
+
return this.finishToken(types$1.backQuote);
|
|
8676
|
+
}
|
|
8634
8677
|
}
|
|
8635
8678
|
out += this.input.slice(chunkStart, this.pos);
|
|
8636
8679
|
return this.finishToken(types$1.template, out);
|
|
@@ -8647,9 +8690,7 @@ pp.readTmplToken = function() {
|
|
|
8647
8690
|
case 10:
|
|
8648
8691
|
out += "\n";
|
|
8649
8692
|
break;
|
|
8650
|
-
default:
|
|
8651
|
-
out += String.fromCharCode(ch);
|
|
8652
|
-
break;
|
|
8693
|
+
default: out += String.fromCharCode(ch);
|
|
8653
8694
|
}
|
|
8654
8695
|
if (this.options.locations) {
|
|
8655
8696
|
++this.curLine;
|
|
@@ -8672,7 +8713,6 @@ pp.readInvalidTemplateToken = function() {
|
|
|
8672
8713
|
case "\u2029":
|
|
8673
8714
|
++this.curLine;
|
|
8674
8715
|
this.lineStart = this.pos + 1;
|
|
8675
|
-
break;
|
|
8676
8716
|
}
|
|
8677
8717
|
this.raise(this.start, "Unterminated template");
|
|
8678
8718
|
};
|
|
@@ -8780,6 +8820,9 @@ Parser.acorn = {
|
|
|
8780
8820
|
lineBreakG,
|
|
8781
8821
|
nonASCIIwhitespace
|
|
8782
8822
|
};
|
|
8823
|
+
function parse(input, options) {
|
|
8824
|
+
return Parser.parse(input, options);
|
|
8825
|
+
}
|
|
8783
8826
|
//#endregion
|
|
8784
8827
|
//#region src/js-lexer.ts
|
|
8785
8828
|
/**
|
|
@@ -8831,7 +8874,7 @@ function notABody(src, pos) {
|
|
|
8831
8874
|
return NOT_A_BODY_RE.test(src);
|
|
8832
8875
|
}
|
|
8833
8876
|
/** Tokens that may end an operand, and so a statement before a line break. */
|
|
8834
|
-
var OPERAND_ENDS = new Set([
|
|
8877
|
+
var OPERAND_ENDS = /* @__PURE__ */ new Set([
|
|
8835
8878
|
types$1.name,
|
|
8836
8879
|
types$1.num,
|
|
8837
8880
|
types$1.string,
|
|
@@ -8957,13 +9000,13 @@ function transientAssignment(p, end) {
|
|
|
8957
9000
|
return false;
|
|
8958
9001
|
}
|
|
8959
9002
|
}
|
|
8960
|
-
var OPENERS = new Set([
|
|
9003
|
+
var OPENERS = /* @__PURE__ */ new Set([
|
|
8961
9004
|
types$1.parenL,
|
|
8962
9005
|
types$1.bracketL,
|
|
8963
9006
|
types$1.braceL,
|
|
8964
9007
|
types$1.dollarBraceL
|
|
8965
9008
|
]);
|
|
8966
|
-
var CLOSERS = new Set([
|
|
9009
|
+
var CLOSERS = /* @__PURE__ */ new Set([
|
|
8967
9010
|
types$1.parenR,
|
|
8968
9011
|
types$1.bracketR,
|
|
8969
9012
|
types$1.braceR
|
|
@@ -9256,11 +9299,11 @@ function walk(node, src, out, binding, shorthand) {
|
|
|
9256
9299
|
}
|
|
9257
9300
|
}
|
|
9258
9301
|
/** The rest of a word, after a number (`2s`). */
|
|
9259
|
-
var WORD_RE$
|
|
9302
|
+
var WORD_RE$2 = /[\p{ID_Continue}$.]*/uy;
|
|
9260
9303
|
/** The flags after a regex literal, whatever they are. */
|
|
9261
9304
|
var FLAGS_RE = /[\p{ID_Continue}$]*/uy;
|
|
9262
9305
|
/** Words a string may follow with no space between (`of'x'`, `get"y"`). */
|
|
9263
|
-
var WORDS_BEFORE_STRING = new Set([
|
|
9306
|
+
var WORDS_BEFORE_STRING = /* @__PURE__ */ new Set([
|
|
9264
9307
|
"of",
|
|
9265
9308
|
"get",
|
|
9266
9309
|
"set",
|
|
@@ -9416,9 +9459,9 @@ function* tokens(src, start, goal, options = {}) {
|
|
|
9416
9459
|
continue;
|
|
9417
9460
|
}
|
|
9418
9461
|
} else if (!unterminated && p.start <= pos && /[\d.]/.test(first) && /\d/.test(src.slice(p.start, p.start + 2))) {
|
|
9419
|
-
WORD_RE$
|
|
9420
|
-
WORD_RE$
|
|
9421
|
-
yield operand(types$1.num, p.start, WORD_RE$
|
|
9462
|
+
WORD_RE$2.lastIndex = p.start;
|
|
9463
|
+
WORD_RE$2.test(src);
|
|
9464
|
+
yield operand(types$1.num, p.start, WORD_RE$2.lastIndex);
|
|
9422
9465
|
continue;
|
|
9423
9466
|
}
|
|
9424
9467
|
yield {
|
|
@@ -10245,7 +10288,7 @@ function unset(param) {
|
|
|
10245
10288
|
if (param.type === "flag" || param.type === "separator") return false;
|
|
10246
10289
|
return param.type === "options" ? {} : void 0;
|
|
10247
10290
|
}
|
|
10248
|
-
var WORD_RE = /\w+/y;
|
|
10291
|
+
var WORD_RE$1 = /\w+/y;
|
|
10249
10292
|
var NUMBER_RE$1 = /[-+]?(?:\d+\.?\d*|\.\d+)/y;
|
|
10250
10293
|
var WORD_OR_PUNCT_RE = /\S+/y;
|
|
10251
10294
|
/** Match the sticky regex `re` at `pos`, returning the matched text. */
|
|
@@ -10265,7 +10308,7 @@ function readOptions(params, src, { at, spans }) {
|
|
|
10265
10308
|
const options = {};
|
|
10266
10309
|
let i = 0;
|
|
10267
10310
|
while (i < src.length) {
|
|
10268
|
-
const key = matchAt(WORD_RE, src, i);
|
|
10311
|
+
const key = matchAt(WORD_RE$1, src, i);
|
|
10269
10312
|
if (!key) {
|
|
10270
10313
|
i = readQuoted(src, i)?.end ?? i + 1;
|
|
10271
10314
|
continue;
|
|
@@ -10444,7 +10487,7 @@ function evaluatePassageName(expr, evaluate, { storyData, currentPassage }) {
|
|
|
10444
10487
|
return name;
|
|
10445
10488
|
}
|
|
10446
10489
|
/** The parameters of the built-in sub-macros that take arguments. */
|
|
10447
|
-
var SUB_MACRO_PARAMETERS = new Map([["option", [{
|
|
10490
|
+
var SUB_MACRO_PARAMETERS = /* @__PURE__ */ new Map([["option", [{
|
|
10448
10491
|
name: "value",
|
|
10449
10492
|
type: "string",
|
|
10450
10493
|
holds: "text",
|
|
@@ -10494,13 +10537,13 @@ function extentOf(piece) {
|
|
|
10494
10537
|
return piece.kind === "code" ? piece.code.length : piece.kind === "text" ? piece.text.length : piece.length;
|
|
10495
10538
|
}
|
|
10496
10539
|
/** Macros whose whole argument text is one expression: branch conditions. */
|
|
10497
|
-
var CONDITION_MACROS = new Set([
|
|
10540
|
+
var CONDITION_MACROS = /* @__PURE__ */ new Set([
|
|
10498
10541
|
"if",
|
|
10499
10542
|
"elseif",
|
|
10500
10543
|
"case"
|
|
10501
10544
|
]);
|
|
10502
10545
|
/** Block macros whose body is the name of a passage. */
|
|
10503
|
-
var PASSAGE_BODIES = new Set(["dialog"]);
|
|
10546
|
+
var PASSAGE_BODIES = /* @__PURE__ */ new Set(["dialog"]);
|
|
10504
10547
|
/**
|
|
10505
10548
|
* `params` with each `string` and `text` parameter (options too) saying
|
|
10506
10549
|
* what it holds: what it declares, else `holds`.
|
|
@@ -11008,9 +11051,11 @@ function textContainsChildren(text, parametersOf) {
|
|
|
11008
11051
|
* Whether a tag renders a `{@children}` in an attribute value or a macro
|
|
11009
11052
|
* argument that holds markup (`<span title="{@children}">`,
|
|
11010
11053
|
* `{button "{@children}"}`). Literal arguments and code are not markup.
|
|
11054
|
+
* `src` is the text a flat token's offsets index into (its attribute values
|
|
11055
|
+
* are read from it); a token made from an AST has none.
|
|
11011
11056
|
*/
|
|
11012
|
-
function tokenTextContainsChildren(token, parametersOf = registeredParameters) {
|
|
11013
|
-
for (const piece of codeAndText(
|
|
11057
|
+
function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "") {
|
|
11058
|
+
for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf)) return true;
|
|
11014
11059
|
return false;
|
|
11015
11060
|
}
|
|
11016
11061
|
/**
|
|
@@ -11070,13 +11115,14 @@ var WIDGET_PARAMETERS = [{
|
|
|
11070
11115
|
}];
|
|
11071
11116
|
/**
|
|
11072
11117
|
* The widget a {widget} definition's arguments declare: its name and its
|
|
11073
|
-
* parameters, the words after it that start with `@` (docs/widgets.md)
|
|
11074
|
-
* Other words, such as `$name`, are
|
|
11118
|
+
* parameters, the words after it that start with `@` (docs/widgets.md),
|
|
11119
|
+
* separated by spaces or commas (`@a, @b`). Other words, such as `$name`, are
|
|
11120
|
+
* not parameters.
|
|
11075
11121
|
*/
|
|
11076
11122
|
function widgetDef({ name = "", parameters = "" }) {
|
|
11077
11123
|
return {
|
|
11078
11124
|
name,
|
|
11079
|
-
params: parameters.split(
|
|
11125
|
+
params: parameters.split(/[\s,]+/).filter((word) => word.startsWith("@"))
|
|
11080
11126
|
};
|
|
11081
11127
|
}
|
|
11082
11128
|
/** Read the arguments of a {widget} definition (see widgetDef). */
|
|
@@ -11108,18 +11154,19 @@ function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
|
|
|
11108
11154
|
if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
|
|
11109
11155
|
const open = [];
|
|
11110
11156
|
const done = [];
|
|
11111
|
-
for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget")
|
|
11112
|
-
token
|
|
11113
|
-
|
|
11114
|
-
|
|
11115
|
-
else {
|
|
11116
|
-
const def = open.pop();
|
|
11117
|
-
if (def) done.push({
|
|
11118
|
-
...def,
|
|
11119
|
-
closeStart: token.start
|
|
11157
|
+
for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
|
|
11158
|
+
if (!token.isClose) open.push({
|
|
11159
|
+
token,
|
|
11160
|
+
isBlock: false
|
|
11120
11161
|
});
|
|
11121
|
-
|
|
11122
|
-
|
|
11162
|
+
else {
|
|
11163
|
+
const def = open.pop();
|
|
11164
|
+
if (def) done.push({
|
|
11165
|
+
...def,
|
|
11166
|
+
closeStart: token.start
|
|
11167
|
+
});
|
|
11168
|
+
}
|
|
11169
|
+
} else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content))) open[open.length - 1].isBlock = true;
|
|
11123
11170
|
done.push(...open);
|
|
11124
11171
|
const defs = [];
|
|
11125
11172
|
for (const { token, isBlock, closeStart } of done) try {
|
|
@@ -11161,14 +11208,14 @@ function blockWidgetNames(passages, parametersOf = registeredParameters) {
|
|
|
11161
11208
|
* Passages that hold no markup: declarations, and the JavaScript function
|
|
11162
11209
|
* body of SaveTitle.
|
|
11163
11210
|
*/
|
|
11164
|
-
var NOT_MARKUP = new Set([
|
|
11211
|
+
var NOT_MARKUP = /* @__PURE__ */ new Set([
|
|
11165
11212
|
"StoryVariables",
|
|
11166
11213
|
"StoryTransients",
|
|
11167
11214
|
"SaveTitle"
|
|
11168
11215
|
]);
|
|
11169
11216
|
var NOT_MARKUP_TAGS$1 = ["script", "stylesheet"];
|
|
11170
11217
|
/** Branch macros, which their parent macro renders. */
|
|
11171
|
-
var BRANCH_MACROS = new Set([
|
|
11218
|
+
var BRANCH_MACROS = /* @__PURE__ */ new Set([
|
|
11172
11219
|
"elseif",
|
|
11173
11220
|
"else",
|
|
11174
11221
|
"case",
|
|
@@ -11250,19 +11297,30 @@ function validateMarkup(passages, options) {
|
|
|
11250
11297
|
const parsed = [];
|
|
11251
11298
|
const widgets = /* @__PURE__ */ new Set();
|
|
11252
11299
|
const passageNames = /* @__PURE__ */ new Set();
|
|
11300
|
+
const addWidgets = (tokens) => {
|
|
11301
|
+
for (const token of tokens) {
|
|
11302
|
+
if (token.type !== "macro" || token.isClose) continue;
|
|
11303
|
+
if (token.name.toLowerCase() !== "widget") continue;
|
|
11304
|
+
const name = widgetName(token.rawArgs);
|
|
11305
|
+
if (name) widgets.add(name);
|
|
11306
|
+
}
|
|
11307
|
+
};
|
|
11253
11308
|
for (const passage of passages) {
|
|
11254
11309
|
passageNames.add(passage.name);
|
|
11255
11310
|
if (NOT_MARKUP.has(passage.name)) continue;
|
|
11256
11311
|
if (passage.tags?.some((tag) => NOT_MARKUP_TAGS$1.includes(tag))) continue;
|
|
11257
11312
|
const reported = !options.only || options.only(passage);
|
|
11313
|
+
if (options.tolerant) {
|
|
11314
|
+
const { tokens, errors } = analyzeMarkup(passage.content, { hooks });
|
|
11315
|
+
addWidgets(tokens);
|
|
11316
|
+
if (!reported) continue;
|
|
11317
|
+
for (const err of errors) reportError(passage, err, "");
|
|
11318
|
+
parsed.push([passage, tokens]);
|
|
11319
|
+
continue;
|
|
11320
|
+
}
|
|
11258
11321
|
try {
|
|
11259
11322
|
const tokens = tokenizeMarkup(passage.content);
|
|
11260
|
-
|
|
11261
|
-
if (token.type !== "macro" || token.isClose) continue;
|
|
11262
|
-
if (token.name.toLowerCase() !== "widget") continue;
|
|
11263
|
-
const name = widgetName(token.rawArgs);
|
|
11264
|
-
if (name) widgets.add(name);
|
|
11265
|
-
}
|
|
11323
|
+
addWidgets(tokens);
|
|
11266
11324
|
if (!reported) continue;
|
|
11267
11325
|
parseMarkup(passage.content, { hooks });
|
|
11268
11326
|
parsed.push([passage, tokens]);
|
|
@@ -11381,7 +11439,13 @@ Object.freeze(createNamespace());
|
|
|
11381
11439
|
*/
|
|
11382
11440
|
var NUMBER_RE = /(?:0[xX][\da-fA-F_]+|0[bB][01_]+|0[oO][0-7_]+|(?:\d[\d_]*\.?[\d_]*|\.\d[\d_]*)(?:[eE][+-]?\d+)?)(n?)/y;
|
|
11383
11441
|
var IDENT_RE = /[A-Za-z_$][\w$]*/y;
|
|
11442
|
+
var KEY_RE = /[\w$]+/y;
|
|
11384
11443
|
var ARROW_RE = /(?:async\s+)?(?:\((?:[^()]|\([^()]*\))*\)|[A-Za-z_$][\w$]*)\s*=>/y;
|
|
11444
|
+
var ARRAY_INDEX_RE = /^(?:0|[1-9]\d{0,8})$/;
|
|
11445
|
+
var UNSUPPORTED_UNDEFINED = {
|
|
11446
|
+
unsupported: "undefined",
|
|
11447
|
+
value: "undefined"
|
|
11448
|
+
};
|
|
11385
11449
|
/** Read `src`, one literal and nothing else. */
|
|
11386
11450
|
function staticLiteral(src) {
|
|
11387
11451
|
const reader = new Reader(src);
|
|
@@ -11389,6 +11453,27 @@ function staticLiteral(src) {
|
|
|
11389
11453
|
reader.space();
|
|
11390
11454
|
return reader.i === src.length ? value : void 0;
|
|
11391
11455
|
}
|
|
11456
|
+
/**
|
|
11457
|
+
* The keys of an object in the order `Object.entries` lists them (array
|
|
11458
|
+
* indices first, ascending, then the others as they were added): the order
|
|
11459
|
+
* the runtime meets the members in.
|
|
11460
|
+
*/
|
|
11461
|
+
function entryOrder(keys) {
|
|
11462
|
+
const all = [...keys];
|
|
11463
|
+
return [...all.filter((key) => ARRAY_INDEX_RE.test(key)).sort((a, b) => Number(a) - Number(b)), ...all.filter((key) => !ARRAY_INDEX_RE.test(key))];
|
|
11464
|
+
}
|
|
11465
|
+
/** `String(value)` of a BigInt literal's digits, or `undefined` if they are no BigInt. */
|
|
11466
|
+
function bigintValue(digits) {
|
|
11467
|
+
try {
|
|
11468
|
+
return BigInt(digits.replace(/_/g, "")).toString();
|
|
11469
|
+
} catch {
|
|
11470
|
+
return;
|
|
11471
|
+
}
|
|
11472
|
+
}
|
|
11473
|
+
/**
|
|
11474
|
+
* The cursor over a JavaScript text that the literal reader moves: the
|
|
11475
|
+
* helpers that skip what is not read are shared (see macro-discovery.ts).
|
|
11476
|
+
*/
|
|
11392
11477
|
var Reader = class {
|
|
11393
11478
|
constructor(src) {
|
|
11394
11479
|
this.src = src;
|
|
@@ -11430,6 +11515,15 @@ var Reader = class {
|
|
|
11430
11515
|
closed
|
|
11431
11516
|
};
|
|
11432
11517
|
}
|
|
11518
|
+
/**
|
|
11519
|
+
* Skip the string literal at the cursor and read its value, or `undefined`
|
|
11520
|
+
* if it is not closed or not well-formed.
|
|
11521
|
+
*/
|
|
11522
|
+
stringValue() {
|
|
11523
|
+
const at = this.i;
|
|
11524
|
+
const { closed } = this.string();
|
|
11525
|
+
return closed ? stringLiteralValue(this.src.slice(at, this.i)) ?? void 0 : void 0;
|
|
11526
|
+
}
|
|
11433
11527
|
/** A template literal: a string, but for `${}`. */
|
|
11434
11528
|
template() {
|
|
11435
11529
|
const { src } = this;
|
|
@@ -11446,7 +11540,8 @@ var Reader = class {
|
|
|
11446
11540
|
number() {
|
|
11447
11541
|
const { src } = this;
|
|
11448
11542
|
let i = this.i;
|
|
11449
|
-
|
|
11543
|
+
const sign = src.charAt(i);
|
|
11544
|
+
if (sign === "+" || sign === "-") {
|
|
11450
11545
|
i++;
|
|
11451
11546
|
while (/\s/.test(src.charAt(i))) i++;
|
|
11452
11547
|
}
|
|
@@ -11454,7 +11549,13 @@ var Reader = class {
|
|
|
11454
11549
|
const match = NUMBER_RE.exec(src);
|
|
11455
11550
|
if (match) {
|
|
11456
11551
|
this.i = NUMBER_RE.lastIndex;
|
|
11457
|
-
|
|
11552
|
+
if (!match[1]) return { shape: { type: "number" } };
|
|
11553
|
+
if (sign === "+") return { throws: "Cannot convert a BigInt value to a number" };
|
|
11554
|
+
const digits = bigintValue(match[0].slice(0, -1));
|
|
11555
|
+
return digits === void 0 ? void 0 : {
|
|
11556
|
+
unsupported: "bigint",
|
|
11557
|
+
value: sign === "-" && digits !== "0" ? `-${digits}` : digits
|
|
11558
|
+
};
|
|
11458
11559
|
}
|
|
11459
11560
|
IDENT_RE.lastIndex = i;
|
|
11460
11561
|
if (IDENT_RE.exec(src)?.[0] === "Infinity") {
|
|
@@ -11465,8 +11566,9 @@ var Reader = class {
|
|
|
11465
11566
|
/** A keyword, a function, or a name (which is not static). */
|
|
11466
11567
|
word() {
|
|
11467
11568
|
const { src } = this;
|
|
11468
|
-
|
|
11469
|
-
|
|
11569
|
+
const start = this.i;
|
|
11570
|
+
const arrow = this.arrow();
|
|
11571
|
+
if (arrow !== void 0) return arrow ? this.functionFrom(start) : void 0;
|
|
11470
11572
|
IDENT_RE.lastIndex = this.i;
|
|
11471
11573
|
const word = IDENT_RE.exec(src)?.[0];
|
|
11472
11574
|
if (word === void 0) return void 0;
|
|
@@ -11484,72 +11586,152 @@ var Reader = class {
|
|
|
11484
11586
|
return { shape: { type: "number" } };
|
|
11485
11587
|
case "undefined":
|
|
11486
11588
|
this.i = end;
|
|
11487
|
-
return
|
|
11589
|
+
return UNSUPPORTED_UNDEFINED;
|
|
11590
|
+
case "void": {
|
|
11591
|
+
this.i = end;
|
|
11592
|
+
const operand = this.value();
|
|
11593
|
+
return operand && !("throws" in operand) ? UNSUPPORTED_UNDEFINED : operand;
|
|
11594
|
+
}
|
|
11488
11595
|
case "function":
|
|
11489
11596
|
case "class":
|
|
11490
|
-
case "async": return this.
|
|
11597
|
+
case "async": return this.skipDeclaration(word) ? this.functionFrom(start) : void 0;
|
|
11491
11598
|
}
|
|
11492
11599
|
}
|
|
11493
|
-
/**
|
|
11494
|
-
|
|
11495
|
-
return
|
|
11600
|
+
/** The function (or class) that was skipped since `start`. */
|
|
11601
|
+
functionFrom(start) {
|
|
11602
|
+
return {
|
|
11603
|
+
unsupported: "function",
|
|
11604
|
+
value: this.src.slice(start, this.i).trimEnd()
|
|
11605
|
+
};
|
|
11496
11606
|
}
|
|
11497
|
-
/**
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11607
|
+
/**
|
|
11608
|
+
* Skip the parameters of an arrow function and its body, which ends at a
|
|
11609
|
+
* `,` or `}` outside brackets, or at the end of the text. `undefined` if the
|
|
11610
|
+
* text at the cursor is no arrow function, false if it cannot be skipped.
|
|
11611
|
+
*/
|
|
11612
|
+
arrow() {
|
|
11613
|
+
const { src } = this;
|
|
11614
|
+
ARROW_RE.lastIndex = this.i;
|
|
11615
|
+
if (!ARROW_RE.test(src)) return void 0;
|
|
11616
|
+
this.i = ARROW_RE.lastIndex;
|
|
11617
|
+
this.space();
|
|
11618
|
+
if (src.charAt(this.i) === "{") return this.skipBalanced();
|
|
11619
|
+
while (this.i < src.length && !",}".includes(src.charAt(this.i))) if (!this.skipOne()) break;
|
|
11620
|
+
return true;
|
|
11621
|
+
}
|
|
11622
|
+
/**
|
|
11623
|
+
* Skip a `function`, `async function` or `class` (its keyword `word` is at
|
|
11624
|
+
* the cursor), up to the end of its body.
|
|
11625
|
+
*/
|
|
11626
|
+
skipDeclaration(word) {
|
|
11627
|
+
const { src } = this;
|
|
11628
|
+
this.i += word.length;
|
|
11629
|
+
this.space();
|
|
11630
|
+
if (word === "async") {
|
|
11631
|
+
IDENT_RE.lastIndex = this.i;
|
|
11632
|
+
if (IDENT_RE.exec(src)?.[0] !== "function") return false;
|
|
11633
|
+
return this.skipDeclaration("function");
|
|
11634
|
+
}
|
|
11635
|
+
if (word === "function") {
|
|
11636
|
+
if (src.charAt(this.i) === "*") this.i++;
|
|
11637
|
+
this.space();
|
|
11638
|
+
IDENT_RE.lastIndex = this.i;
|
|
11639
|
+
if (IDENT_RE.test(src)) this.i = IDENT_RE.lastIndex;
|
|
11640
|
+
this.space();
|
|
11641
|
+
if (src.charAt(this.i) !== "(" || !this.skipBalanced()) return false;
|
|
11642
|
+
this.space();
|
|
11643
|
+
} else while (this.i < src.length && src.charAt(this.i) !== "{") if (!this.skipOne()) return false;
|
|
11644
|
+
return src.charAt(this.i) === "{" && this.skipBalanced();
|
|
11501
11645
|
}
|
|
11502
11646
|
/** An object literal: the members that are static. */
|
|
11503
11647
|
object() {
|
|
11504
11648
|
const { src } = this;
|
|
11505
|
-
const
|
|
11649
|
+
const members = /* @__PURE__ */ new Map();
|
|
11650
|
+
let thrown;
|
|
11506
11651
|
this.i++;
|
|
11507
11652
|
for (;;) {
|
|
11508
11653
|
this.space();
|
|
11509
11654
|
const c = src.charAt(this.i);
|
|
11510
11655
|
if (c === "}") {
|
|
11511
11656
|
this.i++;
|
|
11512
|
-
return {
|
|
11513
|
-
type: "object",
|
|
11514
|
-
fields
|
|
11515
|
-
} };
|
|
11657
|
+
return thrown === void 0 ? this.objectOf(members) : { throws: thrown };
|
|
11516
11658
|
}
|
|
11517
11659
|
if (c === ",") {
|
|
11518
11660
|
this.i++;
|
|
11519
11661
|
continue;
|
|
11520
11662
|
}
|
|
11521
11663
|
if (this.i >= src.length) return void 0;
|
|
11664
|
+
const start = this.i;
|
|
11522
11665
|
const key = this.key();
|
|
11666
|
+
if (key === "__proto__") return void 0;
|
|
11523
11667
|
this.space();
|
|
11524
|
-
|
|
11668
|
+
const next = src.charAt(this.i);
|
|
11669
|
+
if (key !== void 0 && next === ":") {
|
|
11525
11670
|
this.i++;
|
|
11526
11671
|
const at = this.i;
|
|
11527
11672
|
const value = this.value();
|
|
11528
11673
|
this.space();
|
|
11529
|
-
if (value &&
|
|
11530
|
-
|
|
11531
|
-
|
|
11674
|
+
if (value && this.atMemberEnd()) {
|
|
11675
|
+
if ("throws" in value) thrown ?? (thrown = value.throws);
|
|
11676
|
+
else members.set(key, "shape" in value ? value.shape : value);
|
|
11532
11677
|
continue;
|
|
11533
11678
|
}
|
|
11679
|
+
members.set(key, null);
|
|
11534
11680
|
this.i = at;
|
|
11535
|
-
} else if (key !== void 0 &&
|
|
11681
|
+
} else if (key !== void 0 && next === "(") {
|
|
11682
|
+
if (!this.skipBalanced()) return void 0;
|
|
11683
|
+
this.space();
|
|
11684
|
+
if (src.charAt(this.i) === "{" && this.skipBalanced()) {
|
|
11685
|
+
members.set(key, {
|
|
11686
|
+
unsupported: "function",
|
|
11687
|
+
value: src.slice(start, this.i)
|
|
11688
|
+
});
|
|
11689
|
+
continue;
|
|
11690
|
+
}
|
|
11691
|
+
return;
|
|
11692
|
+
} else if (key !== void 0 && (next === "," || next === "}")) {
|
|
11693
|
+
members.set(key, null);
|
|
11694
|
+
continue;
|
|
11695
|
+
} else members.clear();
|
|
11536
11696
|
if (!this.skipMember()) return void 0;
|
|
11537
11697
|
}
|
|
11538
11698
|
}
|
|
11699
|
+
/** Whether a member ends at the cursor. */
|
|
11700
|
+
atMemberEnd() {
|
|
11701
|
+
return this.i < this.src.length && ",}".includes(this.src.charAt(this.i));
|
|
11702
|
+
}
|
|
11703
|
+
/**
|
|
11704
|
+
* The object literal with these members: a value no variable can hold
|
|
11705
|
+
* anywhere in it (the first the runtime meets) is what it reads as.
|
|
11706
|
+
*/
|
|
11707
|
+
objectOf(members) {
|
|
11708
|
+
const fields = /* @__PURE__ */ new Map();
|
|
11709
|
+
for (const key of entryOrder(members.keys())) {
|
|
11710
|
+
const member = members.get(key);
|
|
11711
|
+
if (!member) continue;
|
|
11712
|
+
if ("unsupported" in member) return member;
|
|
11713
|
+
fields.set(key, member);
|
|
11714
|
+
}
|
|
11715
|
+
return { shape: {
|
|
11716
|
+
type: "object",
|
|
11717
|
+
fields
|
|
11718
|
+
} };
|
|
11719
|
+
}
|
|
11539
11720
|
/** The key of a member (a name, a string or a number), if it has one. */
|
|
11540
11721
|
key() {
|
|
11541
11722
|
const { src } = this;
|
|
11542
11723
|
const c = src.charAt(this.i);
|
|
11543
|
-
if (c === "\"" || c === "'")
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
}
|
|
11547
|
-
const word = /[\w$]+/y;
|
|
11548
|
-
word.lastIndex = this.i;
|
|
11549
|
-
const found = word.exec(src)?.[0];
|
|
11724
|
+
if (c === "\"" || c === "'") return this.stringValue();
|
|
11725
|
+
KEY_RE.lastIndex = this.i;
|
|
11726
|
+
const found = KEY_RE.exec(src)?.[0];
|
|
11550
11727
|
if (found === void 0) return void 0;
|
|
11551
|
-
this.i =
|
|
11552
|
-
return found;
|
|
11728
|
+
this.i = KEY_RE.lastIndex;
|
|
11729
|
+
if (!/^\d/.test(found)) return found;
|
|
11730
|
+
const digits = found.replace(/_/g, "");
|
|
11731
|
+
if (/^0\d/.test(digits)) return void 0;
|
|
11732
|
+
if (digits.endsWith("n") && !/^0[xX]/.test(digits)) return bigintValue(digits.slice(0, -1));
|
|
11733
|
+
const value = Number(digits);
|
|
11734
|
+
return Number.isNaN(value) ? void 0 : String(value);
|
|
11553
11735
|
}
|
|
11554
11736
|
/** Skip to the `,` or `}` that ends a member, balancing what is inside. */
|
|
11555
11737
|
skipMember() {
|
|
@@ -11636,7 +11818,7 @@ function declarationRegex(sigil) {
|
|
|
11636
11818
|
var VAR_PATH_RE = /([$%])(\w+(?:\.\w+)*)/y;
|
|
11637
11819
|
/** Quoted first argument of an input macro naming a story variable. */
|
|
11638
11820
|
var QUOTED_VAR_ARG_RE = /^["']\$(\w+(?:\.\w+)*)["']?$/;
|
|
11639
|
-
var VALID_VAR_TYPES = new Set([
|
|
11821
|
+
var VALID_VAR_TYPES = /* @__PURE__ */ new Set([
|
|
11640
11822
|
"number",
|
|
11641
11823
|
"string",
|
|
11642
11824
|
"boolean"
|
|
@@ -11683,6 +11865,27 @@ function shapeSchema(shape) {
|
|
|
11683
11865
|
};
|
|
11684
11866
|
}
|
|
11685
11867
|
/**
|
|
11868
|
+
* What is wrong with the syntax of an initializer, as it is evaluated
|
|
11869
|
+
* (`return (expr)` in a function body), or `undefined`. `pos` is where, as an
|
|
11870
|
+
* index into `expr` (it may be past its end, for an unexpected end).
|
|
11871
|
+
*/
|
|
11872
|
+
function initializerSyntaxError(expr) {
|
|
11873
|
+
const prefix = "return (";
|
|
11874
|
+
try {
|
|
11875
|
+
parse(prefix + expr + ")", {
|
|
11876
|
+
ecmaVersion: "latest",
|
|
11877
|
+
allowReturnOutsideFunction: true
|
|
11878
|
+
});
|
|
11879
|
+
} catch (err) {
|
|
11880
|
+
if (!(err instanceof SyntaxError)) throw err;
|
|
11881
|
+
const { pos } = err;
|
|
11882
|
+
return {
|
|
11883
|
+
message: err.message.replace(/ \(\d+:\d+\)$/, ""),
|
|
11884
|
+
pos: Math.max(0, pos - 8)
|
|
11885
|
+
};
|
|
11886
|
+
}
|
|
11887
|
+
}
|
|
11888
|
+
/**
|
|
11686
11889
|
* Read the declarations of a StoryVariables (`$name = value`) or
|
|
11687
11890
|
* StoryTransients (`%name = value`) passage, without evaluating them and
|
|
11688
11891
|
* without throwing: every valid declaration, and every invalid line as an
|
|
@@ -11690,9 +11893,10 @@ function shapeSchema(shape) {
|
|
|
11690
11893
|
*
|
|
11691
11894
|
* A declaration is a line of the form `$name = expression`; blank lines are
|
|
11692
11895
|
* skipped. A line that is not, and a name that cannot be a variable, are
|
|
11693
|
-
* errors. So is an initializer
|
|
11694
|
-
* `undefined`)
|
|
11695
|
-
*
|
|
11896
|
+
* errors. So is an initializer with a syntax error, and one that no variable
|
|
11897
|
+
* can hold (a function, `undefined`) when it is a literal, or one that throws
|
|
11898
|
+
* when it is a literal (`+1n`); whether any other initializer can only be
|
|
11899
|
+
* known by running it. A name declared again is an error too, but both
|
|
11696
11900
|
* declarations are returned (the later wins when evaluated).
|
|
11697
11901
|
*/
|
|
11698
11902
|
function parseDeclarations(content, sigil = "$") {
|
|
@@ -11735,10 +11939,19 @@ function parseDeclarations(content, sigil = "$") {
|
|
|
11735
11939
|
};
|
|
11736
11940
|
if (seen.has(name)) error("duplicate-declaration", nameStart, nameEnd, `Duplicate declaration of ${sigil}${name}`);
|
|
11737
11941
|
seen.add(name);
|
|
11738
|
-
const literal = staticLiteral(expr);
|
|
11739
|
-
if (literal && "shape" in literal) declaration.schema = shapeSchema(literal.shape);
|
|
11740
|
-
else if (literal) error("unsupported-value", declaration.valueStart, valueEnd, `Unsupported type "${literal.unsupported}" for value ${expr}. ${UNSUPPORTED_TYPE}`);
|
|
11741
11942
|
declarations.push(declaration);
|
|
11943
|
+
const failed = `Failed to evaluate "${sigil}${name} = ${expr}"`;
|
|
11944
|
+
const syntax = initializerSyntaxError(expr);
|
|
11945
|
+
if (syntax) {
|
|
11946
|
+
const at = Math.min(syntax.pos, expr.length - 1);
|
|
11947
|
+
error("syntax", declaration.valueStart + at, declaration.valueStart + at + 1, `${failed}: ${syntax.message}`);
|
|
11948
|
+
continue;
|
|
11949
|
+
}
|
|
11950
|
+
const literal = staticLiteral(expr);
|
|
11951
|
+
if (!literal) continue;
|
|
11952
|
+
if ("shape" in literal) declaration.schema = shapeSchema(literal.shape);
|
|
11953
|
+
else if ("throws" in literal) error("unsupported-value", declaration.valueStart, valueEnd, `${failed}: ${literal.throws}`);
|
|
11954
|
+
else error("unsupported-value", declaration.valueStart, valueEnd, `Unsupported type "${literal.unsupported}" for value ${literal.value}. ${UNSUPPORTED_TYPE}`);
|
|
11742
11955
|
}
|
|
11743
11956
|
return {
|
|
11744
11957
|
declarations,
|
|
@@ -11902,6 +12115,7 @@ function scanCodeLeniently(code, at, emit, goal) {
|
|
|
11902
12115
|
function scanArgs(token, params, at, emit, options) {
|
|
11903
12116
|
if (!token.rawArgs) return;
|
|
11904
12117
|
if (params) {
|
|
12118
|
+
if (options.all && !options.storeVarMacros.has(token.name.toLowerCase())) scanVariableParameters(token, params, at, emit);
|
|
11905
12119
|
const pieces = [...argPieces(token.rawArgs, token.argsStart, params, token.name, "")];
|
|
11906
12120
|
if (!pieces.some((piece) => piece.kind === "argument-error")) {
|
|
11907
12121
|
for (const piece of pieces) {
|
|
@@ -11917,11 +12131,41 @@ function scanArgs(token, params, at, emit, options) {
|
|
|
11917
12131
|
}
|
|
11918
12132
|
scanCode(token.rawArgs, (i) => at(token.argsStart + i), emit);
|
|
11919
12133
|
}
|
|
12134
|
+
/**
|
|
12135
|
+
* Report the variables the `variable` parameters of a macro name
|
|
12136
|
+
* (`{unset $x}`, `{computed $x = …}`), when they are `$` or `%` variables.
|
|
12137
|
+
* Arguments that do not parse hold none.
|
|
12138
|
+
*/
|
|
12139
|
+
function scanVariableParameters(token, params, at, emit) {
|
|
12140
|
+
const spans = /* @__PURE__ */ new Map();
|
|
12141
|
+
try {
|
|
12142
|
+
parseMacroArgs(token.rawArgs, params, spans);
|
|
12143
|
+
} catch (err) {
|
|
12144
|
+
if (err instanceof MacroArgumentError) return;
|
|
12145
|
+
throw err;
|
|
12146
|
+
}
|
|
12147
|
+
for (const param of params) {
|
|
12148
|
+
const span = spans.get(param);
|
|
12149
|
+
if (param.type !== "variable" || !span) continue;
|
|
12150
|
+
const ref = referenceAt(token.rawArgs.slice(span[0], span[1]), 0, (i) => at(token.argsStart + span[0] + i));
|
|
12151
|
+
if (ref) emit(ref);
|
|
12152
|
+
}
|
|
12153
|
+
}
|
|
12154
|
+
/** Report the references in the selectors of a token, which are interpolated. */
|
|
12155
|
+
function scanSelectors(content, token, at, emit, options) {
|
|
12156
|
+
if (!("selectorsStart" in token) || token.selectorsStart === void 0 || token.selectorsEnd === void 0) return;
|
|
12157
|
+
const from = token.selectorsStart;
|
|
12158
|
+
scanInterpolations(content.slice(from, token.selectorsEnd), (i) => at(from + i), emit, {
|
|
12159
|
+
...options,
|
|
12160
|
+
storeVarMacros: NO_STORE_VAR_MACROS
|
|
12161
|
+
});
|
|
12162
|
+
}
|
|
11920
12163
|
/** Report the `$var` references in the tokens of `content`. */
|
|
11921
12164
|
function collectTokenRefs(content, tokens, at, emit, options) {
|
|
11922
12165
|
const { storeVarMacros, parametersOf } = options;
|
|
11923
12166
|
for (let t = 0; t < tokens.length; t++) {
|
|
11924
12167
|
const token = tokens[t];
|
|
12168
|
+
if (options.all && token.type !== "macro" && token.type !== "html" && token.type !== "text") scanSelectors(content, token, at, emit, options);
|
|
11925
12169
|
if (token.type === "variable") {
|
|
11926
12170
|
if ((token.scope === "variable" || token.scope === "transient") && token.name) {
|
|
11927
12171
|
const [name, ...path] = token.name.split(".");
|
|
@@ -11945,13 +12189,7 @@ function collectTokenRefs(content, tokens, at, emit, options) {
|
|
|
11945
12189
|
}
|
|
11946
12190
|
else if (token.type === "macro" && !token.isClose) {
|
|
11947
12191
|
scanArgs(token, parametersOf(token.name), at, emit, options);
|
|
11948
|
-
|
|
11949
|
-
const from = token.selectorsStart;
|
|
11950
|
-
scanInterpolations(content.slice(from, token.selectorsEnd), (i) => at(from + i), emit, {
|
|
11951
|
-
...options,
|
|
11952
|
-
storeVarMacros: NO_STORE_VAR_MACROS
|
|
11953
|
-
});
|
|
11954
|
-
}
|
|
12192
|
+
scanSelectors(content, token, at, emit, options);
|
|
11955
12193
|
if (storeVarMacros.has(token.name.toLowerCase())) {
|
|
11956
12194
|
const lead = token.rawArgs.length - token.rawArgs.trimStart().length;
|
|
11957
12195
|
const first = token.rawArgs.trim().split(/\s+/)[0] ?? "";
|
|
@@ -12021,6 +12259,243 @@ function checkVariableReferences(passages, declared, options) {
|
|
|
12021
12259
|
return diagnostics;
|
|
12022
12260
|
}
|
|
12023
12261
|
//#endregion
|
|
12262
|
+
//#region src/macro-discovery.ts
|
|
12263
|
+
/**
|
|
12264
|
+
* What `defineMacro({ … })` calls in JavaScript declare, read from the text
|
|
12265
|
+
* without running it (see discoverMacros): the literal parts of the config
|
|
12266
|
+
* object, and nothing else.
|
|
12267
|
+
*/
|
|
12268
|
+
/** The text of an object config, or the name of the variable that holds it. */
|
|
12269
|
+
var CALL_RE = /(?<![\w$])defineMacro\s*\(\s*/g;
|
|
12270
|
+
var IDENTIFIER_ARGUMENT_RE = /^([A-Za-z_$][\w$]*)\s*[,)]/;
|
|
12271
|
+
var WORD_RE = /[A-Za-z_]+/y;
|
|
12272
|
+
/** The literals of a config object, read to the end of what is static. */
|
|
12273
|
+
var ConfigReader = class extends Reader {
|
|
12274
|
+
constructor(..._args) {
|
|
12275
|
+
super(..._args);
|
|
12276
|
+
this.failed = false;
|
|
12277
|
+
}
|
|
12278
|
+
/** The static value of a member or element, whatever follows is skipped. */
|
|
12279
|
+
member() {
|
|
12280
|
+
const at = this.i;
|
|
12281
|
+
const datum = this.datum();
|
|
12282
|
+
this.space();
|
|
12283
|
+
if (datum && this.atElementEnd()) return datum;
|
|
12284
|
+
this.i = at;
|
|
12285
|
+
while (this.i < this.src.length && !this.atElementEnd()) if (!this.skipOne()) {
|
|
12286
|
+
this.fail();
|
|
12287
|
+
break;
|
|
12288
|
+
}
|
|
12289
|
+
}
|
|
12290
|
+
atElementEnd() {
|
|
12291
|
+
return this.i >= this.src.length || ",]}".includes(this.src.charAt(this.i));
|
|
12292
|
+
}
|
|
12293
|
+
/** The literal at the cursor, if it is a string, boolean, array or object. */
|
|
12294
|
+
datum() {
|
|
12295
|
+
const { src } = this;
|
|
12296
|
+
this.space();
|
|
12297
|
+
const c = src.charAt(this.i);
|
|
12298
|
+
if (c === "\"" || c === "'") {
|
|
12299
|
+
const start = this.i;
|
|
12300
|
+
const value = this.stringValue();
|
|
12301
|
+
return value === void 0 ? void 0 : {
|
|
12302
|
+
type: "string",
|
|
12303
|
+
value,
|
|
12304
|
+
start: start + 1,
|
|
12305
|
+
end: this.i - 1
|
|
12306
|
+
};
|
|
12307
|
+
}
|
|
12308
|
+
if (c === "`") return this.plainTemplate();
|
|
12309
|
+
if (c === "[") return this.array();
|
|
12310
|
+
if (c === "{") return this.record();
|
|
12311
|
+
WORD_RE.lastIndex = this.i;
|
|
12312
|
+
const word = WORD_RE.exec(src)?.[0];
|
|
12313
|
+
if (word === "true" || word === "false") {
|
|
12314
|
+
this.i = WORD_RE.lastIndex;
|
|
12315
|
+
return {
|
|
12316
|
+
type: "boolean",
|
|
12317
|
+
value: word === "true"
|
|
12318
|
+
};
|
|
12319
|
+
}
|
|
12320
|
+
}
|
|
12321
|
+
/** A template literal that has no `${}` and no escapes, as a string. */
|
|
12322
|
+
plainTemplate() {
|
|
12323
|
+
const { src } = this;
|
|
12324
|
+
const start = this.i;
|
|
12325
|
+
for (let i = start + 1; i < src.length; i++) {
|
|
12326
|
+
const c = src.charAt(i);
|
|
12327
|
+
if (c === "`") {
|
|
12328
|
+
this.i = i + 1;
|
|
12329
|
+
return {
|
|
12330
|
+
type: "string",
|
|
12331
|
+
value: src.slice(start + 1, i),
|
|
12332
|
+
start: start + 1,
|
|
12333
|
+
end: i
|
|
12334
|
+
};
|
|
12335
|
+
}
|
|
12336
|
+
if (c === "\\" || c === "$" && src.charAt(i + 1) === "{") break;
|
|
12337
|
+
}
|
|
12338
|
+
}
|
|
12339
|
+
/**
|
|
12340
|
+
* Read the elements up to `close`, each by `read`, which leaves the cursor
|
|
12341
|
+
* after what it read. False if the text ends first, or cannot be read.
|
|
12342
|
+
*/
|
|
12343
|
+
elements(close, read) {
|
|
12344
|
+
this.i++;
|
|
12345
|
+
for (;;) {
|
|
12346
|
+
this.space();
|
|
12347
|
+
const c = this.src.charAt(this.i);
|
|
12348
|
+
if (c === close) {
|
|
12349
|
+
this.i++;
|
|
12350
|
+
return true;
|
|
12351
|
+
}
|
|
12352
|
+
if (c === ",") {
|
|
12353
|
+
this.i++;
|
|
12354
|
+
continue;
|
|
12355
|
+
}
|
|
12356
|
+
if (this.failed || this.i >= this.src.length) return false;
|
|
12357
|
+
const before = this.i;
|
|
12358
|
+
read();
|
|
12359
|
+
if (this.i === before) this.fail();
|
|
12360
|
+
}
|
|
12361
|
+
}
|
|
12362
|
+
array() {
|
|
12363
|
+
const items = [];
|
|
12364
|
+
return this.elements("]", () => items.push(this.member())) ? {
|
|
12365
|
+
type: "array",
|
|
12366
|
+
items
|
|
12367
|
+
} : void 0;
|
|
12368
|
+
}
|
|
12369
|
+
record() {
|
|
12370
|
+
const props = /* @__PURE__ */ new Map();
|
|
12371
|
+
return this.elements("}", () => {
|
|
12372
|
+
const key = this.key();
|
|
12373
|
+
this.space();
|
|
12374
|
+
if (key !== void 0 && this.src.charAt(this.i) === ":") {
|
|
12375
|
+
this.i++;
|
|
12376
|
+
props.set(key, this.member());
|
|
12377
|
+
} else if (!this.skipMember()) this.fail();
|
|
12378
|
+
}) ? {
|
|
12379
|
+
type: "object",
|
|
12380
|
+
props
|
|
12381
|
+
} : void 0;
|
|
12382
|
+
}
|
|
12383
|
+
/** Stop reading: the text cannot be skipped through. */
|
|
12384
|
+
fail() {
|
|
12385
|
+
this.failed = true;
|
|
12386
|
+
}
|
|
12387
|
+
};
|
|
12388
|
+
/** The text with everything but code (strings, comments, regexes) blanked. */
|
|
12389
|
+
function codeOnly(source) {
|
|
12390
|
+
const chars = Array.from({ length: source.length }, () => " ");
|
|
12391
|
+
lexJs(source, { code(ch, index) {
|
|
12392
|
+
for (let k = 0; k < ch.length; k++) chars[index + k] = ch[k];
|
|
12393
|
+
} }, "statements");
|
|
12394
|
+
return chars.join("");
|
|
12395
|
+
}
|
|
12396
|
+
var stringOf = (d) => d?.type === "string" ? d : void 0;
|
|
12397
|
+
var booleanOf = (d) => d?.type === "boolean" ? d.value : void 0;
|
|
12398
|
+
var textOf = (d) => stringOf(d)?.value;
|
|
12399
|
+
var stringsOf = (d) => d?.type === "array" ? d.items.flatMap((item) => stringOf(item)?.value ?? []) : [];
|
|
12400
|
+
/** `{ [key]: value }` if `read` finds the property `key` written out, else `{}`. */
|
|
12401
|
+
function written(props, key, read) {
|
|
12402
|
+
const value = read(props.get(key));
|
|
12403
|
+
return value === void 0 ? {} : { [key]: value };
|
|
12404
|
+
}
|
|
12405
|
+
/** A declared parameter, if its name and type are written out. */
|
|
12406
|
+
function parameterOf(datum) {
|
|
12407
|
+
if (datum?.type !== "object") return void 0;
|
|
12408
|
+
const { props } = datum;
|
|
12409
|
+
const name = stringOf(props.get("name"));
|
|
12410
|
+
const type = stringOf(props.get("type"));
|
|
12411
|
+
if (!name || !type) return void 0;
|
|
12412
|
+
const param = {
|
|
12413
|
+
name: name.value,
|
|
12414
|
+
type: type.value,
|
|
12415
|
+
...written(props, "required", booleanOf),
|
|
12416
|
+
...written(props, "description", textOf),
|
|
12417
|
+
...written(props, "holds", (d) => textOf(d))
|
|
12418
|
+
};
|
|
12419
|
+
if (props.has("parameters")) {
|
|
12420
|
+
const options = parametersOf(props.get("parameters"));
|
|
12421
|
+
if (!options) return void 0;
|
|
12422
|
+
param.parameters = options;
|
|
12423
|
+
}
|
|
12424
|
+
return param;
|
|
12425
|
+
}
|
|
12426
|
+
/** The parameters of an array literal of them, if every one is written out. */
|
|
12427
|
+
function parametersOf(datum) {
|
|
12428
|
+
if (datum?.type !== "array") return void 0;
|
|
12429
|
+
const params = [];
|
|
12430
|
+
for (const item of datum.items) {
|
|
12431
|
+
const param = parameterOf(item);
|
|
12432
|
+
if (!param) return void 0;
|
|
12433
|
+
params.push(param);
|
|
12434
|
+
}
|
|
12435
|
+
return params;
|
|
12436
|
+
}
|
|
12437
|
+
/** The macro a config object declares, if its name is written out. */
|
|
12438
|
+
function macroOf(config) {
|
|
12439
|
+
if (config.type !== "object") return void 0;
|
|
12440
|
+
const { props } = config;
|
|
12441
|
+
const name = stringOf(props.get("name"));
|
|
12442
|
+
if (!name?.value) return void 0;
|
|
12443
|
+
const subMacros = stringsOf(props.get("subMacros"));
|
|
12444
|
+
const block = booleanOf(props.get("block"));
|
|
12445
|
+
const macro = {
|
|
12446
|
+
name: name.value,
|
|
12447
|
+
block: block === true || block !== false && subMacros.length > 0,
|
|
12448
|
+
subMacros,
|
|
12449
|
+
nameStart: name.start,
|
|
12450
|
+
nameEnd: name.end,
|
|
12451
|
+
...written(props, "interpolate", booleanOf),
|
|
12452
|
+
...written(props, "storeVar", booleanOf),
|
|
12453
|
+
...written(props, "merged", booleanOf),
|
|
12454
|
+
...written(props, "description", textOf)
|
|
12455
|
+
};
|
|
12456
|
+
const parameters = parametersOf(props.get("parameters"));
|
|
12457
|
+
if (parameters) try {
|
|
12458
|
+
checkParameterTypes(macro.name, parameters);
|
|
12459
|
+
macro.parameters = parameters;
|
|
12460
|
+
} catch {}
|
|
12461
|
+
return macro;
|
|
12462
|
+
}
|
|
12463
|
+
/**
|
|
12464
|
+
* The macros the `defineMacro({ … })` and `Story.defineMacro({ … })` calls in
|
|
12465
|
+
* `source` (JavaScript: a script passage, the body of a `{do}`, a project
|
|
12466
|
+
* file) declare, in source order, read from the text without running it. A
|
|
12467
|
+
* call whose config is an object literal (or a variable declared as one with
|
|
12468
|
+
* `const`, `let` or `var`) and whose `name` is a string is found, wherever it
|
|
12469
|
+
* is, even inside a function. Only what is written out is read: a `block`,
|
|
12470
|
+
* `interpolate`, `storeVar` or `merged` that is a boolean literal, the
|
|
12471
|
+
* strings of `subMacros`, and `parameters` when every one is an object
|
|
12472
|
+
* literal with a string `name` and `type` (and `holds`, `required`,
|
|
12473
|
+
* `description` and nested `parameters` of options when written out as such);
|
|
12474
|
+
* a list with a parameter that is not, or that `defineMacro` would refuse,
|
|
12475
|
+
* declares none. It is tolerant: text it cannot read is skipped, and it
|
|
12476
|
+
* throws for none.
|
|
12477
|
+
*/
|
|
12478
|
+
function discoverMacros(source) {
|
|
12479
|
+
const code = codeOnly(source);
|
|
12480
|
+
const found = [];
|
|
12481
|
+
for (const call of code.matchAll(CALL_RE)) {
|
|
12482
|
+
let at = call.index + call[0].length;
|
|
12483
|
+
if (code.charAt(at) !== "{") {
|
|
12484
|
+
const variable = IDENTIFIER_ARGUMENT_RE.exec(code.slice(at))?.[1];
|
|
12485
|
+
if (!variable) continue;
|
|
12486
|
+
const declaration = new RegExp(`(?<![\\w$.])(?:const|let|var)\\s+${variable.replace(/\$/g, "\\$")}\\s*=\\s*(?=\\{)`).exec(code);
|
|
12487
|
+
if (!declaration) continue;
|
|
12488
|
+
at = declaration.index + declaration[0].length;
|
|
12489
|
+
}
|
|
12490
|
+
const reader = new ConfigReader(source);
|
|
12491
|
+
reader.i = at;
|
|
12492
|
+
const config = reader.datum();
|
|
12493
|
+
const macro = config && macroOf(config);
|
|
12494
|
+
if (macro) found.push(macro);
|
|
12495
|
+
}
|
|
12496
|
+
return found;
|
|
12497
|
+
}
|
|
12498
|
+
//#endregion
|
|
12024
12499
|
//#region src/components/macros/include-args.ts
|
|
12025
12500
|
/**
|
|
12026
12501
|
* The parameters of `{include}`. A standalone `inline` flag only counts
|
|
@@ -12129,7 +12604,8 @@ function validateStoryMarkup(passages, macros, options = {}) {
|
|
|
12129
12604
|
macroNames: known,
|
|
12130
12605
|
parametersOf,
|
|
12131
12606
|
isBlockMacro: (name) => blocks.has(name.toLowerCase()) || isBlockMacro(name),
|
|
12132
|
-
checkPassageNames: options.checkPassageNames
|
|
12607
|
+
checkPassageNames: options.checkPassageNames,
|
|
12608
|
+
tolerant: options.tolerant
|
|
12133
12609
|
});
|
|
12134
12610
|
}
|
|
12135
12611
|
/** Whether a macro takes a body, among `macros` and the built-in ones. */
|
|
@@ -12176,11 +12652,12 @@ function widgetDefinitions(passages, macros = []) {
|
|
|
12176
12652
|
/** Passages tagged so hold code or styles, not markup. */
|
|
12177
12653
|
var NOT_MARKUP_TAGS = ["script", "stylesheet"];
|
|
12178
12654
|
/** What reading the variable references of markup depends on. */
|
|
12179
|
-
function referenceOptions(macros) {
|
|
12180
|
-
const
|
|
12655
|
+
function referenceOptions(macros, all = false) {
|
|
12656
|
+
const list = [...macros];
|
|
12181
12657
|
return {
|
|
12182
|
-
|
|
12183
|
-
|
|
12658
|
+
all,
|
|
12659
|
+
storeVarMacros: new Set(list.filter((m) => m.storeVar).map((m) => m.name.toLowerCase())),
|
|
12660
|
+
parametersOf: parameterLookup(list),
|
|
12184
12661
|
tolerant: true
|
|
12185
12662
|
};
|
|
12186
12663
|
}
|
|
@@ -12192,9 +12669,16 @@ function referenceOptions(macros) {
|
|
|
12192
12669
|
* bound by input macros, and the markup in labels and HTML attributes. Prose
|
|
12193
12670
|
* is literal text. Malformed tags are skipped, so it reads half-typed markup.
|
|
12194
12671
|
* The macros are those the markup may use, built-in and user-defined.
|
|
12672
|
+
*
|
|
12673
|
+
* These are the references the story start checks. With `all: true`, the
|
|
12674
|
+
* list is complete (the checked ones are among it, in source order): it also
|
|
12675
|
+
* has the variable a macro names in a `variable` parameter, such as the
|
|
12676
|
+
* target of `{unset}` and `{computed}`, and the `{$name}` in the selectors of
|
|
12677
|
+
* a link, display or expression (`[[.c{$name} Go->T]]`). A rename or a find
|
|
12678
|
+
* of references needs these too.
|
|
12195
12679
|
*/
|
|
12196
|
-
function variableReferences(source, macros = []) {
|
|
12197
|
-
return collectVariableReferences(source, referenceOptions(macros));
|
|
12680
|
+
function variableReferences(source, macros = [], options = {}) {
|
|
12681
|
+
return collectVariableReferences(source, referenceOptions(macros, options.all));
|
|
12198
12682
|
}
|
|
12199
12683
|
/**
|
|
12200
12684
|
* The variable references of the passages' markup that are not valid against
|
|
@@ -12207,4 +12691,4 @@ function validateVariableReferences(passages, declarations, macros = []) {
|
|
|
12207
12691
|
return checkVariableReferences([...passages].filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros));
|
|
12208
12692
|
}
|
|
12209
12693
|
//#endregion
|
|
12210
|
-
export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, isBlockMacro, isSigil, lexJs, lexTemplate, pairMarkup, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
|
|
12694
|
+
export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, discoverMacros, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, isBlockMacro, isSigil, lexJs, lexTemplate, pairMarkup, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
|