@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.
@@ -37,6 +37,10 @@ export {
37
37
  stripLooseQuotes,
38
38
  unescapeQuoted,
39
39
  splitIncludeFlag,
40
+ parseWidgetDef,
41
+ widgetDefinitions,
42
+ variableReferences,
43
+ validateVariableReferences,
40
44
  } from './story-variables.js';
41
45
 
42
46
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rohal12/spindle",
3
- "version": "0.59.23",
3
+ "version": "0.59.26",
4
4
  "type": "module",
5
5
  "description": "A Preact-based story format for Twine 2.",
6
6
  "license": "Unlicense",
@@ -69,40 +69,39 @@
69
69
  },
70
70
  "dependencies": {
71
71
  "acorn": "^8.19.0",
72
- "devalue": "^6",
73
- "immer": "^11.1.4",
74
- "micromark": "^4.0.2",
72
+ "devalue": "^6.0.2",
73
+ "immer": "^11.1.21",
74
+ "micromark": "^4.0.3",
75
75
  "micromark-extension-gfm-strikethrough": "^2.1.0",
76
- "micromark-extension-gfm-table": "^2.1.1",
77
- "preact": "^10.29.0",
78
- "zustand": "^5.0.12"
76
+ "micromark-extension-gfm-table": "^2.1.2",
77
+ "preact": "^11.0.1",
78
+ "zustand": "^5.0.15"
79
79
  },
80
80
  "lint-staged": {
81
81
  "*": "prettier --write --ignore-unknown"
82
82
  },
83
83
  "devDependencies": {
84
84
  "@fast-check/vitest": "^0.5.0",
85
- "@preact/preset-vite": "^2.10.5",
86
- "@rohal12/twee-ts": "^1.14.0",
87
- "@types/js-yaml": "^4.0.9",
88
- "@types/node": "^25.5.0",
89
- "@types/react": "^19.2.14",
90
- "@vitest/coverage-v8": "^4.1.2",
85
+ "@preact/preset-vite": "^2.10.6",
86
+ "@rohal12/twee-ts": "^1.18.2",
87
+ "@types/node": "^26.6.5",
88
+ "@types/react": "^19.3.0",
89
+ "@vitest/coverage-v8": "^5.0.3",
91
90
  "fake-indexeddb": "^6.2.5",
92
- "fallow": "3.31.0",
91
+ "fallow": "3.33.1",
93
92
  "fast-check": "^4.10.2",
94
- "happy-dom": "^20.8.9",
93
+ "happy-dom": "^20.14.6",
95
94
  "husky": "^9.1.7",
96
- "js-yaml": "^4.1.1",
97
- "jscpd": "5.4.0",
98
- "lint-staged": "^16.4.0",
95
+ "js-yaml": "^5.4.3",
96
+ "jscpd": "5.4.1",
97
+ "lint-staged": "^17.6.0",
99
98
  "peggy": "5.1.0",
100
- "playwright": "^1.58.2",
101
- "prettier": "^3.8.1",
102
- "typescript": "^6.0.2",
103
- "vite": "^8.0.3",
104
- "vite-plugin-singlefile": "^2.3.2",
99
+ "playwright": "^1.64.0",
100
+ "prettier": "^3.9.9",
101
+ "typescript": "^7.0.2",
102
+ "vite": "^8.3.4",
103
+ "vite-plugin-singlefile": "^2.3.3",
105
104
  "vitepress": "^1.6.4",
106
- "vitest": "^4.1.2"
105
+ "vitest": "^5.0.3"
107
106
  }
108
107
  }
@@ -1,4 +1,4 @@
1
- import yaml from 'js-yaml';
1
+ import * as yaml from 'js-yaml';
2
2
  import type { AutomationScript, AutomationStep } from './types';
3
3
 
4
4
  function validateStep(step: unknown, index: number): AutomationStep {
package/src/code-check.ts CHANGED
@@ -331,17 +331,13 @@ export function* codeAndText(
331
331
  );
332
332
  continue;
333
333
  }
334
- let from = 0;
335
- for (const part of splitSigilTemplate(value)) {
336
- if (!('expr' in part)) continue;
337
- const k = locate(value, part.expr, from);
338
- from = k + part.expr.length;
334
+ for (const { expr, at: k } of sigilExpressions(value)) {
339
335
  yield {
340
336
  kind: 'code',
341
- code: part.expr,
337
+ code: expr,
342
338
  offset: at + k,
343
339
  goal: 'expression',
344
- label: `{${part.expr}} in the ${name} attribute of <${token.tag}>`,
340
+ label: `{${expr}} in the ${name} attribute of <${token.tag}>`,
345
341
  };
346
342
  }
347
343
  }
@@ -652,7 +648,7 @@ const textPiece = (text: string, offset: number, where: string): TextPiece => ({
652
648
  * value is: the first of equal names, which is the one in effect. A token
653
649
  * with no spans (made from an AST) has them found in `src`, in order.
654
650
  */
655
- function attributeValues(
651
+ export function attributeValues(
656
652
  src: string,
657
653
  token: HtmlToken,
658
654
  ): { name: string; value: string; at: number }[] {
@@ -680,11 +676,29 @@ function attributeValues(
680
676
  return values;
681
677
  }
682
678
 
679
+ /**
680
+ * The `{$…}` expressions in the value of a code attribute (`onclick`, see
681
+ * isCodeAttribute), with where each is in the value.
682
+ */
683
+ export function sigilExpressions(
684
+ value: string,
685
+ ): { expr: string; at: number }[] {
686
+ const found = [];
687
+ let from = 0;
688
+ for (const part of splitSigilTemplate(value)) {
689
+ if (!('expr' in part)) continue;
690
+ const at = locate(value, part.expr, from);
691
+ from = at + part.expr.length;
692
+ found.push({ expr: part.expr, at });
693
+ }
694
+ return found;
695
+ }
696
+
683
697
  /**
684
698
  * Index of `part` in `text` from `from` on, else anywhere, else `from`: the
685
699
  * place to report an error in `part` at.
686
700
  */
687
- function locate(text: string, part: string, from: number): number {
701
+ export function locate(text: string, part: string, from: number): number {
688
702
  const at = text.indexOf(part, from);
689
703
  if (at >= 0) return at;
690
704
  const anywhere = text.indexOf(part);
@@ -1,5 +1,11 @@
1
1
  import { createContext } from 'preact';
2
- import { useCallback, useLayoutEffect, useMemo, useRef } from 'preact/hooks';
2
+ import {
3
+ useCallback,
4
+ useId,
5
+ useLayoutEffect,
6
+ useMemo,
7
+ useRef,
8
+ } from 'preact/hooks';
3
9
  import { parseMarkup } from '../markup/parse';
4
10
  import {
5
11
  renderNodes,
@@ -20,6 +26,11 @@ interface PassageDialogProps {
20
26
  fallbackMarkup?: string;
21
27
  panelClass?: string;
22
28
  onClose: () => void;
29
+ /**
30
+ * The dialog's accessible name. Without one, the first heading authored in
31
+ * the dialog names it, or else its passage.
32
+ */
33
+ label?: string;
23
34
  /** Show the default `✕` button. Defaults to `dismissible`. */
24
35
  showCloseButton?: boolean;
25
36
  /**
@@ -35,6 +46,7 @@ export function PassageDialog({
35
46
  fallbackMarkup,
36
47
  panelClass,
37
48
  onClose,
49
+ label,
38
50
  dismissible = true,
39
51
  showCloseButton = dismissible,
40
52
  }: PassageDialogProps) {
@@ -71,6 +83,7 @@ export function PassageDialog({
71
83
  }, [markup, nobr]);
72
84
 
73
85
  const panelRef = useRef<HTMLDivElement>(null);
86
+ const labelId = useId();
74
87
  const viewScope = useViewScope();
75
88
 
76
89
  // Focus into the dialog, trap Tab, Escape to close, restore focus on close.
@@ -80,6 +93,19 @@ export function PassageDialog({
80
93
  // Be on the stack of displayed dialogs the Story dialog API works on.
81
94
  useLayoutEffect(() => registerOpenDialog(stableOnClose), [stableOnClose]);
82
95
 
96
+ // Name the dialog after its first heading when no label is given
97
+ useLayoutEffect(() => {
98
+ const panel = panelRef.current;
99
+ if (!panel || label) return;
100
+ const heading = panel.querySelector<HTMLElement>(
101
+ '.dialog-body :is(h1, h2, h3, h4, h5, h6)',
102
+ );
103
+ if (!heading) return;
104
+ heading.id ||= `${labelId}-heading`;
105
+ panel.setAttribute('aria-labelledby', heading.id);
106
+ return () => panel.removeAttribute('aria-labelledby');
107
+ }, [label, markup]);
108
+
83
109
  // Signal that the dialog's DOM is committed (once per open).
84
110
  useLayoutEffect(() => {
85
111
  if (panelRef.current) {
@@ -107,6 +133,7 @@ export function PassageDialog({
107
133
  class={cls}
108
134
  role="dialog"
109
135
  aria-modal="true"
136
+ aria-label={label ?? passageName}
110
137
  tabIndex={-1}
111
138
  >
112
139
  {showCloseButton && (
@@ -41,7 +41,7 @@ export function logMacroError(
41
41
  export function useRunOnce(macro: string, rawArgs: string, effect: () => void) {
42
42
  // Unset until the effect has run. Boxed: anything can be thrown,
43
43
  // including null and other falsy values.
44
- const failure = useRef<{ error: unknown } | null>();
44
+ const failure = useRef<{ error: unknown } | null | undefined>(undefined);
45
45
  if (failure.current === undefined) {
46
46
  failure.current = null;
47
47
  const location = currentSourceLocation();
@@ -77,6 +77,9 @@ export function defineMenubarAction(config: MenubarActionConfig) {
77
77
  passageName={config.dialog.passageName}
78
78
  fallbackMarkup={config.dialog.fallbackMarkup}
79
79
  panelClass={config.dialog.panelClass}
80
+ label={
81
+ typeof config.label === 'string' ? config.label : config.name
82
+ }
80
83
  onClose={() => setDialogOpen(false)}
81
84
  showCloseButton={config.dialog.showCloseButton}
82
85
  />
@@ -112,8 +112,8 @@ export function SaveManagerContent() {
112
112
  // Actions are async and may finish after the manager closed: once
113
113
  // unmounted, no status is shown and no timer is left behind.
114
114
  const mounted = useRef(true);
115
- const statusTimer = useRef<number>();
116
- const closeTimer = useRef<number>();
115
+ const statusTimer = useRef<number | undefined>(undefined);
116
+ const closeTimer = useRef<number | undefined>(undefined);
117
117
  const showStatus = (text: string, type: 'success' | 'error' = 'success') => {
118
118
  if (!mounted.current) return;
119
119
  clearTimeout(statusTimer.current);
@@ -1,14 +1,18 @@
1
- import { useState } from 'preact/hooks';
2
- import { settings, type SettingDef } from '../../settings';
1
+ import { useEffect, useState } from 'preact/hooks';
2
+ import { settings, subscribeSettings, type SettingDef } from '../../settings';
3
3
  import { defineMacro } from '../../define-macro';
4
4
 
5
5
  function SettingControl({ name, def }: { name: string; def: SettingDef }) {
6
6
  const [value, setValue] = useState(() => settings.get(name));
7
7
 
8
- const update = (newValue: unknown) => {
9
- setValue(newValue);
10
- settings.set(name, newValue);
11
- };
8
+ // Follow changes made elsewhere: Story.settings.set(), another view
9
+ useEffect(() => {
10
+ const sync = () => setValue(settings.get(name));
11
+ sync();
12
+ return subscribeSettings(sync);
13
+ }, [name]);
14
+
15
+ const update = (newValue: unknown) => settings.set(name, newValue);
12
16
 
13
17
  switch (def.type) {
14
18
  case 'toggle':
@@ -125,7 +125,7 @@ defineMacro({
125
125
  clipPath: clip,
126
126
  }}
127
127
  >
128
- {ctx.renderInlineNodes(children)}
128
+ {ctx.renderNodes(children, { inline: true })}
129
129
  </span>
130
130
  {!done && totalChars > 0 && <span class="macro-type-cursor" />}
131
131
  </span>
@@ -20,19 +20,67 @@ import { runWithCommittedMutations } from '../../execute-mutation';
20
20
  import { subscribeStateReplacement } from '../../store';
21
21
  import { RepeatContext } from './Repeat';
22
22
  import { DialogCloseContext } from '../PassageDialog';
23
+ import { NameSet } from '../../utils/macro-names';
23
24
  import { ItemEditContext } from '../../utils/control-edits';
24
25
 
25
26
  const frozenAlways = () => true;
26
27
 
28
+ /**
29
+ * Macros whose work is over once their effects have run: a body made of
30
+ * these alone has nothing left to wait for. Any other macro (a timer, a
31
+ * widget, an author's macro) may keep working after rendering.
32
+ */
33
+ const SETTLING_MACROS = new NameSet([
34
+ 'set',
35
+ 'unset',
36
+ 'if',
37
+ 'for',
38
+ 'switch',
39
+ 'do',
40
+ 'print',
41
+ 'goto',
42
+ 'nobr',
43
+ 'span',
44
+ ]);
45
+
46
+ /** Whether `nodes` use no macro outside SETTLING_MACROS (see above). */
47
+ function settlesAfterRender(nodes: ASTNode[]): boolean {
48
+ return nodes.every((n) => {
49
+ switch (n.type) {
50
+ case 'macro':
51
+ return (
52
+ SETTLING_MACROS.has(n.name) &&
53
+ settlesAfterRender(n.children) &&
54
+ (n.branches ?? []).every((b) => settlesAfterRender(b.children))
55
+ );
56
+ case 'html':
57
+ return settlesAfterRender(n.children);
58
+ default:
59
+ return true;
60
+ }
61
+ });
62
+ }
63
+
64
+ /** Calls `onSettled` once the effects of the content before it have run. */
65
+ function Settled({ onSettled }: { onSettled: () => void }) {
66
+ useEffect(() => {
67
+ // After the effects of the whole body, and what they render in turn
68
+ const timer = setTimeout(onSettled, 0);
69
+ return () => clearTimeout(timer);
70
+ }, []);
71
+ return null;
72
+ }
73
+
27
74
  /**
28
75
  * Return a function that runs a macro body once, outside the passage tree:
29
76
  * it renders `children` into a detached node, so the body's macros ({set},
30
77
  * {if}, {goto}, ...) fire their side effects through the normal Preact
31
78
  * pipeline. Used by {button} and {link} on click. The body's state is frozen
32
79
  * once it has rendered, so it runs once per click. It stays mounted
33
- * until the owning macro unmounts (its passage changes, say), so work it
34
- * starts in an effect, such as the timer of a {timed} or {repeat}, can
35
- * finish; the passage leaving cancels it, and so does a restart or a load
80
+ * until it has nothing left to do: a body of plain macros ({set}, {if},
81
+ * {goto}...) once its effects have run, any other (with the timer of a
82
+ * {timed} or {repeat}, say) until the owning macro unmounts, e.g. its
83
+ * passage changes, so that work it starts in an effect can finish; the passage leaving cancels it, and so does a restart or a load
36
84
  * replacing the game, which a control of the story interface outlives
37
85
  * (#401).
38
86
  *
@@ -80,6 +128,16 @@ export function useDetachedBody(): (children: ASTNode[]) => void {
80
128
  const run = (children: ASTNode[]) => {
81
129
  const locals = liveLocalsView(updater.getValues);
82
130
  const container = document.createElement('div');
131
+ // A body that settles is released once it has: it is not kept (with its
132
+ // detached nodes) for every click until the control goes away
133
+ const release = settlesAfterRender(children)
134
+ ? () => {
135
+ const at = mounted.current.indexOf(container);
136
+ if (at === -1) return;
137
+ mounted.current.splice(at, 1);
138
+ render(null, container);
139
+ }
140
+ : null;
83
141
  render(
84
142
  <FrozenStateContext.Provider value={frozenAlways}>
85
143
  <LocalsUpdateContext.Provider value={updater}>
@@ -98,6 +156,7 @@ export function useDetachedBody(): (children: ASTNode[]) => void {
98
156
  structural,
99
157
  locals,
100
158
  })}
159
+ {release && <Settled onSettled={release} />}
101
160
  </OutgoingContext.Provider>
102
161
  </ItemEditContext.Provider>
103
162
  </DialogCloseContext.Provider>
@@ -344,8 +344,7 @@ export function parseMacroArgs<const P extends readonly ParameterDef[]>(
344
344
 
345
345
  /** What a `passage` argument is: a quoted name, or an expression. */
346
346
  export type PassageTarget =
347
- | { kind: 'name'; name: string }
348
- | { kind: 'expression'; expression: string };
347
+ { kind: 'name'; name: string } | { kind: 'expression'; expression: string };
349
348
 
350
349
  /**
351
350
  * Read a `passage` argument as written (`{goto "Hall"}`, `{goto $room}`): a
@@ -340,9 +340,10 @@ export function routeStoreUpdate<S extends VariableNamespaces>(
340
340
  const changes = NAMESPACES.flatMap((ns) => {
341
341
  const own = patches.filter((p) => p.path[0] === ns);
342
342
  return own.length
343
- ? writtenPaths(view[ns], next[ns], own).map(
344
- (change): PathChange => ({ ...change, path: [ns, ...change.path] }),
345
- )
343
+ ? writtenPaths(view[ns], next[ns], own).map((change): PathChange => ({
344
+ ...change,
345
+ path: [ns, ...change.path],
346
+ }))
346
347
  : [];
347
348
  });
348
349
  // Each target takes its own copies, which share what the written values do,
@@ -147,8 +147,35 @@ const openModals: ModalEntry[] = [];
147
147
  * - closes the topmost dialog on Escape when it is dismissible;
148
148
  * - returns focus to the previously focused element on close.
149
149
  */
150
+ /** The input types made of several segments, each a native Tab stop. */
151
+ const SEGMENTED_INPUTS = new Set([
152
+ 'date',
153
+ 'time',
154
+ 'datetime-local',
155
+ 'month',
156
+ 'week',
157
+ ]);
158
+
159
+ /** Whether the element has native tab stops inside it, in its shadow tree. */
160
+ function hasNativeStops(el: Element | null): el is HTMLElement {
161
+ if (el instanceof HTMLMediaElement) return el.controls;
162
+ return (
163
+ el instanceof HTMLInputElement &&
164
+ SEGMENTED_INPUTS.has(el.type) &&
165
+ !el.readOnly
166
+ );
167
+ }
168
+
169
+ /** The tab stops of an embedded document, in tab order. */
170
+ function frameStops(doc: Document | null): HTMLElement[] {
171
+ if (!doc) return [];
172
+ return Array.from(doc.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(
173
+ (el) => isAvailable(el) && isTabStop(el),
174
+ );
175
+ }
176
+
150
177
  export function useModalFocus(
151
- panelRef: RefObject<HTMLElement>,
178
+ panelRef: RefObject<HTMLElement | null>,
152
179
  bodySelector: string,
153
180
  dismissible: boolean,
154
181
  onClose: () => void,
@@ -200,6 +227,24 @@ export function useModalFocus(
200
227
  * (#424). `from` may be an element of an embedded document, whose frame
201
228
  * element then stands in for it.
202
229
  */
230
+ /** Focus `el`; a frame is entered at its first (or last) control (#460). */
231
+ const enter = (el: HTMLElement, backwards: boolean) => {
232
+ if (el instanceof HTMLIFrameElement) {
233
+ let inner: HTMLElement[] = [];
234
+ try {
235
+ inner = frameStops(el.contentDocument);
236
+ } catch {
237
+ // Not accessible: the frame itself takes focus
238
+ }
239
+ const edge = backwards ? inner[inner.length - 1] : inner[0];
240
+ if (edge) {
241
+ edge.focus();
242
+ return;
243
+ }
244
+ }
245
+ el.focus();
246
+ };
247
+
203
248
  const moveFocus = (from: Element | null, backwards: boolean) => {
204
249
  const items = focusables(panel);
205
250
  const first = items[0];
@@ -224,12 +269,12 @@ export function useModalFocus(
224
269
  } else {
225
270
  next = backwards ? last : first;
226
271
  }
227
- (next ?? (backwards ? last : first)).focus();
272
+ enter(next ?? (backwards ? last : first), backwards);
228
273
  };
229
274
 
230
- // The media element whose native controls Tab is stepping through
231
- let steppingMedia: { el: HTMLMediaElement; backwards: boolean } | null =
232
- null;
275
+ // The element whose native inner controls (a media element's, a date
276
+ // input's segments) Tab is stepping through
277
+ let steppingNative: { el: HTMLElement; backwards: boolean } | null = null;
233
278
 
234
279
  const onKeyDown = (e: KeyboardEvent) => {
235
280
  if (!top()) return;
@@ -243,13 +288,13 @@ export function useModalFocus(
243
288
  }
244
289
 
245
290
  if (e.key !== 'Tab') return;
246
- // The controls of a media element are in its user-agent shadow tree,
247
- // where the element stays the active one: they step through them
248
- // natively, and onFocusIn takes over where focus leaves the element
249
- // (#444).
291
+ // The controls of a media element and the segments of a date input are
292
+ // in its user-agent shadow tree, where the element stays the active
293
+ // one: they step through them natively, and onFocusIn takes over where
294
+ // focus leaves the element (#444, #461).
250
295
  const active = document.activeElement;
251
- if (active instanceof HTMLMediaElement && active.controls) {
252
- steppingMedia = { el: active, backwards: e.shiftKey };
296
+ if (hasNativeStops(active)) {
297
+ steppingNative = { el: active, backwards: e.shiftKey };
253
298
  return;
254
299
  }
255
300
  e.preventDefault();
@@ -257,7 +302,7 @@ export function useModalFocus(
257
302
  };
258
303
  // Clicking elsewhere ends the stepping through the controls
259
304
  const onPointerDown = () => {
260
- steppingMedia = null;
305
+ steppingNative = null;
261
306
  };
262
307
 
263
308
  // Key events inside an embedded document never reach this one (#425).
@@ -279,9 +324,7 @@ export function useModalFocus(
279
324
  const onFrameKeyDown = (e: KeyboardEvent) => {
280
325
  if (!top()) return;
281
326
  if (e.key !== 'Tab') return onKeyDown(e);
282
- const inner = Array.from(
283
- doc!.querySelectorAll<HTMLElement>(FOCUSABLE),
284
- ).filter((el) => isAvailable(el) && isTabStop(el));
327
+ const inner = frameStops(doc!);
285
328
  const active = doc!.activeElement;
286
329
  const edge = e.shiftKey ? inner[0] : inner[inner.length - 1];
287
330
  if (!edge || active === edge || active === doc!.body) {
@@ -307,10 +350,10 @@ export function useModalFocus(
307
350
  // document can't be reached, is brought back in.
308
351
  const onFocusIn = (e: FocusEvent) => {
309
352
  const target = e.target;
310
- if (steppingMedia && target !== steppingMedia.el && top()) {
353
+ if (steppingNative && target !== steppingNative.el && top()) {
311
354
  // Focus left the media controls: on to the modal's next control
312
- const { el, backwards } = steppingMedia;
313
- steppingMedia = null;
355
+ const { el, backwards } = steppingNative;
356
+ steppingNative = null;
314
357
  moveFocus(el, backwards);
315
358
  return;
316
359
  }
@@ -330,11 +373,11 @@ export function useModalFocus(
330
373
  // with no tab stop after it in the document) sends no focusin: the
331
374
  // modal's next control takes it at once.
332
375
  const onFocusOut = (e: FocusEvent) => {
333
- const pending = steppingMedia;
376
+ const pending = steppingNative;
334
377
  if (!pending || e.target !== pending.el || e.relatedTarget || !top()) {
335
378
  return;
336
379
  }
337
- steppingMedia = null;
380
+ steppingNative = null;
338
381
  moveFocus(pending.el, pending.backwards);
339
382
  };
340
383
  document.addEventListener('focusout', onFocusOut, { signal });
@@ -31,7 +31,7 @@ export const OutgoingContext = createContext<(() => boolean) | null>(null);
31
31
  export function useStoryFields<K extends keyof StoryState>(
32
32
  ...keys: K[]
33
33
  ): Pick<StoryState, K> {
34
- const prev = useRef<Pick<StoryState, K>>();
34
+ const prev = useRef<Pick<StoryState, K> | undefined>(undefined);
35
35
  const freeze = useContext(FrozenStateContext);
36
36
  return useStoryStore((s) => {
37
37
  if (prev.current && freeze?.(s)) return prev.current;
package/src/markup/ast.ts CHANGED
@@ -45,11 +45,7 @@ export interface HtmlNode {
45
45
  }
46
46
 
47
47
  export type ASTNode =
48
- | TextNode
49
- | VariableNode
50
- | ExpressionNode
51
- | MacroNode
52
- | HtmlNode;
48
+ TextNode | VariableNode | ExpressionNode | MacroNode | HtmlNode;
53
49
 
54
50
  /** Macros that require a closing tag and can contain children */
55
51
  const BLOCK_MACROS = new NameSet([
@@ -17,9 +17,7 @@ export function isCodeAttribute(name: string): boolean {
17
17
  /** Literal text, the source of one `{…}` reference (without braces), or a
18
18
  * `{…}` block that is kept exactly as written. */
19
19
  export type SigilPart =
20
- | { text: string }
21
- | { expr: string }
22
- | { verbatim: string };
20
+ { text: string } | { expr: string } | { verbatim: string };
23
21
 
24
22
  /**
25
23
  * Split a code attribute value into literal text and its `{…}` blocks that
@@ -33,7 +33,7 @@ const NON_STRING_QUOTE_PREFIX = /[\p{L}\p{N}_\\]/u;
33
33
  function skipLiteral(input: string, i: number): number {
34
34
  const quote = input[i];
35
35
  const template = quote === '`';
36
- for (let j = i + 1; j < input.length; ) {
36
+ for (let j = i + 1; j < input.length;) {
37
37
  const c = input[j];
38
38
  if (c === '\\') j += 2;
39
39
  else if (c === quote) return j + 1;
@@ -5,7 +5,7 @@ export function lineColumn(
5
5
  ): { line: number; column: number } {
6
6
  let line = 1;
7
7
  let lineStart = 0;
8
- for (let i = text.indexOf('\n'); i !== -1 && i < offset; ) {
8
+ for (let i = text.indexOf('\n'); i !== -1 && i < offset;) {
9
9
  line++;
10
10
  lineStart = i + 1;
11
11
  i = text.indexOf('\n', lineStart);
@@ -16,10 +16,7 @@ import type { HtmlToken, MacroToken, Span, Token } from './tokens';
16
16
 
17
17
  /** What is wrong with the pairing, by kind. */
18
18
  export type PairingErrorCode =
19
- | 'unclosed-block'
20
- | 'mismatched-closer'
21
- | 'stray-closer'
22
- | 'misplaced-branch';
19
+ 'unclosed-block' | 'mismatched-closer' | 'stray-closer' | 'misplaced-branch';
23
20
 
24
21
  /**
25
22
  * A problem in the pairing of the tokens, at the token from `start` up to