@rohal12/spindle 0.62.9 → 0.64.0
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 +365 -191
- package/dist/pkg/macro-registry.js +4 -1
- package/dist/pkg/macro-registry.json +4 -1
- package/dist/pkg/story-variables.js +447 -179
- package/dist/pkg/tooling.js +2 -0
- package/package.json +1 -1
- package/src/code-check.ts +162 -45
- package/src/completion-context.ts +4 -4
- package/src/components/macros/Cycle.tsx +2 -1
- package/src/components/macros/If.tsx +1 -0
- package/src/components/macros/Listbox.tsx +2 -1
- package/src/components/macros/option-clauses.ts +20 -0
- package/src/components/macros/option-utils.ts +3 -2
- package/src/js-lexer.ts +154 -134
- package/src/markup/ast.ts +22 -9
- package/src/markup/expansion-budget.ts +23 -0
- package/src/markup/pair.ts +6 -4
- package/src/markup/parse.ts +2 -2
- package/src/markup/render.tsx +23 -15
- package/src/markup/validate.ts +13 -0
- package/src/observe/observe.ts +8 -3
- package/src/passage-roles.ts +19 -0
- package/src/registry.ts +33 -13
- package/src/store.ts +6 -23
- package/src/story-variables.ts +48 -15
- package/src/tooling.ts +120 -16
- package/src/widgets/ast-scanner.ts +17 -13
- package/src/widgets/widget-def.ts +3 -0
- package/types/tooling.d.ts +27 -0
|
@@ -3636,6 +3636,18 @@ function peg$parse(input, options) {
|
|
|
3636
3636
|
if (peg$success) return peg$result;
|
|
3637
3637
|
else peg$throw();
|
|
3638
3638
|
}
|
|
3639
|
+
//#endregion
|
|
3640
|
+
//#region src/components/macros/option-clauses.ts
|
|
3641
|
+
/** The direct value clauses read by the built-in choice controls. */
|
|
3642
|
+
var OPTION_CLAUSE = "option";
|
|
3643
|
+
function isOptionClause(name) {
|
|
3644
|
+
return name.toLowerCase() === OPTION_CLAUSE;
|
|
3645
|
+
}
|
|
3646
|
+
/** Replacements render their own children and do not inherit this contract. */
|
|
3647
|
+
function consumesOptionClauses(macro) {
|
|
3648
|
+
const name = macro.name.toLowerCase();
|
|
3649
|
+
return macro.source === "builtin" && !macro.widget && (name === "listbox" || name === "cycle");
|
|
3650
|
+
}
|
|
3639
3651
|
new NameMap();
|
|
3640
3652
|
new NameMap();
|
|
3641
3653
|
new NameSet();
|
|
@@ -3715,10 +3727,30 @@ function parameterError(macro, param, problem, fix) {
|
|
|
3715
3727
|
var metadataRegistry = new NameMap();
|
|
3716
3728
|
/** Indexed at registration, so parsing each tag does not scan every macro. */
|
|
3717
3729
|
var companionParents = new NameMap();
|
|
3730
|
+
/** Share index construction between live registrations and stateless tooling. */
|
|
3731
|
+
function indexCompanionParents(index, macro) {
|
|
3732
|
+
const name = macro.name.toLowerCase();
|
|
3733
|
+
for (const sub of macro.subMacros) {
|
|
3734
|
+
const parents = index.get(sub) ?? /* @__PURE__ */ new Set();
|
|
3735
|
+
parents.add(name);
|
|
3736
|
+
index.set(sub, parents);
|
|
3737
|
+
}
|
|
3738
|
+
}
|
|
3718
3739
|
/** The parents declaring a branching companion (input options are values). */
|
|
3719
3740
|
function branchParents(name, macros) {
|
|
3720
|
-
if (!macros) return [...companionParents.get(name) ?? []].filter((parent) => parent
|
|
3721
|
-
return
|
|
3741
|
+
if (!macros) return [...companionParents.get(name) ?? []].filter((parent) => !consumesOptionClauses(metadataRegistry.get(parent)));
|
|
3742
|
+
return [...branchParentLookup(macros)(name)];
|
|
3743
|
+
}
|
|
3744
|
+
/** Build once per effective metadata snapshot, then look up each token. */
|
|
3745
|
+
function branchParentLookup(macros) {
|
|
3746
|
+
const parents = new NameMap();
|
|
3747
|
+
for (const macro of effectiveNamedDefinitions(macros)) {
|
|
3748
|
+
if (consumesOptionClauses(macro)) continue;
|
|
3749
|
+
indexCompanionParents(parents, macro);
|
|
3750
|
+
}
|
|
3751
|
+
const index = new NameMap();
|
|
3752
|
+
for (const [sub, names] of parents) index.set(sub, [...names]);
|
|
3753
|
+
return (name) => index.get(name) ?? [];
|
|
3722
3754
|
}
|
|
3723
3755
|
/** The declared parameters of the macro `name`, if it declares any. */
|
|
3724
3756
|
function getMacroParameters(name) {
|
|
@@ -3753,14 +3785,16 @@ var BLOCK_MACROS = new NameSet([
|
|
|
3753
3785
|
]);
|
|
3754
3786
|
/**
|
|
3755
3787
|
* The block widgets (those whose body renders `{@children}`), kept apart from
|
|
3756
|
-
*
|
|
3757
|
-
* definition is, whereas the macros in BLOCK_MACROS stay blocks.
|
|
3788
|
+
* built-in defaults: a widget is a block only while its latest definition is.
|
|
3758
3789
|
*/
|
|
3759
3790
|
var BLOCK_WIDGETS = new NameSet();
|
|
3760
3791
|
/** All widgets, including inline ones, override built-in parsing semantics. */
|
|
3761
3792
|
var WIDGETS = new NameSet();
|
|
3762
3793
|
/** Classification owned by defineMacro, independent of explicit registrations. */
|
|
3763
3794
|
var DEFINED_BLOCK_MACROS = new NameSet();
|
|
3795
|
+
var DEFINED_MACROS = new NameSet();
|
|
3796
|
+
/** Explicit registrations remain independent of macro/widget replacements. */
|
|
3797
|
+
var REGISTERED_BLOCK_MACROS = new NameSet();
|
|
3764
3798
|
/** Macros whose body is JavaScript source, kept verbatim. */
|
|
3765
3799
|
var RAW_BODY_MACROS = /* @__PURE__ */ new Set(["do"]);
|
|
3766
3800
|
/** Whether a macro's body is JavaScript, kept verbatim (`{do}`). */
|
|
@@ -3769,7 +3803,18 @@ function isRawMacro(name, widget = WIDGETS.has(name)) {
|
|
|
3769
3803
|
}
|
|
3770
3804
|
/** Whether a macro takes a body closed by `{/name}`. */
|
|
3771
3805
|
function isBlockMacro(name) {
|
|
3772
|
-
|
|
3806
|
+
if (REGISTERED_BLOCK_MACROS.has(name)) return true;
|
|
3807
|
+
if (WIDGETS.has(name)) return BLOCK_WIDGETS.has(name);
|
|
3808
|
+
if (DEFINED_MACROS.has(name)) return DEFINED_BLOCK_MACROS.has(name);
|
|
3809
|
+
return isBuiltinBlockMacro(name);
|
|
3810
|
+
}
|
|
3811
|
+
/** Built-in defaults without any process-global registrations or widgets. */
|
|
3812
|
+
function isBuiltinBlockMacro(name) {
|
|
3813
|
+
return BLOCK_MACROS.has(name);
|
|
3814
|
+
}
|
|
3815
|
+
/** Explicit parser registrations, unaffected by effective tooling metadata. */
|
|
3816
|
+
function isRegisteredBlockMacro(name) {
|
|
3817
|
+
return REGISTERED_BLOCK_MACROS.has(name);
|
|
3773
3818
|
}
|
|
3774
3819
|
/** Macros whose branches render as one: the node holds one per branch. */
|
|
3775
3820
|
var BRANCHING = /* @__PURE__ */ new Set([
|
|
@@ -3927,9 +3972,11 @@ function pairMarkup(tokens, options = {}) {
|
|
|
3927
3972
|
const isBlock = options.isBlock ?? isBlockMacro;
|
|
3928
3973
|
const isRaw = options.isRaw ?? isRawMacro;
|
|
3929
3974
|
const parentsOf = (name) => {
|
|
3975
|
+
if (options.branchParents) return options.branchParents(name);
|
|
3976
|
+
const registered = branchParents(name);
|
|
3930
3977
|
const lower = name.toLowerCase();
|
|
3931
3978
|
const builtin = Object.prototype.hasOwnProperty.call(BRANCH_PARENT, lower) ? BRANCH_PARENT[lower] : void 0;
|
|
3932
|
-
return builtin ? [builtin] :
|
|
3979
|
+
return builtin && getMacroParameters.source(builtin) === void 0 ? [...registered, builtin] : registered;
|
|
3933
3980
|
};
|
|
3934
3981
|
const errors = [];
|
|
3935
3982
|
const noticedAtEnd = (tokens[tokens.length - 1]?.end ?? 0) + 1;
|
|
@@ -9690,118 +9737,144 @@ function propertyName(node, src) {
|
|
|
9690
9737
|
* identifiers here are declared (a `let`, a parameter), where a sigil
|
|
9691
9738
|
* variable can't be. `shorthand`: the node is a shorthand property's value.
|
|
9692
9739
|
*/
|
|
9693
|
-
function walk(
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9740
|
+
function walk(root, src, out, binding, shorthand, access = "read") {
|
|
9741
|
+
const pending = [[
|
|
9742
|
+
root,
|
|
9743
|
+
binding,
|
|
9744
|
+
shorthand,
|
|
9745
|
+
access
|
|
9746
|
+
]];
|
|
9747
|
+
while (pending.length) {
|
|
9748
|
+
const [node, bind, short, role] = pending.pop();
|
|
9749
|
+
const children = [];
|
|
9750
|
+
visit(node, bind, short, role, children);
|
|
9751
|
+
for (let i = children.length - 1; i >= 0; i--) pending.push(children[i]);
|
|
9752
|
+
}
|
|
9753
|
+
function visit(node, binding, shorthand, access, children) {
|
|
9754
|
+
if (Array.isArray(node)) {
|
|
9755
|
+
for (const n of node) children.push([
|
|
9756
|
+
n,
|
|
9757
|
+
binding,
|
|
9758
|
+
false,
|
|
9759
|
+
access
|
|
9760
|
+
]);
|
|
9714
9761
|
return;
|
|
9715
9762
|
}
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
|
|
9740
|
-
|
|
9741
|
-
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9745
|
-
|
|
9746
|
-
|
|
9747
|
-
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
|
|
9752
|
-
|
|
9753
|
-
|
|
9754
|
-
|
|
9755
|
-
|
|
9756
|
-
|
|
9757
|
-
|
|
9758
|
-
|
|
9759
|
-
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
|
|
9763
|
-
|
|
9764
|
-
|
|
9765
|
-
|
|
9766
|
-
|
|
9767
|
-
|
|
9768
|
-
|
|
9769
|
-
|
|
9770
|
-
|
|
9771
|
-
|
|
9772
|
-
|
|
9773
|
-
|
|
9774
|
-
|
|
9775
|
-
return;
|
|
9776
|
-
|
|
9777
|
-
|
|
9778
|
-
|
|
9779
|
-
|
|
9780
|
-
|
|
9781
|
-
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
|
|
9792
|
-
|
|
9793
|
-
|
|
9794
|
-
|
|
9795
|
-
|
|
9796
|
-
|
|
9797
|
-
|
|
9798
|
-
"
|
|
9799
|
-
|
|
9800
|
-
|
|
9801
|
-
|
|
9802
|
-
|
|
9803
|
-
|
|
9804
|
-
|
|
9763
|
+
if (!isNode(node)) return;
|
|
9764
|
+
const sub = (child, bind = false, short = false, role = "read") => {
|
|
9765
|
+
children.push([
|
|
9766
|
+
child,
|
|
9767
|
+
bind,
|
|
9768
|
+
short,
|
|
9769
|
+
role
|
|
9770
|
+
]);
|
|
9771
|
+
};
|
|
9772
|
+
switch (node.type) {
|
|
9773
|
+
case "Identifier": {
|
|
9774
|
+
const sigil = sigilOf(node, src);
|
|
9775
|
+
if (!sigil) return;
|
|
9776
|
+
if (binding) throw new CodeSyntaxError(`"${node.name}" is a ${NAMESPACE_NAME[sigil[0]]} variable and can't be declared`, src, node.start);
|
|
9777
|
+
out.refs.push({
|
|
9778
|
+
sigil: sigil[0],
|
|
9779
|
+
name: sigil[1],
|
|
9780
|
+
start: node.start,
|
|
9781
|
+
end: node.end,
|
|
9782
|
+
shorthand,
|
|
9783
|
+
read: access !== "write",
|
|
9784
|
+
write: access !== "read"
|
|
9785
|
+
});
|
|
9786
|
+
return;
|
|
9787
|
+
}
|
|
9788
|
+
case "Literal":
|
|
9789
|
+
if (typeof node.value === "string") out.strings.push(src.slice(node.start + 1, node.end - 1));
|
|
9790
|
+
return;
|
|
9791
|
+
case "TemplateElement":
|
|
9792
|
+
out.strings.push(node.value.raw);
|
|
9793
|
+
return;
|
|
9794
|
+
case "MemberExpression":
|
|
9795
|
+
sub(node.object);
|
|
9796
|
+
if (node.computed) sub(node.property);
|
|
9797
|
+
else propertyName(node.property, src);
|
|
9798
|
+
return;
|
|
9799
|
+
case "Property":
|
|
9800
|
+
if (node.computed) sub(node.key);
|
|
9801
|
+
else if (!node.shorthand) propertyName(node.key, src);
|
|
9802
|
+
if (node.shorthand) {
|
|
9803
|
+
const value = node.value;
|
|
9804
|
+
if (value.type === "AssignmentPattern") {
|
|
9805
|
+
sub(value.left, binding, true, access);
|
|
9806
|
+
sub(value.right);
|
|
9807
|
+
} else sub(value, binding, true, access);
|
|
9808
|
+
} else sub(node.value, binding, false, access);
|
|
9809
|
+
return;
|
|
9810
|
+
case "MethodDefinition":
|
|
9811
|
+
case "PropertyDefinition":
|
|
9812
|
+
if (node.computed) sub(node.key);
|
|
9813
|
+
else propertyName(node.key, src);
|
|
9814
|
+
sub(node.value);
|
|
9815
|
+
return;
|
|
9816
|
+
case "LabeledStatement":
|
|
9817
|
+
sub(node.body);
|
|
9818
|
+
return;
|
|
9819
|
+
case "BreakStatement":
|
|
9820
|
+
case "ContinueStatement":
|
|
9821
|
+
case "MetaProperty":
|
|
9822
|
+
case "PrivateIdentifier": return;
|
|
9823
|
+
case "VariableDeclarator":
|
|
9824
|
+
sub(node.id, true);
|
|
9825
|
+
sub(node.init);
|
|
9826
|
+
return;
|
|
9827
|
+
case "FunctionDeclaration":
|
|
9828
|
+
case "FunctionExpression":
|
|
9829
|
+
case "ArrowFunctionExpression":
|
|
9830
|
+
sub(node.id, true);
|
|
9831
|
+
for (const p of node.params) sub(p, true);
|
|
9832
|
+
sub(node.body);
|
|
9833
|
+
return;
|
|
9834
|
+
case "ClassDeclaration":
|
|
9835
|
+
case "ClassExpression":
|
|
9836
|
+
sub(node.id, true);
|
|
9837
|
+
sub(node.superClass);
|
|
9838
|
+
sub(node.body);
|
|
9839
|
+
return;
|
|
9840
|
+
case "CatchClause":
|
|
9841
|
+
sub(node.param, true);
|
|
9842
|
+
sub(node.body);
|
|
9843
|
+
return;
|
|
9844
|
+
case "AssignmentExpression":
|
|
9845
|
+
sub(node.left, false, false, node.operator === "=" ? "write" : "readwrite");
|
|
9846
|
+
sub(node.right);
|
|
9847
|
+
return;
|
|
9848
|
+
case "UnaryExpression":
|
|
9849
|
+
sub(node.argument, false, false, node.operator === "delete" ? "write" : "read");
|
|
9850
|
+
return;
|
|
9851
|
+
case "UpdateExpression":
|
|
9852
|
+
sub(node.argument, false, false, "readwrite");
|
|
9853
|
+
return;
|
|
9854
|
+
case "ForInStatement":
|
|
9855
|
+
case "ForOfStatement":
|
|
9856
|
+
sub(node.left, false, false, "write");
|
|
9857
|
+
sub(node.right);
|
|
9858
|
+
sub(node.body);
|
|
9859
|
+
return;
|
|
9860
|
+
case "AssignmentPattern":
|
|
9861
|
+
sub(node.left, binding, false, access);
|
|
9862
|
+
sub(node.right);
|
|
9863
|
+
return;
|
|
9864
|
+
case "ObjectPattern":
|
|
9865
|
+
case "ArrayPattern":
|
|
9866
|
+
case "RestElement":
|
|
9867
|
+
for (const key of [
|
|
9868
|
+
"properties",
|
|
9869
|
+
"elements",
|
|
9870
|
+
"argument"
|
|
9871
|
+
]) sub(node[key], binding, false, access);
|
|
9872
|
+
return;
|
|
9873
|
+
default: for (const key in node) {
|
|
9874
|
+
if (key === "type" || key === "start" || key === "end") continue;
|
|
9875
|
+
const v = node[key];
|
|
9876
|
+
if (typeof v === "object" && v !== null) sub(v);
|
|
9877
|
+
}
|
|
9805
9878
|
}
|
|
9806
9879
|
}
|
|
9807
9880
|
}
|
|
@@ -10571,7 +10644,7 @@ function scanMarkupTolerant(source, options = {}, completion = false) {
|
|
|
10571
10644
|
const rest = source.slice(base);
|
|
10572
10645
|
const result = attempt(rest, base);
|
|
10573
10646
|
if (Array.isArray(result)) {
|
|
10574
|
-
tokens.push(
|
|
10647
|
+
for (const token of result) tokens.push(token);
|
|
10575
10648
|
break;
|
|
10576
10649
|
}
|
|
10577
10650
|
const at = base + result.offset;
|
|
@@ -10584,7 +10657,7 @@ function scanMarkupTolerant(source, options = {}, completion = false) {
|
|
|
10584
10657
|
cut = prefix.offset;
|
|
10585
10658
|
prefix = attempt(rest.slice(0, cut), base);
|
|
10586
10659
|
}
|
|
10587
|
-
tokens.push(
|
|
10660
|
+
for (const token of prefix) tokens.push(token);
|
|
10588
10661
|
damage.push(base + cut);
|
|
10589
10662
|
if (cut < rest.length) {
|
|
10590
10663
|
const start = base + cut;
|
|
@@ -11285,7 +11358,7 @@ function macroArgumentSpans(rawArgs, parameters) {
|
|
|
11285
11358
|
return result.sort((a, b) => a.start - b.start || b.end - a.end);
|
|
11286
11359
|
}
|
|
11287
11360
|
/** The parameters of the built-in sub-macros that take arguments. */
|
|
11288
|
-
var SUB_MACRO_PARAMETERS = /* @__PURE__ */ new Map([[
|
|
11361
|
+
var SUB_MACRO_PARAMETERS = /* @__PURE__ */ new Map([[OPTION_CLAUSE, [{
|
|
11289
11362
|
name: "value",
|
|
11290
11363
|
type: "string",
|
|
11291
11364
|
holds: "text",
|
|
@@ -11296,6 +11369,27 @@ function subMacroParameters(name) {
|
|
|
11296
11369
|
return SUB_MACRO_PARAMETERS.get(name.toLowerCase());
|
|
11297
11370
|
}
|
|
11298
11371
|
//#endregion
|
|
11372
|
+
//#region src/markup/expansion-budget.ts
|
|
11373
|
+
var _MarkupExpansionBudget;
|
|
11374
|
+
/** Shared bounds for reparsing markup inside labels, selectors and attributes. */
|
|
11375
|
+
var MarkupExpansionBudget = class MarkupExpansionBudget {
|
|
11376
|
+
constructor(sourceLength) {
|
|
11377
|
+
this.depth = 0;
|
|
11378
|
+
this.remaining = Math.max(65536, sourceLength * 8);
|
|
11379
|
+
}
|
|
11380
|
+
enter(length) {
|
|
11381
|
+
if (this.depth >= MarkupExpansionBudget.maxDepth || length > this.remaining) return false;
|
|
11382
|
+
this.remaining -= length;
|
|
11383
|
+
this.depth++;
|
|
11384
|
+
return true;
|
|
11385
|
+
}
|
|
11386
|
+
leave() {
|
|
11387
|
+
this.depth--;
|
|
11388
|
+
}
|
|
11389
|
+
};
|
|
11390
|
+
_MarkupExpansionBudget = MarkupExpansionBudget;
|
|
11391
|
+
_MarkupExpansionBudget.maxDepth = 64;
|
|
11392
|
+
//#endregion
|
|
11299
11393
|
//#region src/code-check.ts
|
|
11300
11394
|
/** While a pass runs: the code it parsed so far, by goal and source. */
|
|
11301
11395
|
var parses = null;
|
|
@@ -11354,6 +11448,30 @@ function widgetParameters(params, holds = {}) {
|
|
|
11354
11448
|
...hasOwn(holds, name) ? { holds: holds[name] } : {}
|
|
11355
11449
|
}));
|
|
11356
11450
|
}
|
|
11451
|
+
/** A consumed branch uses its parent's argument contract, not standalone metadata. */
|
|
11452
|
+
function macroArgumentLookup(tokens, parametersOf) {
|
|
11453
|
+
let owners;
|
|
11454
|
+
const parentsOf = parametersOf.pairing?.branchParents ?? branchParents;
|
|
11455
|
+
return (token) => {
|
|
11456
|
+
const name = token.name.toLowerCase();
|
|
11457
|
+
if (parentsOf(name).length > 0 && !owners) {
|
|
11458
|
+
owners = /* @__PURE__ */ new Map();
|
|
11459
|
+
const pending = [...pairMarkup(tokens, parametersOf.pairing).nodes];
|
|
11460
|
+
while (pending.length) {
|
|
11461
|
+
const node = pending.pop();
|
|
11462
|
+
if (!node.body) continue;
|
|
11463
|
+
for (const branch of node.body.branches) {
|
|
11464
|
+
if (node.token.type === "macro") owners.set(branch.tag, node.token.name.toLowerCase());
|
|
11465
|
+
for (const child of branch.children) pending.push(child);
|
|
11466
|
+
}
|
|
11467
|
+
for (const child of node.body.children) pending.push(child);
|
|
11468
|
+
}
|
|
11469
|
+
}
|
|
11470
|
+
const owner = owners?.get(token);
|
|
11471
|
+
if (owner !== void 0) return CONDITION_MACROS.has(name) && owner === BRANCH_PARENT[name] && usesBuiltinSemantics(owner, parametersOf) ? "condition" : "branch";
|
|
11472
|
+
return CONDITION_MACROS.has(name) && usesBuiltinSemantics(name, parametersOf) ? "condition" : "invocation";
|
|
11473
|
+
};
|
|
11474
|
+
}
|
|
11357
11475
|
/** Whether builtin-only interpretation still belongs to this implementation. */
|
|
11358
11476
|
function usesBuiltinSemantics(name, parametersOf) {
|
|
11359
11477
|
return parametersOf.widget?.(name) === void 0 && parametersOf.source?.(name) !== "user";
|
|
@@ -11387,10 +11505,11 @@ function withHolds(params, holds) {
|
|
|
11387
11505
|
* A widget among `macros` says what its parameters hold (see ParametersOf).
|
|
11388
11506
|
*/
|
|
11389
11507
|
function parameterLookup(macros) {
|
|
11508
|
+
const list = [...macros];
|
|
11390
11509
|
const parameters = new NameMap();
|
|
11391
11510
|
const widgets = new NameMap();
|
|
11392
11511
|
const sources = new NameMap();
|
|
11393
|
-
for (const { name, parameters: params, interpolate, widget, source } of
|
|
11512
|
+
for (const { name, parameters: params, interpolate, widget, source } of list) {
|
|
11394
11513
|
sources.set(name, source ?? "user");
|
|
11395
11514
|
if (params) parameters.set(name, withHolds(params, holdsByDefault(interpolate)));
|
|
11396
11515
|
else parameters.delete(name);
|
|
@@ -11407,6 +11526,15 @@ function parameterLookup(macros) {
|
|
|
11407
11526
|
};
|
|
11408
11527
|
if (widgets.size > 0) lookup.widget = (name) => widgets.get(name);
|
|
11409
11528
|
lookup.source = (name) => sources.get(name);
|
|
11529
|
+
const definitions = new NameMap(effectiveNamedDefinitions([...list.filter((macro) => !macro.widget), ...list.filter((macro) => macro.widget)]).map((macro) => [macro.name, macro]));
|
|
11530
|
+
lookup.pairing = {
|
|
11531
|
+
isBlock: (name) => definitions.get(name)?.block ?? isBuiltinBlockMacro(name),
|
|
11532
|
+
isRaw: (name) => isRawMacro(name, widgets.has(name)),
|
|
11533
|
+
branchParents: branchParentLookup([...definitions.values()].map((macro) => ({
|
|
11534
|
+
...macro,
|
|
11535
|
+
subMacros: [...macro.subMacros ?? []]
|
|
11536
|
+
})))
|
|
11537
|
+
};
|
|
11410
11538
|
return lookup;
|
|
11411
11539
|
}
|
|
11412
11540
|
/** What a `string` or `text` argument holds when its parameter doesn't say. */
|
|
@@ -11429,6 +11557,7 @@ function stringHolds(param) {
|
|
|
11429
11557
|
* `parametersOf` gives the declared parameters of a macro, if it has any.
|
|
11430
11558
|
*/
|
|
11431
11559
|
function* codeAndText(src, tokens, parametersOf) {
|
|
11560
|
+
const argumentRole = macroArgumentLookup(tokens, parametersOf);
|
|
11432
11561
|
const closeOfTextBody = (t, name) => {
|
|
11433
11562
|
for (let k = t + 1; k < tokens.length; k++) {
|
|
11434
11563
|
const c = tokens[k];
|
|
@@ -11446,6 +11575,7 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
11446
11575
|
offset: token.targetStart,
|
|
11447
11576
|
length: token.targetEnd - token.targetStart,
|
|
11448
11577
|
macro: "link",
|
|
11578
|
+
...usesBuiltinSemantics("link", parametersOf) && { navigation: true },
|
|
11449
11579
|
label: src.slice(token.start, token.end)
|
|
11450
11580
|
};
|
|
11451
11581
|
if (token.display.includes("{")) yield textPiece(token.display, token.displayStart, "In the label of a link: ");
|
|
@@ -11471,6 +11601,8 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
11471
11601
|
}
|
|
11472
11602
|
else if (token.type === "macro" && !token.isClose) {
|
|
11473
11603
|
const name = token.name.toLowerCase();
|
|
11604
|
+
const role = argumentRole(token);
|
|
11605
|
+
if (role === "branch") continue;
|
|
11474
11606
|
const widget = parametersOf.widget?.(name);
|
|
11475
11607
|
if (executesRawBody(name, parametersOf)) {
|
|
11476
11608
|
const close = closeOfTextBody(t, name);
|
|
@@ -11504,7 +11636,7 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
11504
11636
|
if (!args) continue;
|
|
11505
11637
|
const label = `{${token.name} ${args}}`;
|
|
11506
11638
|
const argsAt = token.argsStart;
|
|
11507
|
-
if (
|
|
11639
|
+
if (role === "condition") {
|
|
11508
11640
|
yield {
|
|
11509
11641
|
kind: "code",
|
|
11510
11642
|
code: args,
|
|
@@ -11515,7 +11647,10 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
11515
11647
|
continue;
|
|
11516
11648
|
}
|
|
11517
11649
|
const params = parametersOf(name);
|
|
11518
|
-
if (params)
|
|
11650
|
+
if (params) {
|
|
11651
|
+
const navigation = usesBuiltinSemantics(name, parametersOf) ? name === "goto" || name === "link" ? ["passage"] : name === "watch" ? ["goto"] : [] : [];
|
|
11652
|
+
yield* argPieces(args, argsAt, params, token.name, label, navigation);
|
|
11653
|
+
}
|
|
11519
11654
|
if (widget) yield* widgetPieces(args, argsAt, widget, token.name, label);
|
|
11520
11655
|
}
|
|
11521
11656
|
}
|
|
@@ -11529,37 +11664,51 @@ function* codeAndText(src, tokens, parametersOf) {
|
|
|
11529
11664
|
function* passagePiecesOf(src, tokens, parametersOf, options = {}) {
|
|
11530
11665
|
let position;
|
|
11531
11666
|
const locate = (offset) => (position ?? (position = sourcePositions(src)))(offset);
|
|
11532
|
-
yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0, locate);
|
|
11667
|
+
yield* expand(src, src, tokens, parametersOf, options, (i) => i, void 0, locate, new MarkupExpansionBudget(src.length));
|
|
11533
11668
|
}
|
|
11534
11669
|
/**
|
|
11535
11670
|
* The pieces of `tokens`, the tokens of `src`, which is the text described by
|
|
11536
11671
|
* `where` (none for `root`, the markup of the whole passage), and whose
|
|
11537
11672
|
* offsets `toRoot` turns into offsets in `root`.
|
|
11538
11673
|
*/
|
|
11539
|
-
function* expand(root, src, tokens, parametersOf, options, toRoot, where, locate) {
|
|
11674
|
+
function* expand(root, src, tokens, parametersOf, options, toRoot, where, locate, budget) {
|
|
11540
11675
|
for (const flat of codeAndText(src, tokens, parametersOf)) {
|
|
11541
11676
|
const piece = where ? nestedPiece(flat, toRoot, where) : flat;
|
|
11542
11677
|
if (flat.kind !== "text" || !flat.text.includes("{")) {
|
|
11543
11678
|
yield piece;
|
|
11544
11679
|
continue;
|
|
11545
11680
|
}
|
|
11546
|
-
const toText = (i) =>
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11552
|
-
|
|
11553
|
-
|
|
11554
|
-
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
|
|
11558
|
-
|
|
11559
|
-
|
|
11560
|
-
|
|
11561
|
-
|
|
11562
|
-
|
|
11681
|
+
const toText = (i) => pieceOffset(piece, i);
|
|
11682
|
+
if (!budget.enter(flat.text.length)) {
|
|
11683
|
+
const at = toText(0);
|
|
11684
|
+
const { line, column } = locate(at);
|
|
11685
|
+
yield {
|
|
11686
|
+
...piece,
|
|
11687
|
+
errors: [new MarkupError("Markup in labels and attributes exceeds the nesting or work limit", at, line, column, "nesting-limit", toText(flat.text.length), { limit: String(MarkupExpansionBudget.maxDepth) })]
|
|
11688
|
+
};
|
|
11689
|
+
continue;
|
|
11690
|
+
}
|
|
11691
|
+
try {
|
|
11692
|
+
const inner = analyzeMarkup(flat.text, {
|
|
11693
|
+
text: true,
|
|
11694
|
+
hooks: {
|
|
11695
|
+
...parametersOf.pairing,
|
|
11696
|
+
...options.isBlock && { isBlock: options.isBlock },
|
|
11697
|
+
isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0)
|
|
11698
|
+
}
|
|
11699
|
+
});
|
|
11700
|
+
yield {
|
|
11701
|
+
...piece,
|
|
11702
|
+
tokens: inner.tokens.map((t) => mapOffsets(t, toText)),
|
|
11703
|
+
errors: inner.errors.map((e) => {
|
|
11704
|
+
const { line, column } = locate(toText(e.offset));
|
|
11705
|
+
return new MarkupError(e.reason, toText(e.offset), line, column, e.code, toText(e.end), e.data);
|
|
11706
|
+
})
|
|
11707
|
+
};
|
|
11708
|
+
yield* expand(root, flat.text, inner.tokens, parametersOf, options, toText, flat.where, locate, budget);
|
|
11709
|
+
} finally {
|
|
11710
|
+
budget.leave();
|
|
11711
|
+
}
|
|
11563
11712
|
}
|
|
11564
11713
|
}
|
|
11565
11714
|
/** `piece`, of a text in another, with its offsets turned by `toRoot`. */
|
|
@@ -11638,7 +11787,7 @@ function escapeOffsets(raw, at, value, escapes) {
|
|
|
11638
11787
|
return escaped ? offsets : void 0;
|
|
11639
11788
|
}
|
|
11640
11789
|
/** The code and text in the arguments `args` (at `offset`) of `macro`. */
|
|
11641
|
-
function* argPieces(args, offset, params, macro, label) {
|
|
11790
|
+
function* argPieces(args, offset, params, macro, label, navigation = []) {
|
|
11642
11791
|
let values;
|
|
11643
11792
|
const spans = /* @__PURE__ */ new Map();
|
|
11644
11793
|
try {
|
|
@@ -11655,7 +11804,7 @@ function* argPieces(args, offset, params, macro, label) {
|
|
|
11655
11804
|
};
|
|
11656
11805
|
return;
|
|
11657
11806
|
}
|
|
11658
|
-
yield* valuePieces(args, offset, params, values, spans, macro, label, "quotes");
|
|
11807
|
+
yield* valuePieces(args, offset, params, values, spans, macro, label, "quotes", navigation);
|
|
11659
11808
|
}
|
|
11660
11809
|
/**
|
|
11661
11810
|
* The code and text in the arguments `args` (at `offset`) of the widget
|
|
@@ -11688,7 +11837,7 @@ function* widgetPieces(args, offset, params, macro, label) {
|
|
|
11688
11837
|
* (at `offset`), whose `spans` tell where each was written and whose strings
|
|
11689
11838
|
* are unescaped as `escapes` says.
|
|
11690
11839
|
*/
|
|
11691
|
-
function* valuePieces(args, offset, params, values, spans, macro, label, escapes) {
|
|
11840
|
+
function* valuePieces(args, offset, params, values, spans, macro, label, escapes, navigation = []) {
|
|
11692
11841
|
const name = macro.toLowerCase();
|
|
11693
11842
|
/** The pieces of the parameters `list`, with their values in `from`. */
|
|
11694
11843
|
function* visit(list, from) {
|
|
@@ -11709,7 +11858,8 @@ function* valuePieces(args, offset, params, values, spans, macro, label, escapes
|
|
|
11709
11858
|
offset: offset + start,
|
|
11710
11859
|
length: end - start,
|
|
11711
11860
|
macro: name,
|
|
11712
|
-
label
|
|
11861
|
+
label,
|
|
11862
|
+
...navigation.includes(param.name) && { navigation: true }
|
|
11713
11863
|
});
|
|
11714
11864
|
const goal = codeGoal(param);
|
|
11715
11865
|
if (param.type === "passage") {
|
|
@@ -11926,11 +12076,9 @@ function completionContext(source, cursor, macros = []) {
|
|
|
11926
12076
|
const name = token.name.toLowerCase();
|
|
11927
12077
|
const args = token.rawArgs;
|
|
11928
12078
|
const widget = parametersOf.widget?.(name);
|
|
11929
|
-
|
|
11930
|
-
|
|
11931
|
-
|
|
11932
|
-
"case"
|
|
11933
|
-
].includes(name)) return codeAt(args, token.argsStart);
|
|
12079
|
+
const role = macroArgumentLookup(tokens, parametersOf)(token);
|
|
12080
|
+
if (role === "branch") return LITERAL;
|
|
12081
|
+
if (role === "condition") return codeAt(args, token.argsStart);
|
|
11934
12082
|
const stringContext = (raw, at, holds, escapes = "quotes") => {
|
|
11935
12083
|
const quoted = readQuoted(raw, 0, true);
|
|
11936
12084
|
if (!quoted) {
|
|
@@ -11987,18 +12135,19 @@ registeredParameters.source = getMacroParameters.source;
|
|
|
11987
12135
|
* Whether the text of an attribute value or macro label renders a
|
|
11988
12136
|
* `{@children}`: it is markup, parsed as the renderer parses it.
|
|
11989
12137
|
*/
|
|
11990
|
-
function textContainsChildren(text, parametersOf, hooks) {
|
|
12138
|
+
function textContainsChildren(text, parametersOf, hooks, budget = new MarkupExpansionBudget(text.length)) {
|
|
11991
12139
|
if (!text.includes("{")) return false;
|
|
11992
|
-
|
|
12140
|
+
if (!budget.enter(text.length)) return false;
|
|
11993
12141
|
try {
|
|
11994
|
-
|
|
12142
|
+
return astContainsChildren(parseMarkup(text, {
|
|
11995
12143
|
text: true,
|
|
11996
12144
|
hooks
|
|
11997
|
-
});
|
|
12145
|
+
}), parametersOf, hooks, budget);
|
|
11998
12146
|
} catch {
|
|
11999
12147
|
return false;
|
|
12148
|
+
} finally {
|
|
12149
|
+
budget.leave();
|
|
12000
12150
|
}
|
|
12001
|
-
return astContainsChildren(nodes, parametersOf, hooks);
|
|
12002
12151
|
}
|
|
12003
12152
|
/**
|
|
12004
12153
|
* Whether a tag renders a `{@children}` in an attribute value or a macro
|
|
@@ -12008,19 +12157,21 @@ function textContainsChildren(text, parametersOf, hooks) {
|
|
|
12008
12157
|
* are read from it); a token made from an AST has none. Discovery hooks
|
|
12009
12158
|
* also apply inside these texts, before widgets have been registered.
|
|
12010
12159
|
*/
|
|
12011
|
-
function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "", hooks) {
|
|
12012
|
-
for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf, hooks)) return true;
|
|
12160
|
+
function tokenTextContainsChildren(token, parametersOf = registeredParameters, src = "", hooks, budget) {
|
|
12161
|
+
for (const piece of codeAndText(src, [token], parametersOf)) if (piece.kind === "text" && textContainsChildren(piece.text, parametersOf, hooks, budget)) return true;
|
|
12013
12162
|
return false;
|
|
12014
12163
|
}
|
|
12015
12164
|
/**
|
|
12016
|
-
*
|
|
12165
|
+
* Scan an AST node array for a VariableNode
|
|
12017
12166
|
* with scope 'local' and name 'children' (@children), in the content and in
|
|
12018
12167
|
* the attributes and labels that render markup. A nested `{widget}` is not
|
|
12019
12168
|
* entered: its slot belongs to the innermost widget (as widgetDefinitions
|
|
12020
12169
|
* reads it), and a definition renders nothing of its own.
|
|
12021
12170
|
*/
|
|
12022
|
-
function astContainsChildren(nodes, parametersOf = registeredParameters, hooks) {
|
|
12023
|
-
|
|
12171
|
+
function astContainsChildren(nodes, parametersOf = registeredParameters, hooks, budget) {
|
|
12172
|
+
const pending = [...nodes];
|
|
12173
|
+
while (pending.length) {
|
|
12174
|
+
const node = pending.pop();
|
|
12024
12175
|
if (node.type === "variable" && node.scope === "local" && node.name === "children") return true;
|
|
12025
12176
|
if (node.type !== "html" && node.type !== "macro") continue;
|
|
12026
12177
|
if (node.type === "macro" && node.name.toLowerCase() === "widget") continue;
|
|
@@ -12043,10 +12194,9 @@ function astContainsChildren(nodes, parametersOf = registeredParameters, hooks)
|
|
|
12043
12194
|
nameEnd: 0,
|
|
12044
12195
|
argsStart: 0,
|
|
12045
12196
|
argsEnd: 0
|
|
12046
|
-
}, parametersOf, "", hooks
|
|
12047
|
-
|
|
12048
|
-
|
|
12049
|
-
}
|
|
12197
|
+
}, parametersOf, "", hooks, budget)) return true;
|
|
12198
|
+
for (const child of node.children) pending.push(child);
|
|
12199
|
+
if (node.type === "macro" && node.branches) for (const branch of node.branches) for (const child of branch.children) pending.push(child);
|
|
12050
12200
|
}
|
|
12051
12201
|
return false;
|
|
12052
12202
|
}
|
|
@@ -12127,6 +12277,7 @@ function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
|
|
|
12127
12277
|
const hooks = { isRaw: (name) => isRawMacro(name, replacesDo || parametersOf.widget?.(name) !== void 0) };
|
|
12128
12278
|
for (const passage of list) {
|
|
12129
12279
|
if (passage.name !== "StoryInit" && !passage.tags?.includes("widget")) continue;
|
|
12280
|
+
const budget = new MarkupExpansionBudget(passage.content.length);
|
|
12130
12281
|
const open = [];
|
|
12131
12282
|
const done = [];
|
|
12132
12283
|
for (const token of tokenizeMarkupTolerant$1(passage.content, { hooks }).tokens) if (token.type === "macro" && token.name.toLowerCase() === "widget") {
|
|
@@ -12141,7 +12292,7 @@ function widgetDefinitions$1(passages, parametersOf = registeredParameters) {
|
|
|
12141
12292
|
closeStart: token.start
|
|
12142
12293
|
});
|
|
12143
12294
|
}
|
|
12144
|
-
} else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content, hooks))) open[open.length - 1].isBlock = true;
|
|
12295
|
+
} else if (open.length > 0 && (token.type === "variable" && token.scope === "local" && token.name === "children" || tokenTextContainsChildren(token, parametersOf, passage.content, hooks, budget))) open[open.length - 1].isBlock = true;
|
|
12145
12296
|
done.push(...open);
|
|
12146
12297
|
const defs = [];
|
|
12147
12298
|
for (const { token, isBlock, closeStart } of done) try {
|
|
@@ -12178,6 +12329,26 @@ function effectiveWidgetDefinitions(definitions) {
|
|
|
12178
12329
|
return [...effective.values()];
|
|
12179
12330
|
}
|
|
12180
12331
|
//#endregion
|
|
12332
|
+
//#region src/passage-roles.ts
|
|
12333
|
+
/** Runtime-owned passage roles, shared with stateless authoring tools. */
|
|
12334
|
+
var SPECIAL_PASSAGES = /* @__PURE__ */ new Set([
|
|
12335
|
+
"StoryInit",
|
|
12336
|
+
"StoryInterface",
|
|
12337
|
+
"StoryVariables",
|
|
12338
|
+
"StoryTransients",
|
|
12339
|
+
"StoryLoading",
|
|
12340
|
+
"SaveTitle",
|
|
12341
|
+
"PassageReady",
|
|
12342
|
+
"PassageHeader",
|
|
12343
|
+
"PassageFooter",
|
|
12344
|
+
"PassageDone",
|
|
12345
|
+
"StoryContext"
|
|
12346
|
+
]);
|
|
12347
|
+
/** Whether `name` is a special passage, which navigation never goes to. */
|
|
12348
|
+
function isSpecialPassage(name) {
|
|
12349
|
+
return SPECIAL_PASSAGES.has(name);
|
|
12350
|
+
}
|
|
12351
|
+
//#endregion
|
|
12181
12352
|
//#region src/markup/validate.ts
|
|
12182
12353
|
/**
|
|
12183
12354
|
* Markup validation: parse every passage when the story starts and report
|
|
@@ -12361,6 +12532,13 @@ function validateMarkup(passages, options) {
|
|
|
12361
12532
|
report(passage, at, at + piece.length, "argument-error", `${where}${piece.message} in ${piece.label}`, { macro: piece.macro });
|
|
12362
12533
|
break;
|
|
12363
12534
|
case "passage":
|
|
12535
|
+
if (piece.navigation && isSpecialPassage(piece.name)) {
|
|
12536
|
+
report(passage, at, at + piece.length, "special-passage", `${where}Cannot navigate to special passage ${JSON.stringify(piece.name)} in ${piece.label}.`, {
|
|
12537
|
+
name: piece.name,
|
|
12538
|
+
macro: piece.macro
|
|
12539
|
+
});
|
|
12540
|
+
break;
|
|
12541
|
+
}
|
|
12364
12542
|
if (options.checkPassageNames !== false && !passageNames.has(piece.name)) {
|
|
12365
12543
|
const best = closestName(piece.name, passageNames);
|
|
12366
12544
|
report(passage, at, at + piece.length, "unknown-passage", `${where}No passage named ${JSON.stringify(piece.name)} in ${piece.label}.${didYouMean(best, JSON.stringify)}`, {
|
|
@@ -13097,7 +13275,15 @@ function scanSigilReferences(value, at, emit) {
|
|
|
13097
13275
|
*/
|
|
13098
13276
|
function scanInterpolations(text, at, emit, options) {
|
|
13099
13277
|
if (!text.includes("{")) return;
|
|
13100
|
-
|
|
13278
|
+
const budget = options.expansionBudget;
|
|
13279
|
+
if (!budget.enter(text.length)) return;
|
|
13280
|
+
try {
|
|
13281
|
+
const offset = at(0);
|
|
13282
|
+
const sourceOffsets = at(text.length) - offset === text.length ? void 0 : Array.from({ length: text.length + 1 }, (_, i) => at(i));
|
|
13283
|
+
collectTokenRefs(text, tokensOf(text, true, options), (i) => sourceOffsets?.[i] ?? offset + i, emit, options);
|
|
13284
|
+
} finally {
|
|
13285
|
+
budget.leave();
|
|
13286
|
+
}
|
|
13101
13287
|
}
|
|
13102
13288
|
/**
|
|
13103
13289
|
* Report `$var` references in JavaScript code, lexed as the expression
|
|
@@ -13224,6 +13410,7 @@ function boundReference(token, at, all) {
|
|
|
13224
13410
|
/** Report the `$var` references in the tokens of `content`. */
|
|
13225
13411
|
function collectTokenRefs(content, tokens, at, emit, options) {
|
|
13226
13412
|
const { storeVarMacros, parametersOf } = options;
|
|
13413
|
+
const argumentRole = macroArgumentLookup(tokens, parametersOf);
|
|
13227
13414
|
for (let t = 0; t < tokens.length; t++) {
|
|
13228
13415
|
const token = tokens[t];
|
|
13229
13416
|
if (options.all && token.type !== "macro" && token.type !== "html" && token.type !== "text") scanSelectors(content, token, at, emit, options);
|
|
@@ -13249,13 +13436,15 @@ function collectTokenRefs(content, tokens, at, emit, options) {
|
|
|
13249
13436
|
else scanInterpolations(value, valueIn, emit, options);
|
|
13250
13437
|
}
|
|
13251
13438
|
else if (token.type === "macro" && !token.isClose) {
|
|
13252
|
-
const
|
|
13253
|
-
|
|
13439
|
+
const role = argumentRole(token);
|
|
13440
|
+
const binding = role === "invocation" && storeVarMacros.has(token.name.toLowerCase()) && !parametersOf.widget?.(token.name) ? boundReference(token, at, options.all) : void 0;
|
|
13441
|
+
if (role === "condition") scanCode(token.rawArgs, (i) => at(token.argsStart + i), emit);
|
|
13442
|
+
else if (role === "invocation") scanArgs(token, parametersOf, at, (ref) => {
|
|
13254
13443
|
if (!binding || ref.start < binding.start || ref.start >= binding.end) emit(ref);
|
|
13255
13444
|
}, options);
|
|
13256
13445
|
scanSelectors(content, token, at, emit, options);
|
|
13257
13446
|
if (binding) emit(binding);
|
|
13258
|
-
if (executesRawBody(token.name, parametersOf)) {
|
|
13447
|
+
if (role === "invocation" && executesRawBody(token.name, parametersOf)) {
|
|
13259
13448
|
let close = t + 1;
|
|
13260
13449
|
while (close < tokens.length) {
|
|
13261
13450
|
const c = tokens[close];
|
|
@@ -13279,7 +13468,10 @@ function collectTokenRefs(content, tokens, at, emit, options) {
|
|
|
13279
13468
|
*/
|
|
13280
13469
|
function collectVariableReferences(content, options) {
|
|
13281
13470
|
const found = [];
|
|
13282
|
-
withParseCache(() => collectTokenRefs(content, tokensOf(content, false, options), (i) => i, (ref) => found.push(ref),
|
|
13471
|
+
withParseCache(() => collectTokenRefs(content, tokensOf(content, false, options), (i) => i, (ref) => found.push(ref), {
|
|
13472
|
+
...options,
|
|
13473
|
+
expansionBudget: new MarkupExpansionBudget(content.length)
|
|
13474
|
+
}));
|
|
13283
13475
|
return found.sort((a, b) => a.start - b.start);
|
|
13284
13476
|
}
|
|
13285
13477
|
/**
|
|
@@ -25849,7 +26041,7 @@ function tokenizationOptions(options) {
|
|
|
25849
26041
|
hooks: {
|
|
25850
26042
|
isRaw: (name) => isRawMacro(name, parametersOf.widget?.(name) !== void 0),
|
|
25851
26043
|
isBlock: blockLookup(macros),
|
|
25852
|
-
branchParents: (
|
|
26044
|
+
branchParents: branchParentLookup(macros),
|
|
25853
26045
|
...options.hooks
|
|
25854
26046
|
}
|
|
25855
26047
|
};
|
|
@@ -25873,20 +26065,24 @@ function validateStoryMarkup(passages, macros, options = {}) {
|
|
|
25873
26065
|
const all = effectiveToolingMacros(macros);
|
|
25874
26066
|
const known = /* @__PURE__ */ new Set();
|
|
25875
26067
|
const widgets = effectiveWidgetDefinitions(widgetDefinitions$1(list, parameterLookup(all)));
|
|
25876
|
-
const
|
|
26068
|
+
const effective = effectiveToolingMacros([...all, ...widgets.map((widget) => ({
|
|
26069
|
+
name: widget.name,
|
|
26070
|
+
block: widget.block,
|
|
26071
|
+
subMacros: [],
|
|
26072
|
+
widget
|
|
26073
|
+
}))]);
|
|
25877
26074
|
const parametersOf = parameterLookup([...all, ...definedWidgetMacros(widgets)]);
|
|
25878
26075
|
for (const macro of all) {
|
|
25879
26076
|
const name = macro.name.toLowerCase();
|
|
25880
26077
|
known.add(name);
|
|
25881
26078
|
for (const sub of macro.subMacros) known.add(sub.toLowerCase());
|
|
25882
|
-
if (macro.block) blocks.add(name);
|
|
25883
26079
|
}
|
|
25884
26080
|
return validateMarkup(list, {
|
|
25885
|
-
branchParents: (
|
|
26081
|
+
branchParents: branchParentLookup(effective),
|
|
25886
26082
|
isKnownMacro: (name) => known.has(name),
|
|
25887
26083
|
macroNames: known,
|
|
25888
26084
|
parametersOf,
|
|
25889
|
-
isBlockMacro: (
|
|
26085
|
+
isBlockMacro: blockLookup(effective),
|
|
25890
26086
|
checkPassageNames: options.checkPassageNames,
|
|
25891
26087
|
tolerant: options.tolerant
|
|
25892
26088
|
});
|
|
@@ -25899,9 +26095,81 @@ function definedWidgetMacros(widgets) {
|
|
|
25899
26095
|
}));
|
|
25900
26096
|
}
|
|
25901
26097
|
/** Whether a macro takes a body, among `macros` and the built-in ones. */
|
|
25902
|
-
function blockLookup(macros) {
|
|
25903
|
-
const
|
|
25904
|
-
|
|
26098
|
+
function blockLookup(macros, includeRuntime = true) {
|
|
26099
|
+
const definitions = new NameMap();
|
|
26100
|
+
for (const macro of effectiveToolingMacros(macros)) definitions.set(macro.name, macro.block);
|
|
26101
|
+
return (name) => includeRuntime && isRegisteredBlockMacro(name) || (definitions.get(name) ?? (includeRuntime ? isBlockMacro(name) : isBuiltinBlockMacro(name)));
|
|
26102
|
+
}
|
|
26103
|
+
/**
|
|
26104
|
+
* Classify heads against explicit effective metadata, without running code.
|
|
26105
|
+
* Labels and attributes are separate markup scopes and never inherit a
|
|
26106
|
+
* surrounding control's clause ownership. This describes dispatch, not
|
|
26107
|
+
* whether a conditional body will execute.
|
|
26108
|
+
*/
|
|
26109
|
+
function macroCalls(source, macros = []) {
|
|
26110
|
+
const all = effectiveToolingMacros(macros);
|
|
26111
|
+
const definitions = new NameMap(all.map((macro) => [macro.name, macro]));
|
|
26112
|
+
const parametersOf = parameterLookup(all);
|
|
26113
|
+
const options = tokenizationOptions({
|
|
26114
|
+
macros: all,
|
|
26115
|
+
hooks: { isBlock: blockLookup(all, false) }
|
|
26116
|
+
});
|
|
26117
|
+
const hooks = options.hooks;
|
|
26118
|
+
const tokens = tokenizeMarkupTolerant$1(source, options).tokens;
|
|
26119
|
+
const calls = [];
|
|
26120
|
+
const classify = (tokens) => {
|
|
26121
|
+
const found = /* @__PURE__ */ new Map();
|
|
26122
|
+
const pending = pairMarkup(tokens, hooks).nodes.map((node) => ({ node }));
|
|
26123
|
+
while (pending.length) {
|
|
26124
|
+
const { node, parent } = pending.pop();
|
|
26125
|
+
const token = node.token;
|
|
26126
|
+
if (token.type === "macro") {
|
|
26127
|
+
const definition = parent && definitions.get(parent.name);
|
|
26128
|
+
const value = definition && consumesOptionClauses(definition) && isOptionClause(token.name);
|
|
26129
|
+
found.set(token, {
|
|
26130
|
+
token,
|
|
26131
|
+
kind: value ? "value" : "invocation",
|
|
26132
|
+
...value && { owner: parent }
|
|
26133
|
+
});
|
|
26134
|
+
}
|
|
26135
|
+
if (!node.body) continue;
|
|
26136
|
+
const owner = token.type === "macro" ? token : void 0;
|
|
26137
|
+
for (const child of node.body.children) pending.push({
|
|
26138
|
+
node: child,
|
|
26139
|
+
parent: owner
|
|
26140
|
+
});
|
|
26141
|
+
for (const branch of node.body.branches) {
|
|
26142
|
+
found.set(branch.tag, {
|
|
26143
|
+
token: branch.tag,
|
|
26144
|
+
kind: "branch",
|
|
26145
|
+
owner
|
|
26146
|
+
});
|
|
26147
|
+
for (const child of branch.children) pending.push({
|
|
26148
|
+
node: child,
|
|
26149
|
+
parent: owner
|
|
26150
|
+
});
|
|
26151
|
+
}
|
|
26152
|
+
}
|
|
26153
|
+
for (const token of tokens) {
|
|
26154
|
+
if (token.type !== "macro" || token.isClose) continue;
|
|
26155
|
+
const call = found.get(token) ?? {
|
|
26156
|
+
token,
|
|
26157
|
+
kind: "branch"
|
|
26158
|
+
};
|
|
26159
|
+
calls.push(call);
|
|
26160
|
+
}
|
|
26161
|
+
};
|
|
26162
|
+
classify(tokens);
|
|
26163
|
+
for (const piece of passagePiecesOf(source, tokens, parametersOf, { isBlock: hooks.isBlock })) {
|
|
26164
|
+
if (piece.kind !== "text" || !piece.tokens.length) continue;
|
|
26165
|
+
classify(piece.tokens);
|
|
26166
|
+
}
|
|
26167
|
+
let literalEnd = -1;
|
|
26168
|
+
return calls.sort((a, b) => a.token.start - b.token.start).filter((call) => {
|
|
26169
|
+
if (call.token.start < literalEnd) return false;
|
|
26170
|
+
if (call.kind === "value" || call.kind === "branch") literalEnd = call.token.argsEnd;
|
|
26171
|
+
return true;
|
|
26172
|
+
});
|
|
25905
26173
|
}
|
|
25906
26174
|
/**
|
|
25907
26175
|
* What a passage's markup runs and names, and where: the pieces of code
|
|
@@ -26000,4 +26268,4 @@ function validateVariableReferences(passages, declarations, macros = []) {
|
|
|
26000
26268
|
return checkVariableReferences(list.filter((p) => !p.tags?.some((t) => NOT_MARKUP_TAGS.includes(t))), declarations, referenceOptions(macros, false, list));
|
|
26001
26269
|
}
|
|
26002
26270
|
//#endregion
|
|
26003
|
-
export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, isBlockMacro, isSigil, lexJs, lexTemplate, macroArgumentSpans, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
|
|
26271
|
+
export { MarkupError, SIGIL_SCOPES, checkParameterTypes, collectStoryPassageReferences, completionContext, discoverMacros, effectiveWidgetDefinitions, endsWithOperator, evaluatePassageName, findCodeEnd, formatDiagnostic, formatPassage, isBlockMacro, isSigil, isSpecialPassage, lexJs, lexTemplate, macroArgumentSpans, macroCalls, pairMarkup, parseBoundVariable, parseCode, parseDeclarations, parseSelectors, parseStoryVariables, parseWidgetDef, passagePieces, passagePiecesOfTokens, passageTarget, pieceOffset, readQuoted, scanStringLiteral, splitArgs, splitIncludeFlag, splitTopLevel, stripLooseQuotes, tokenizeMarkup, tokenizeMarkupTolerant, transform, unescapeQuoted, validateStoryMarkup, validateVariableReferences, variableReferences, widgetDefinitions };
|