@rohal12/spindle 0.62.8 → 0.63.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 +321 -208
- package/dist/pkg/macro-registry.js +3 -1
- package/dist/pkg/macro-registry.json +3 -1
- package/dist/pkg/story-variables.js +357 -197
- package/dist/pkg/tooling.js +1 -0
- package/package.json +1 -1
- package/src/code-check.ts +83 -36
- package/src/components/macros/Computed.tsx +5 -3
- package/src/components/macros/Cycle.tsx +1 -0
- package/src/format/format-passage.ts +37 -1
- package/src/js-lexer.ts +180 -134
- package/src/markup/ast.ts +17 -9
- package/src/markup/expansion-budget.ts +23 -0
- package/src/markup/pair.ts +20 -1
- package/src/markup/parse.ts +2 -2
- package/src/markup/render.tsx +4 -4
- package/src/markup/validate.ts +13 -0
- package/src/observe/observe.ts +8 -3
- package/src/parser.ts +2 -2
- package/src/passage-roles.ts +19 -0
- package/src/registry.ts +3 -2
- package/src/store.ts +6 -23
- package/src/story-api.ts +1 -5
- package/src/story-variables.ts +49 -44
- package/src/tooling.ts +18 -11
- package/src/widgets/ast-scanner.ts +17 -13
- package/src/widgets/widget-def.ts +3 -0
- package/types/tooling.d.ts +12 -1
|
@@ -3,6 +3,7 @@ import type { Token } from '../markup/tokens';
|
|
|
3
3
|
import { codeAndText, parameterLookup, type ParametersOf } from '../code-check';
|
|
4
4
|
import { parseMarkup, type MarkupHooks } from '../markup/parse';
|
|
5
5
|
import { getMacroRegistry, getMacroParameters } from '../registry';
|
|
6
|
+
import { MarkupExpansionBudget } from '../markup/expansion-budget';
|
|
6
7
|
|
|
7
8
|
/** The declared parameters of the macros registered so far. */
|
|
8
9
|
export const registeredParameters: ParametersOf = (name) =>
|
|
@@ -17,16 +18,19 @@ function textContainsChildren(
|
|
|
17
18
|
text: string,
|
|
18
19
|
parametersOf: ParametersOf,
|
|
19
20
|
hooks?: Partial<MarkupHooks>,
|
|
21
|
+
budget = new MarkupExpansionBudget(text.length),
|
|
20
22
|
): boolean {
|
|
21
23
|
if (!text.includes('{')) return false;
|
|
22
|
-
|
|
24
|
+
if (!budget.enter(text.length)) return false;
|
|
23
25
|
try {
|
|
24
|
-
nodes = parseMarkup(text, { text: true, hooks });
|
|
26
|
+
const nodes = parseMarkup(text, { text: true, hooks });
|
|
27
|
+
return astContainsChildren(nodes, parametersOf, hooks, budget);
|
|
25
28
|
} catch {
|
|
26
29
|
// The renderer reports the markup that does not parse
|
|
27
30
|
return false;
|
|
31
|
+
} finally {
|
|
32
|
+
budget.leave();
|
|
28
33
|
}
|
|
29
|
-
return astContainsChildren(nodes, parametersOf, hooks);
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
/**
|
|
@@ -42,11 +46,12 @@ export function tokenTextContainsChildren(
|
|
|
42
46
|
parametersOf: ParametersOf = registeredParameters,
|
|
43
47
|
src = '',
|
|
44
48
|
hooks?: Partial<MarkupHooks>,
|
|
49
|
+
budget?: MarkupExpansionBudget,
|
|
45
50
|
): boolean {
|
|
46
51
|
for (const piece of codeAndText(src, [token], parametersOf)) {
|
|
47
52
|
if (
|
|
48
53
|
piece.kind === 'text' &&
|
|
49
|
-
textContainsChildren(piece.text, parametersOf, hooks)
|
|
54
|
+
textContainsChildren(piece.text, parametersOf, hooks, budget)
|
|
50
55
|
) {
|
|
51
56
|
return true;
|
|
52
57
|
}
|
|
@@ -55,7 +60,7 @@ export function tokenTextContainsChildren(
|
|
|
55
60
|
}
|
|
56
61
|
|
|
57
62
|
/**
|
|
58
|
-
*
|
|
63
|
+
* Scan an AST node array for a VariableNode
|
|
59
64
|
* with scope 'local' and name 'children' (@children), in the content and in
|
|
60
65
|
* the attributes and labels that render markup. A nested `{widget}` is not
|
|
61
66
|
* entered: its slot belongs to the innermost widget (as widgetDefinitions
|
|
@@ -65,8 +70,11 @@ export function astContainsChildren(
|
|
|
65
70
|
nodes: ASTNode[],
|
|
66
71
|
parametersOf: ParametersOf = registeredParameters,
|
|
67
72
|
hooks?: Partial<MarkupHooks>,
|
|
73
|
+
budget?: MarkupExpansionBudget,
|
|
68
74
|
): boolean {
|
|
69
|
-
|
|
75
|
+
const pending = [...nodes];
|
|
76
|
+
while (pending.length) {
|
|
77
|
+
const node = pending.pop()!;
|
|
70
78
|
if (
|
|
71
79
|
node.type === 'variable' &&
|
|
72
80
|
node.scope === 'local' &&
|
|
@@ -96,17 +104,13 @@ export function astContainsChildren(
|
|
|
96
104
|
argsStart: 0,
|
|
97
105
|
argsEnd: 0,
|
|
98
106
|
};
|
|
99
|
-
if (
|
|
100
|
-
tokenTextContainsChildren(tag, parametersOf, '', hooks) ||
|
|
101
|
-
astContainsChildren(node.children, parametersOf, hooks)
|
|
102
|
-
) {
|
|
107
|
+
if (tokenTextContainsChildren(tag, parametersOf, '', hooks, budget)) {
|
|
103
108
|
return true;
|
|
104
109
|
}
|
|
110
|
+
for (const child of node.children) pending.push(child);
|
|
105
111
|
if (node.type === 'macro' && node.branches) {
|
|
106
112
|
for (const branch of node.branches) {
|
|
107
|
-
|
|
108
|
-
return true;
|
|
109
|
-
}
|
|
113
|
+
for (const child of branch.children) pending.push(child);
|
|
110
114
|
}
|
|
111
115
|
}
|
|
112
116
|
}
|
|
@@ -10,6 +10,7 @@ import type { MacroToken } from '../markup/tokens';
|
|
|
10
10
|
import type { ParametersOf } from '../code-check';
|
|
11
11
|
import { NameMap } from '../utils/macro-names';
|
|
12
12
|
import { registeredParameters, tokenTextContainsChildren } from './ast-scanner';
|
|
13
|
+
import { MarkupExpansionBudget } from '../markup/expansion-budget';
|
|
13
14
|
|
|
14
15
|
/** A {widget} definition's name, then its `@` parameters. */
|
|
15
16
|
export const WIDGET_PARAMETERS = [
|
|
@@ -146,6 +147,7 @@ export function widgetDefinitions(
|
|
|
146
147
|
if (passage.name !== 'StoryInit' && !passage.tags?.includes('widget')) {
|
|
147
148
|
continue;
|
|
148
149
|
}
|
|
150
|
+
const budget = new MarkupExpansionBudget(passage.content.length);
|
|
149
151
|
// The open definitions: their tags, and whether a slot was seen
|
|
150
152
|
const open: {
|
|
151
153
|
token: MacroToken;
|
|
@@ -172,6 +174,7 @@ export function widgetDefinitions(
|
|
|
172
174
|
parametersOf,
|
|
173
175
|
passage.content,
|
|
174
176
|
hooks,
|
|
177
|
+
budget,
|
|
175
178
|
))
|
|
176
179
|
) {
|
|
177
180
|
open[open.length - 1]!.isBlock = true;
|
package/types/tooling.d.ts
CHANGED
|
@@ -171,6 +171,7 @@ export interface MarkupDiagnostic {
|
|
|
171
171
|
* | --- | --- |
|
|
172
172
|
* | `unknown-macro` | `name`, `suggestions` (the closest known macro, if close) |
|
|
173
173
|
* | `unknown-passage` | `name`, `macro` (`link` for `[[…]]`), `suggestions` |
|
|
174
|
+
* | `special-passage` | `name`, `macro` |
|
|
174
175
|
* | `unquoted-passage-name` | `name`, `macro` |
|
|
175
176
|
* | `argument-error` | `macro` |
|
|
176
177
|
* | `code-syntax` | `macro`, for a macro argument |
|
|
@@ -181,6 +182,7 @@ export type MarkupDiagnosticCode =
|
|
|
181
182
|
| 'argument-error'
|
|
182
183
|
| 'code-syntax'
|
|
183
184
|
| 'unknown-passage'
|
|
185
|
+
| 'special-passage'
|
|
184
186
|
| 'unquoted-passage-name';
|
|
185
187
|
|
|
186
188
|
/** What a diagnostic names, by code (see {@link MarkupDiagnosticCode}). */
|
|
@@ -887,6 +889,8 @@ export interface CodePiece extends PieceBase {
|
|
|
887
889
|
export interface PassagePiece extends PieceBase {
|
|
888
890
|
kind: 'passage';
|
|
889
891
|
name: string;
|
|
892
|
+
/** A known navigation target, rather than included/dialog content. */
|
|
893
|
+
navigation?: true;
|
|
890
894
|
/** The markup it is in, for an error: `[[Go->Hall]]`. */
|
|
891
895
|
label: string;
|
|
892
896
|
/** How much of the markup is the name, as written (quotes included). */
|
|
@@ -955,7 +959,11 @@ export declare function passagePieces(
|
|
|
955
959
|
|
|
956
960
|
/** What is wrong with the pairing of tags (a subset of {@link MarkupErrorCode}). */
|
|
957
961
|
export type PairingErrorCode =
|
|
958
|
-
'unclosed-block'
|
|
962
|
+
| 'unclosed-block'
|
|
963
|
+
| 'mismatched-closer'
|
|
964
|
+
| 'stray-closer'
|
|
965
|
+
| 'misplaced-branch'
|
|
966
|
+
| 'nesting-limit';
|
|
959
967
|
|
|
960
968
|
/** A problem in the pairing of the tokens. */
|
|
961
969
|
export interface PairingError {
|
|
@@ -1046,6 +1054,9 @@ export declare function pairMarkup(
|
|
|
1046
1054
|
*/
|
|
1047
1055
|
export declare function isBlockMacro(name: string): boolean;
|
|
1048
1056
|
|
|
1057
|
+
/** Whether a case-sensitive passage name is reserved and cannot be navigated to. */
|
|
1058
|
+
export declare function isSpecialPassage(name: string): boolean;
|
|
1059
|
+
|
|
1049
1060
|
// ---------------------------------------------------------------------------
|
|
1050
1061
|
// Declarations
|
|
1051
1062
|
// ---------------------------------------------------------------------------
|