@rohal12/spindle 0.59.23 → 0.59.26
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 +694 -407
- package/dist/pkg/story-variables.js +510 -123
- package/dist/pkg/tooling.js +4 -0
- package/package.json +23 -24
- package/src/automation/load-yaml.ts +1 -1
- package/src/code-check.ts +23 -9
- package/src/components/PassageDialog.tsx +28 -1
- package/src/components/macros/MacroError.tsx +1 -1
- package/src/components/macros/MenubarButtons.tsx +3 -0
- package/src/components/macros/SaveManager.tsx +2 -2
- package/src/components/macros/SettingsControls.tsx +10 -6
- package/src/components/macros/Type.tsx +1 -1
- package/src/components/macros/detached-body.tsx +62 -3
- package/src/components/macros/macro-args.ts +1 -2
- package/src/execute-mutation.ts +4 -3
- package/src/hooks/use-modal-focus.ts +63 -20
- package/src/hooks/use-story-fields.ts +1 -1
- 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 +25 -13
- package/src/settings.ts +9 -0
- package/src/static-literal.ts +1 -6
- package/src/store.ts +1 -1
- package/src/story-variables.ts +291 -121
- package/src/tooling.ts +89 -1
- package/src/widgets/widget-def.ts +93 -22
- package/types/index.d.ts +2 -10
- package/types/tooling.d.ts +126 -17
|
@@ -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
|
};
|
|
@@ -8831,7 +8871,7 @@ function notABody(src, pos) {
|
|
|
8831
8871
|
return NOT_A_BODY_RE.test(src);
|
|
8832
8872
|
}
|
|
8833
8873
|
/** Tokens that may end an operand, and so a statement before a line break. */
|
|
8834
|
-
var OPERAND_ENDS = new Set([
|
|
8874
|
+
var OPERAND_ENDS = /* @__PURE__ */ new Set([
|
|
8835
8875
|
types$1.name,
|
|
8836
8876
|
types$1.num,
|
|
8837
8877
|
types$1.string,
|
|
@@ -8957,13 +8997,13 @@ function transientAssignment(p, end) {
|
|
|
8957
8997
|
return false;
|
|
8958
8998
|
}
|
|
8959
8999
|
}
|
|
8960
|
-
var OPENERS = new Set([
|
|
9000
|
+
var OPENERS = /* @__PURE__ */ new Set([
|
|
8961
9001
|
types$1.parenL,
|
|
8962
9002
|
types$1.bracketL,
|
|
8963
9003
|
types$1.braceL,
|
|
8964
9004
|
types$1.dollarBraceL
|
|
8965
9005
|
]);
|
|
8966
|
-
var CLOSERS = new Set([
|
|
9006
|
+
var CLOSERS = /* @__PURE__ */ new Set([
|
|
8967
9007
|
types$1.parenR,
|
|
8968
9008
|
types$1.bracketR,
|
|
8969
9009
|
types$1.braceR
|
|
@@ -9260,7 +9300,7 @@ var WORD_RE$1 = /[\p{ID_Continue}$.]*/uy;
|
|
|
9260
9300
|
/** The flags after a regex literal, whatever they are. */
|
|
9261
9301
|
var FLAGS_RE = /[\p{ID_Continue}$]*/uy;
|
|
9262
9302
|
/** Words a string may follow with no space between (`of'x'`, `get"y"`). */
|
|
9263
|
-
var WORDS_BEFORE_STRING = new Set([
|
|
9303
|
+
var WORDS_BEFORE_STRING = /* @__PURE__ */ new Set([
|
|
9264
9304
|
"of",
|
|
9265
9305
|
"get",
|
|
9266
9306
|
"set",
|
|
@@ -10444,7 +10484,7 @@ function evaluatePassageName(expr, evaluate, { storyData, currentPassage }) {
|
|
|
10444
10484
|
return name;
|
|
10445
10485
|
}
|
|
10446
10486
|
/** The parameters of the built-in sub-macros that take arguments. */
|
|
10447
|
-
var SUB_MACRO_PARAMETERS = new Map([["option", [{
|
|
10487
|
+
var SUB_MACRO_PARAMETERS = /* @__PURE__ */ new Map([["option", [{
|
|
10448
10488
|
name: "value",
|
|
10449
10489
|
type: "string",
|
|
10450
10490
|
holds: "text",
|
|
@@ -10494,13 +10534,13 @@ function extentOf(piece) {
|
|
|
10494
10534
|
return piece.kind === "code" ? piece.code.length : piece.kind === "text" ? piece.text.length : piece.length;
|
|
10495
10535
|
}
|
|
10496
10536
|
/** Macros whose whole argument text is one expression: branch conditions. */
|
|
10497
|
-
var CONDITION_MACROS = new Set([
|
|
10537
|
+
var CONDITION_MACROS = /* @__PURE__ */ new Set([
|
|
10498
10538
|
"if",
|
|
10499
10539
|
"elseif",
|
|
10500
10540
|
"case"
|
|
10501
10541
|
]);
|
|
10502
10542
|
/** Block macros whose body is the name of a passage. */
|
|
10503
|
-
var PASSAGE_BODIES = new Set(["dialog"]);
|
|
10543
|
+
var PASSAGE_BODIES = /* @__PURE__ */ new Set(["dialog"]);
|
|
10504
10544
|
/**
|
|
10505
10545
|
* `params` with each `string` and `text` parameter (options too) saying
|
|
10506
10546
|
* what it holds: what it declares, else `holds`.
|
|
@@ -10582,19 +10622,13 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
10582
10622
|
yield textPiece(value, at, `In the ${name} attribute of <${token.tag}>: `);
|
|
10583
10623
|
continue;
|
|
10584
10624
|
}
|
|
10585
|
-
|
|
10586
|
-
|
|
10587
|
-
|
|
10588
|
-
|
|
10589
|
-
|
|
10590
|
-
|
|
10591
|
-
|
|
10592
|
-
code: part.expr,
|
|
10593
|
-
offset: at + k,
|
|
10594
|
-
goal: "expression",
|
|
10595
|
-
label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`
|
|
10596
|
-
};
|
|
10597
|
-
}
|
|
10625
|
+
for (const { expr, at: k } of sigilExpressions(value)) yield {
|
|
10626
|
+
kind: "code",
|
|
10627
|
+
code: expr,
|
|
10628
|
+
offset: at + k,
|
|
10629
|
+
goal: "expression",
|
|
10630
|
+
label: `{${expr}} in the ${name} attribute of <${token.tag}>`
|
|
10631
|
+
};
|
|
10598
10632
|
}
|
|
10599
10633
|
else if (token.type === "macro" && !token.isClose) {
|
|
10600
10634
|
const name = token.name.toLowerCase();
|
|
@@ -10862,6 +10896,24 @@ function attributeValues(src, token) {
|
|
|
10862
10896
|
return values;
|
|
10863
10897
|
}
|
|
10864
10898
|
/**
|
|
10899
|
+
* The `{$…}` expressions in the value of a code attribute (`onclick`, see
|
|
10900
|
+
* isCodeAttribute), with where each is in the value.
|
|
10901
|
+
*/
|
|
10902
|
+
function sigilExpressions(value) {
|
|
10903
|
+
const found = [];
|
|
10904
|
+
let from = 0;
|
|
10905
|
+
for (const part of splitSigilTemplate(value)) {
|
|
10906
|
+
if (!("expr" in part)) continue;
|
|
10907
|
+
const at = locate(value, part.expr, from);
|
|
10908
|
+
from = at + part.expr.length;
|
|
10909
|
+
found.push({
|
|
10910
|
+
expr: part.expr,
|
|
10911
|
+
at
|
|
10912
|
+
});
|
|
10913
|
+
}
|
|
10914
|
+
return found;
|
|
10915
|
+
}
|
|
10916
|
+
/**
|
|
10865
10917
|
* Index of `part` in `text` from `from` on, else anywhere, else `from`: the
|
|
10866
10918
|
* place to report an error in `part` at.
|
|
10867
10919
|
*/
|
|
@@ -11071,37 +11123,71 @@ function widgetDef({ name = "", parameters = "" }) {
|
|
|
11071
11123
|
function parseWidgetDef(rawArgs) {
|
|
11072
11124
|
return widgetDef(parseMacroArgs(rawArgs, WIDGET_PARAMETERS));
|
|
11073
11125
|
}
|
|
11126
|
+
/** Where the name is written in the arguments, without its quotes. */
|
|
11127
|
+
function nameSpan(rawArgs) {
|
|
11128
|
+
const spans = /* @__PURE__ */ new Map();
|
|
11129
|
+
parseMacroArgs(rawArgs, WIDGET_PARAMETERS, spans);
|
|
11130
|
+
const [start, end] = spans.get(WIDGET_PARAMETERS[0]) ?? [0, 0];
|
|
11131
|
+
const quote = rawArgs[start];
|
|
11132
|
+
return (quote === "\"" || quote === "'") && end - start >= 2 ? [start + 1, rawArgs[end - 1] === quote ? end - 1 : end] : [start, end];
|
|
11133
|
+
}
|
|
11074
11134
|
/**
|
|
11075
|
-
* The
|
|
11076
|
-
*
|
|
11077
|
-
*
|
|
11078
|
-
*
|
|
11135
|
+
* The widgets that StoryInit and the passages tagged `widget` define, in
|
|
11136
|
+
* source order: the ones the runtime registers, read tolerantly (a half-typed
|
|
11137
|
+
* definition is still reported, without a `closeStart`). Definitions whose
|
|
11138
|
+
* arguments cannot be read are left out.
|
|
11079
11139
|
*
|
|
11080
11140
|
* The passages are read as flat tokens, which need no block macros to be
|
|
11081
11141
|
* known, so a `{@children}` in an HTML comment or in a `{do}` body is text
|
|
11082
|
-
* here as it is to the parser, and does not make a block widget (#387).
|
|
11142
|
+
* here as it is to the parser, and does not make a block widget (#387). In
|
|
11143
|
+
* nested definitions, it belongs to the innermost.
|
|
11083
11144
|
*/
|
|
11084
|
-
function
|
|
11085
|
-
const
|
|
11145
|
+
function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
|
|
11146
|
+
const found = [];
|
|
11086
11147
|
for (const passage of passages) {
|
|
11087
11148
|
if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
|
|
11088
11149
|
const open = [];
|
|
11150
|
+
const done = [];
|
|
11089
11151
|
for (const token of tokenizeMarkupTolerant(passage.content).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
|
|
11090
|
-
if (!token.isClose) {
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11152
|
+
if (!token.isClose) open.push({
|
|
11153
|
+
token,
|
|
11154
|
+
isBlock: false
|
|
11155
|
+
});
|
|
11156
|
+
else {
|
|
11157
|
+
const def = open.pop();
|
|
11158
|
+
if (def) done.push({
|
|
11159
|
+
...def,
|
|
11160
|
+
closeStart: token.start
|
|
11094
11161
|
});
|
|
11095
|
-
continue;
|
|
11096
11162
|
}
|
|
11097
|
-
const def = open.pop();
|
|
11098
|
-
if (!def?.isBlock) continue;
|
|
11099
|
-
try {
|
|
11100
|
-
names.push(parseWidgetDef(def.rawArgs).name);
|
|
11101
|
-
} catch {}
|
|
11102
11163
|
} else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf))) open[open.length - 1].isBlock = true;
|
|
11164
|
+
done.push(...open);
|
|
11165
|
+
const defs = [];
|
|
11166
|
+
for (const { token, isBlock, closeStart } of done) try {
|
|
11167
|
+
const [from, to] = nameSpan(token.rawArgs);
|
|
11168
|
+
defs.push({
|
|
11169
|
+
...parseWidgetDef(token.rawArgs),
|
|
11170
|
+
block: isBlock,
|
|
11171
|
+
passage: passage.name,
|
|
11172
|
+
start: token.start,
|
|
11173
|
+
end: token.end,
|
|
11174
|
+
nameStart: token.argsStart + from,
|
|
11175
|
+
nameEnd: token.argsStart + to,
|
|
11176
|
+
...closeStart === void 0 ? {} : { closeStart }
|
|
11177
|
+
});
|
|
11178
|
+
} catch {}
|
|
11179
|
+
found.push(...defs.sort((a, b) => a.start - b.start));
|
|
11103
11180
|
}
|
|
11104
|
-
return
|
|
11181
|
+
return found;
|
|
11182
|
+
}
|
|
11183
|
+
/**
|
|
11184
|
+
* The names of the block widgets (those whose body renders `{@children}`)
|
|
11185
|
+
* that StoryInit and the passages tagged `widget` define, closed. They must
|
|
11186
|
+
* be known as block macros before any passage is parsed, so that passages
|
|
11187
|
+
* invoking them nest their content whatever the passage order.
|
|
11188
|
+
*/
|
|
11189
|
+
function blockWidgetNames(passages, parametersOf = registeredParameters) {
|
|
11190
|
+
return widgetDefinitions$1(passages, parametersOf).filter((def) => def.block && def.closeStart !== void 0).map((def) => def.name);
|
|
11105
11191
|
}
|
|
11106
11192
|
//#endregion
|
|
11107
11193
|
//#region src/markup/validate.ts
|
|
@@ -11116,14 +11202,14 @@ function blockWidgetNames(passages, parametersOf = registeredParameters) {
|
|
|
11116
11202
|
* Passages that hold no markup: declarations, and the JavaScript function
|
|
11117
11203
|
* body of SaveTitle.
|
|
11118
11204
|
*/
|
|
11119
|
-
var NOT_MARKUP = new Set([
|
|
11205
|
+
var NOT_MARKUP = /* @__PURE__ */ new Set([
|
|
11120
11206
|
"StoryVariables",
|
|
11121
11207
|
"StoryTransients",
|
|
11122
11208
|
"SaveTitle"
|
|
11123
11209
|
]);
|
|
11124
|
-
var NOT_MARKUP_TAGS = ["script", "stylesheet"];
|
|
11210
|
+
var NOT_MARKUP_TAGS$1 = ["script", "stylesheet"];
|
|
11125
11211
|
/** Branch macros, which their parent macro renders. */
|
|
11126
|
-
var BRANCH_MACROS = new Set([
|
|
11212
|
+
var BRANCH_MACROS = /* @__PURE__ */ new Set([
|
|
11127
11213
|
"elseif",
|
|
11128
11214
|
"else",
|
|
11129
11215
|
"case",
|
|
@@ -11208,7 +11294,7 @@ function validateMarkup(passages, options) {
|
|
|
11208
11294
|
for (const passage of passages) {
|
|
11209
11295
|
passageNames.add(passage.name);
|
|
11210
11296
|
if (NOT_MARKUP.has(passage.name)) continue;
|
|
11211
|
-
if (passage.tags?.some((tag) => NOT_MARKUP_TAGS.includes(tag))) continue;
|
|
11297
|
+
if (passage.tags?.some((tag) => NOT_MARKUP_TAGS$1.includes(tag))) continue;
|
|
11212
11298
|
const reported = !options.only || options.only(passage);
|
|
11213
11299
|
try {
|
|
11214
11300
|
const tokens = tokenizeMarkup(passage.content);
|
|
@@ -11570,15 +11656,38 @@ var Reader = class {
|
|
|
11570
11656
|
};
|
|
11571
11657
|
//#endregion
|
|
11572
11658
|
//#region src/story-variables.ts
|
|
11659
|
+
/**
|
|
11660
|
+
* The tokens of markup, or none if it is malformed (validateMarkup reports
|
|
11661
|
+
* that, with its position); in tolerant mode, those of the well-formed parts.
|
|
11662
|
+
*/
|
|
11663
|
+
function tokensOf(text, textMode, { tolerant } = {}) {
|
|
11664
|
+
if (tolerant) return tokenizeMarkupTolerant(text, { text: textMode }).tokens;
|
|
11665
|
+
try {
|
|
11666
|
+
return tokenizeMarkup(text, { text: textMode });
|
|
11667
|
+
} catch (err) {
|
|
11668
|
+
if (err instanceof MarkupError) return [];
|
|
11669
|
+
throw err;
|
|
11670
|
+
}
|
|
11671
|
+
}
|
|
11573
11672
|
function declarationRegex(sigil) {
|
|
11574
11673
|
const escaped = sigil.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
11575
11674
|
return new RegExp(`^${escaped}(\\w+)\\s*=\\s*(.+)$`);
|
|
11576
11675
|
}
|
|
11577
|
-
|
|
11676
|
+
/** A `$name` or `%name` reference with its dot path, at a sigil the lexer found. */
|
|
11677
|
+
var VAR_PATH_RE = /([$%])(\w+(?:\.\w+)*)/y;
|
|
11678
|
+
/** Quoted first argument of an input macro naming a story variable. */
|
|
11679
|
+
var QUOTED_VAR_ARG_RE = /^["']\$(\w+(?:\.\w+)*)["']?$/;
|
|
11680
|
+
var VALID_VAR_TYPES = /* @__PURE__ */ new Set([
|
|
11578
11681
|
"number",
|
|
11579
11682
|
"string",
|
|
11580
11683
|
"boolean"
|
|
11581
11684
|
]);
|
|
11685
|
+
/** Boxed sample values whose members a primitive of each type can access. */
|
|
11686
|
+
var PRIMITIVE_SAMPLES = {
|
|
11687
|
+
string: Object(""),
|
|
11688
|
+
number: Object(0),
|
|
11689
|
+
boolean: Object(false)
|
|
11690
|
+
};
|
|
11582
11691
|
/**
|
|
11583
11692
|
* The schema of a default value. An object met again (a backreference, a
|
|
11584
11693
|
* shared subtree) has the schema made for it the first time, so a cyclic
|
|
@@ -11718,6 +11827,240 @@ function parseStoryVariables(content, sigil = "$") {
|
|
|
11718
11827
|
}
|
|
11719
11828
|
return schema;
|
|
11720
11829
|
}
|
|
11830
|
+
/**
|
|
11831
|
+
* Check a reference against the declarations: the error code and message, or
|
|
11832
|
+
* null if it is valid. (Unknown fields of objects are valid: classes
|
|
11833
|
+
* registered with Story.registerClass() can add members that are not in the
|
|
11834
|
+
* defaults.)
|
|
11835
|
+
*/
|
|
11836
|
+
function checkReference(ref, declared) {
|
|
11837
|
+
const label = (path) => ref.sigil + [ref.name, ...path].join(".");
|
|
11838
|
+
const nameError = variableNameError(ref.name, ref.sigil + ref.name);
|
|
11839
|
+
if (nameError) return {
|
|
11840
|
+
code: "reserved-name",
|
|
11841
|
+
message: nameError
|
|
11842
|
+
};
|
|
11843
|
+
const schema = ref.sigil === "$" ? declared.variables : declared.transients;
|
|
11844
|
+
if (!schema) return null;
|
|
11845
|
+
if (!schema.has(ref.name)) return ref.sigil === "$" ? {
|
|
11846
|
+
code: "undeclared-variable",
|
|
11847
|
+
message: `Undeclared variable: ${label(ref.path)}`
|
|
11848
|
+
} : {
|
|
11849
|
+
code: "undeclared-transient",
|
|
11850
|
+
message: `Undeclared transient: ${label(ref.path)}`
|
|
11851
|
+
};
|
|
11852
|
+
let current = schema.get(ref.name);
|
|
11853
|
+
for (let i = 0; current && i < ref.path.length; i++) {
|
|
11854
|
+
const part = ref.path[i];
|
|
11855
|
+
if (current.type === "array") return null;
|
|
11856
|
+
if (current.type === "null") return null;
|
|
11857
|
+
const sample = PRIMITIVE_SAMPLES[current.type];
|
|
11858
|
+
if (sample && part in sample) {
|
|
11859
|
+
const memberType = typeof sample[part];
|
|
11860
|
+
if (!VALID_VAR_TYPES.has(memberType)) return null;
|
|
11861
|
+
current = { type: memberType };
|
|
11862
|
+
continue;
|
|
11863
|
+
}
|
|
11864
|
+
if (current.type !== "object" || !current.fields) return {
|
|
11865
|
+
code: "primitive-field",
|
|
11866
|
+
message: `Cannot access field "${part}" on ${label(ref.path.slice(0, i))} (type: ${current.type})`
|
|
11867
|
+
};
|
|
11868
|
+
current = current.fields.get(part);
|
|
11869
|
+
}
|
|
11870
|
+
return null;
|
|
11871
|
+
}
|
|
11872
|
+
var NO_STORE_VAR_MACROS = /* @__PURE__ */ new Set();
|
|
11873
|
+
/** A reference written at `index` of `code`, with its dot path. */
|
|
11874
|
+
function referenceAt(code, index, at) {
|
|
11875
|
+
VAR_PATH_RE.lastIndex = index;
|
|
11876
|
+
const match = VAR_PATH_RE.exec(code);
|
|
11877
|
+
if (!match) return void 0;
|
|
11878
|
+
const [name, ...path] = match[2].split(".");
|
|
11879
|
+
return {
|
|
11880
|
+
sigil: match[1],
|
|
11881
|
+
name,
|
|
11882
|
+
path,
|
|
11883
|
+
start: at(index),
|
|
11884
|
+
end: at(index + match[0].length)
|
|
11885
|
+
};
|
|
11886
|
+
}
|
|
11887
|
+
/**
|
|
11888
|
+
* Scan the value of a code attribute (`onclick`, see isCodeAttribute) for
|
|
11889
|
+
* the `{$…}` references resolved in it; its other braces are code. `at` is
|
|
11890
|
+
* where the value is.
|
|
11891
|
+
*/
|
|
11892
|
+
function scanSigilReferences(value, at, emit) {
|
|
11893
|
+
for (const { expr, at: k } of sigilExpressions(value)) scanCode(expr, (i) => at(k + i), emit);
|
|
11894
|
+
}
|
|
11895
|
+
/**
|
|
11896
|
+
* Scan literal text (string contents, HTML attribute values) for the markup
|
|
11897
|
+
* that labels and HTML attributes evaluate at runtime: `{$…}` displays,
|
|
11898
|
+
* expressions and macros, read as in passage text. A bare `$word` in
|
|
11899
|
+
* literal text is not a reference.
|
|
11900
|
+
*/
|
|
11901
|
+
function scanInterpolations(text, at, emit, options) {
|
|
11902
|
+
if (!text.includes("{")) return;
|
|
11903
|
+
collectTokenRefs(text, tokensOf(text, true, options), at, emit, options);
|
|
11904
|
+
}
|
|
11905
|
+
/**
|
|
11906
|
+
* Report `$var` references in JavaScript code, lexed as the expression
|
|
11907
|
+
* engine lexes it (`lexJs`): references in code, but none inside string or
|
|
11908
|
+
* regex literals or comments, nor property names (`a.$b`, `{ $b: 1 }`).
|
|
11909
|
+
* The text of string and template literals is not scanned: a string in code
|
|
11910
|
+
* is literal text unless a macro argument that holds markup is read as such
|
|
11911
|
+
* (see scanArgs); the `${…}` parts of template literals are code.
|
|
11912
|
+
*/
|
|
11913
|
+
function scanCode(code, at, emit, goal = "expression") {
|
|
11914
|
+
const parsed = parseOrError(code, goal);
|
|
11915
|
+
if (parsed instanceof CodeSyntaxError) {
|
|
11916
|
+
scanCodeLeniently(code, at, emit, goal);
|
|
11917
|
+
return;
|
|
11918
|
+
}
|
|
11919
|
+
for (const ref of parsed.refs) {
|
|
11920
|
+
if (ref.sigil !== "$" && ref.sigil !== "%") continue;
|
|
11921
|
+
const found = referenceAt(code, ref.start, at);
|
|
11922
|
+
if (found) emit(found);
|
|
11923
|
+
}
|
|
11924
|
+
}
|
|
11925
|
+
/** `scanCode` for code acorn can't parse: lexed leniently. */
|
|
11926
|
+
function scanCodeLeniently(code, at, emit, goal) {
|
|
11927
|
+
lexJs(code, {
|
|
11928
|
+
variable(sigil, _name, index) {
|
|
11929
|
+
if (sigil !== "$" && sigil !== "%") return;
|
|
11930
|
+
const found = referenceAt(code, index, at);
|
|
11931
|
+
if (found) emit(found);
|
|
11932
|
+
},
|
|
11933
|
+
literal() {}
|
|
11934
|
+
}, goal);
|
|
11935
|
+
}
|
|
11936
|
+
/**
|
|
11937
|
+
* Report the references in the arguments of a macro by what its parameters
|
|
11938
|
+
* say each holds (see ParameterDef.holds): code is scanned as code and
|
|
11939
|
+
* markup as markup, but literal text (a placeholder, a passage name) holds
|
|
11940
|
+
* none. A macro without declared parameters, or arguments that do not
|
|
11941
|
+
* parse, are scanned as code.
|
|
11942
|
+
*/
|
|
11943
|
+
function scanArgs(token, params, at, emit, options) {
|
|
11944
|
+
if (!token.rawArgs) return;
|
|
11945
|
+
if (params) {
|
|
11946
|
+
const pieces = [...argPieces(token.rawArgs, token.argsStart, params, token.name, "")];
|
|
11947
|
+
if (!pieces.some((piece) => piece.kind === "argument-error")) {
|
|
11948
|
+
for (const piece of pieces) {
|
|
11949
|
+
const pieceAt = (i) => at(pieceOffset(piece, i));
|
|
11950
|
+
if (piece.kind === "code") scanCode(piece.code, pieceAt, emit, piece.goal);
|
|
11951
|
+
else if (piece.kind === "text") scanInterpolations(piece.text, pieceAt, emit, {
|
|
11952
|
+
...options,
|
|
11953
|
+
storeVarMacros: NO_STORE_VAR_MACROS
|
|
11954
|
+
});
|
|
11955
|
+
}
|
|
11956
|
+
return;
|
|
11957
|
+
}
|
|
11958
|
+
}
|
|
11959
|
+
scanCode(token.rawArgs, (i) => at(token.argsStart + i), emit);
|
|
11960
|
+
}
|
|
11961
|
+
/** Report the `$var` references in the tokens of `content`. */
|
|
11962
|
+
function collectTokenRefs(content, tokens, at, emit, options) {
|
|
11963
|
+
const { storeVarMacros, parametersOf } = options;
|
|
11964
|
+
for (let t = 0; t < tokens.length; t++) {
|
|
11965
|
+
const token = tokens[t];
|
|
11966
|
+
if (token.type === "variable") {
|
|
11967
|
+
if ((token.scope === "variable" || token.scope === "transient") && token.name) {
|
|
11968
|
+
const [name, ...path] = token.name.split(".");
|
|
11969
|
+
emit({
|
|
11970
|
+
sigil: token.scope === "variable" ? "$" : "%",
|
|
11971
|
+
name,
|
|
11972
|
+
path,
|
|
11973
|
+
start: at(token.nameStart - 1),
|
|
11974
|
+
end: at(token.nameEnd)
|
|
11975
|
+
});
|
|
11976
|
+
}
|
|
11977
|
+
} else if (token.type === "link") scanInterpolations(token.display, (i) => at(token.displayStart + i), emit, {
|
|
11978
|
+
...options,
|
|
11979
|
+
storeVarMacros: NO_STORE_VAR_MACROS
|
|
11980
|
+
});
|
|
11981
|
+
else if (token.type === "expression") scanCode(token.expression, (i) => at(token.expressionStart + i), emit);
|
|
11982
|
+
else if (token.type === "html") for (const { name, value, at: valueAt } of attributeValues(content, token)) {
|
|
11983
|
+
const valueIn = (i) => at(valueAt + i);
|
|
11984
|
+
if (isCodeAttribute(name)) scanSigilReferences(value, valueIn, emit);
|
|
11985
|
+
else scanInterpolations(value, valueIn, emit, options);
|
|
11986
|
+
}
|
|
11987
|
+
else if (token.type === "macro" && !token.isClose) {
|
|
11988
|
+
scanArgs(token, parametersOf(token.name), at, emit, options);
|
|
11989
|
+
if (token.selectorsStart !== void 0 && token.selectorsEnd !== void 0) {
|
|
11990
|
+
const from = token.selectorsStart;
|
|
11991
|
+
scanInterpolations(content.slice(from, token.selectorsEnd), (i) => at(from + i), emit, {
|
|
11992
|
+
...options,
|
|
11993
|
+
storeVarMacros: NO_STORE_VAR_MACROS
|
|
11994
|
+
});
|
|
11995
|
+
}
|
|
11996
|
+
if (storeVarMacros.has(token.name.toLowerCase())) {
|
|
11997
|
+
const lead = token.rawArgs.length - token.rawArgs.trimStart().length;
|
|
11998
|
+
const first = token.rawArgs.trim().split(/\s+/)[0] ?? "";
|
|
11999
|
+
const quoted = QUOTED_VAR_ARG_RE.exec(first);
|
|
12000
|
+
if (quoted) {
|
|
12001
|
+
const [name, ...path] = quoted[1].split(".");
|
|
12002
|
+
const start = token.argsStart + lead + 1;
|
|
12003
|
+
emit({
|
|
12004
|
+
sigil: "$",
|
|
12005
|
+
name,
|
|
12006
|
+
path,
|
|
12007
|
+
start: at(start),
|
|
12008
|
+
end: at(start + 1 + quoted[1].length)
|
|
12009
|
+
});
|
|
12010
|
+
} else if (!/^["'`]/.test(first)) scanCode(first, (i) => at(token.argsStart + lead + i), emit);
|
|
12011
|
+
}
|
|
12012
|
+
if (token.name.toLowerCase() === "do") {
|
|
12013
|
+
let close = t + 1;
|
|
12014
|
+
while (close < tokens.length) {
|
|
12015
|
+
const c = tokens[close];
|
|
12016
|
+
if (c.type === "macro" && c.isClose && c.name.toLowerCase() === "do") break;
|
|
12017
|
+
close++;
|
|
12018
|
+
}
|
|
12019
|
+
if (close < tokens.length) {
|
|
12020
|
+
scanCode(content.slice(token.end, tokens[close].start), (i) => at(token.end + i), emit, "statements");
|
|
12021
|
+
t = close;
|
|
12022
|
+
}
|
|
12023
|
+
}
|
|
12024
|
+
}
|
|
12025
|
+
}
|
|
12026
|
+
}
|
|
12027
|
+
/**
|
|
12028
|
+
* The `$` and `%` variable references a passage evaluates at runtime, in
|
|
12029
|
+
* source order: `{$var}` displays, `{$expr}` expressions, macro arguments and
|
|
12030
|
+
* `{do}` bodies (as code), quoted variable names bound by input macros, and
|
|
12031
|
+
* `{$…}` interpolations in labels and HTML attributes. Prose is literal text
|
|
12032
|
+
* and not scanned.
|
|
12033
|
+
*/
|
|
12034
|
+
function collectVariableReferences(content, options) {
|
|
12035
|
+
const found = [];
|
|
12036
|
+
withParseCache(() => collectTokenRefs(content, tokensOf(content, false, options), (i) => i, (ref) => found.push(ref), options));
|
|
12037
|
+
return found;
|
|
12038
|
+
}
|
|
12039
|
+
/**
|
|
12040
|
+
* The invalid variable references of the passages, against what is declared,
|
|
12041
|
+
* with their positions. The passages that hold no markup (the declarations
|
|
12042
|
+
* themselves, SaveTitle) are skipped.
|
|
12043
|
+
*/
|
|
12044
|
+
function checkVariableReferences(passages, declared, options) {
|
|
12045
|
+
const diagnostics = [];
|
|
12046
|
+
for (const passage of passages) {
|
|
12047
|
+
if (NOT_MARKUP.has(passage.name)) continue;
|
|
12048
|
+
for (const ref of collectVariableReferences(passage.content, options)) {
|
|
12049
|
+
const error = checkReference(ref, declared);
|
|
12050
|
+
if (!error) continue;
|
|
12051
|
+
diagnostics.push({
|
|
12052
|
+
passage: passage.name,
|
|
12053
|
+
code: error.code,
|
|
12054
|
+
name: ref.name,
|
|
12055
|
+
...ref.path.length > 0 ? { path: ref.path } : {},
|
|
12056
|
+
start: ref.start,
|
|
12057
|
+
end: ref.end,
|
|
12058
|
+
message: error.message
|
|
12059
|
+
});
|
|
12060
|
+
}
|
|
12061
|
+
}
|
|
12062
|
+
return diagnostics;
|
|
12063
|
+
}
|
|
11721
12064
|
//#endregion
|
|
11722
12065
|
//#region src/components/macros/include-args.ts
|
|
11723
12066
|
/**
|
|
@@ -11860,5 +12203,49 @@ function passagePieces(source, macros = []) {
|
|
|
11860
12203
|
function collectStoryPassageReferences(source, macros) {
|
|
11861
12204
|
return referencesOf(passagePieces(source, macros));
|
|
11862
12205
|
}
|
|
12206
|
+
/**
|
|
12207
|
+
* The widgets the story defines, as the runtime reads them: those of
|
|
12208
|
+
* StoryInit and of the passages tagged `widget`, with their parameters,
|
|
12209
|
+
* whether their body renders `{@children}` (a block widget) and where they
|
|
12210
|
+
* are written, in source order. Half-typed definitions are reported without a
|
|
12211
|
+
* `closeStart`. The macros are those the markup may use, built-in and
|
|
12212
|
+
* user-defined (a `{@children}` in an attribute or label counts).
|
|
12213
|
+
*/
|
|
12214
|
+
function widgetDefinitions(passages, macros = []) {
|
|
12215
|
+
return widgetDefinitions$1(passages, parameterLookup([...macros]));
|
|
12216
|
+
}
|
|
12217
|
+
/** Passages tagged so hold code or styles, not markup. */
|
|
12218
|
+
var NOT_MARKUP_TAGS = ["script", "stylesheet"];
|
|
12219
|
+
/** What reading the variable references of markup depends on. */
|
|
12220
|
+
function referenceOptions(macros) {
|
|
12221
|
+
const all = [...macros];
|
|
12222
|
+
return {
|
|
12223
|
+
storeVarMacros: new Set(all.filter((m) => m.storeVar).map((m) => m.name.toLowerCase())),
|
|
12224
|
+
parametersOf: parameterLookup(all),
|
|
12225
|
+
tolerant: true
|
|
12226
|
+
};
|
|
12227
|
+
}
|
|
12228
|
+
/**
|
|
12229
|
+
* The `$` and `%` variable references that the markup of a passage evaluates,
|
|
12230
|
+
* in source order, with the dotted path of fields accessed and where each is
|
|
12231
|
+
* written (offsets into `source`, UTF-16): `{$var}` displays, code in
|
|
12232
|
+
* expressions, conditions, `{do}` bodies and macro arguments, quoted names
|
|
12233
|
+
* bound by input macros, and the markup in labels and HTML attributes. Prose
|
|
12234
|
+
* is literal text. Malformed tags are skipped, so it reads half-typed markup.
|
|
12235
|
+
* The macros are those the markup may use, built-in and user-defined.
|
|
12236
|
+
*/
|
|
12237
|
+
function variableReferences(source, macros = []) {
|
|
12238
|
+
return collectVariableReferences(source, referenceOptions(macros));
|
|
12239
|
+
}
|
|
12240
|
+
/**
|
|
12241
|
+
* The variable references of the passages' markup that are not valid against
|
|
12242
|
+
* the declarations, as the story start checks them: a variable (or, when
|
|
12243
|
+
* `transients` is given, a transient) that is not declared, and a field of a
|
|
12244
|
+
* primitive that it has no member of. Built on `variableReferences`:
|
|
12245
|
+
* tolerant of half-typed markup, and it evaluates no project code.
|
|
12246
|
+
*/
|
|
12247
|
+
function validateVariableReferences(passages, declarations, macros = []) {
|
|
12248
|
+
return checkVariableReferences([...passages].filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros));
|
|
12249
|
+
}
|
|
11863
12250
|
//#endregion
|
|
11864
|
-
export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, isBlockMacro, isSigil, lexJs, lexTemplate, pairMarkup, parseDeclarations, parseSelectors, parseStoryVariables, passagePieces, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup };
|
|
12251
|
+
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 };
|