@fluixi/template-parser 1.0.0-alpha.108 → 1.0.0-alpha.109

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/a11y.mjs CHANGED
@@ -1,79 +1,6 @@
1
- // src/a11y.ts
2
- var INTERACTIVE = /* @__PURE__ */ new Set([
3
- "a",
4
- "button",
5
- "input",
6
- "select",
7
- "textarea",
8
- "summary",
9
- "details",
10
- "option",
11
- "label"
12
- ]);
13
- var KEY_EVENTS = /* @__PURE__ */ new Set(["keydown", "keyup", "keypress"]);
14
- function attributeNamed(node, name) {
15
- return node.attributes.find((a) => "name" in a && a.name === name);
16
- }
17
- function hasSpread(node) {
18
- return node.attributes.some((a) => a.kind === "Spread");
19
- }
20
- function staticValue(node, name) {
21
- const attribute = attributeNamed(node, name);
22
- if (!attribute || attribute.kind !== "Attribute" || !attribute.value) return void 0;
23
- const value = attribute.value;
24
- return value.kind === "static" ? value.value : void 0;
25
- }
26
- function isPresentational(node) {
27
- const role = staticValue(node, "role");
28
- if (role === "presentation" || role === "none") return true;
29
- return staticValue(node, "aria-hidden") === "true";
30
- }
31
- function hasEvent(node, predicate) {
32
- return node.attributes.some((a) => a.kind === "EventBinding" && predicate(a.name));
33
- }
34
- function checkAccessibility(root) {
35
- const out = [];
36
- const report = (node, code, message) => {
37
- out.push({ code, message, severity: "warning", loc: node.loc });
38
- };
39
- const visit = (nodes) => {
40
- for (const node of nodes) {
41
- if (node.kind === "Element") check(node, report);
42
- const children = "children" in node ? node.children : void 0;
43
- if (children) visit(children);
44
- }
45
- };
46
- visit(root.children);
47
- return out;
48
- }
49
- function check(node, report) {
50
- if (hasSpread(node)) return;
51
- const tag = node.tag.toLowerCase();
52
- if (tag === "img" && !attributeNamed(node, "alt") && !isPresentational(node)) {
53
- report(node, "a11y-img-alt", 'An `img` needs an `alt`. Use `alt=""` when the image is decorative.');
54
- }
55
- if (tag === "a" && !attributeNamed(node, "href") && !attributeNamed(node, "role")) {
56
- report(node, "a11y-anchor-href", "An `a` without `href` is not a link. Use a `button` for an action.");
57
- }
58
- if (tag === "iframe" && !attributeNamed(node, "title")) {
59
- report(node, "a11y-iframe-title", "An `iframe` needs a `title` describing its content.");
60
- }
61
- const tabindex = staticValue(node, "tabindex") ?? staticValue(node, "tabIndex");
62
- if (tabindex !== void 0 && Number(tabindex) > 0) {
63
- report(
64
- node,
65
- "a11y-positive-tabindex",
66
- "A positive `tabindex` reorders tab navigation for the entire page. Use `0`, or restructure the markup."
67
- );
68
- }
69
- if (!INTERACTIVE.has(tag) && hasEvent(node, (name) => name === "click") && !attributeNamed(node, "role") && !hasEvent(node, (name) => KEY_EVENTS.has(name))) {
70
- report(
71
- node,
72
- "a11y-click-without-keyboard",
73
- `A click handler on \`${tag}\` is unreachable by keyboard. Use a \`button\`, or add a \`role\` and a key handler.`
74
- );
75
- }
76
- }
1
+ import {
2
+ checkAccessibility
3
+ } from "./chunk-DK3MEEE6.mjs";
77
4
  export {
78
5
  checkAccessibility
79
6
  };
package/dist/ast.d.cts CHANGED
@@ -191,6 +191,8 @@ export interface LoadDirectiveNode extends NodeBase {
191
191
  strategy: string;
192
192
  /** `load:visible="200px"` → `'200px'`. Null for a bare directive. */
193
193
  modifier: string | null;
194
+ /** The value was an expression (`load:visible=\${m}`), which a compile-time strategy cannot take. */
195
+ dynamic?: boolean;
194
196
  }
195
197
  /** `use=${directive}` or `use:tooltip` (optionally `use:tooltip=${opts}`). */
196
198
  export interface UseDirectiveNode extends NodeBase {
package/dist/ast.d.ts CHANGED
@@ -191,6 +191,8 @@ export interface LoadDirectiveNode extends NodeBase {
191
191
  strategy: string;
192
192
  /** `load:visible="200px"` → `'200px'`. Null for a bare directive. */
193
193
  modifier: string | null;
194
+ /** The value was an expression (`load:visible=\${m}`), which a compile-time strategy cannot take. */
195
+ dynamic?: boolean;
194
196
  }
195
197
  /** `use=${directive}` or `use:tooltip` (optionally `use:tooltip=${opts}`). */
196
198
  export interface UseDirectiveNode extends NodeBase {
package/dist/ast.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,2EAA2E;AAC3E,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,iFAAiF;AACjF,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,CAAC;AAIlD,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,SAAS,GACT,WAAW,GACX,UAAU,GACV,MAAM,GACN,SAAS,GACT,YAAY,CAAC;AAEjB,MAAM,MAAM,QAAQ,GAChB,WAAW,GACX,iBAAiB,GACjB,cAAc,GACd,YAAY,GACZ,QAAQ,GACR,aAAa,GACb,eAAe,GACf,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,eAAe,GACf,MAAM,CAAC;AAEX,4EAA4E;AAC5E,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,UAAU,CAAC;IAChB,MAAM,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,WAAW,GACX,aAAa,GACb,YAAY,GACZ,QAAQ,GACR,WAAW,GACX,cAAc,CAAC;AAEnB,oEAAoE;AACpE,MAAM,MAAM,iBAAiB,GACzB,aAAa,GACb,mBAAmB,GACnB,gBAAgB,GAChB,cAAc,GACd,UAAU,GACV,eAAe,GACf,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,kBAAkB,GAClB,gBAAgB,GAChB,iBAAiB,GACjB,QAAQ,CAAC;AAIb,MAAM,WAAW,QAAS,SAAQ,QAAQ;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ACjB,yBAAyB,GAGzB,cAAc,GACd,kBAAkB,GAClB,mBAAmB,GACnB,wBAAwB,GACxB,6BAA6B,CAAC;AAElC,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,EAAE,UAAU,EAAE,CAAC;CAC3B;AAID,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CAQnD;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,CAU7D"}
package/dist/ast.mjs CHANGED
@@ -1,24 +1,7 @@
1
- // src/ast.ts
2
- function setParents(root) {
3
- const visit = (node, parent) => {
4
- node.parent = parent;
5
- const kids = childrenOf(node);
6
- for (const child of kids) visit(child, node);
7
- };
8
- visit(root, null);
9
- return root;
10
- }
11
- function childrenOf(node) {
12
- switch (node.kind) {
13
- case "Root":
14
- case "Element":
15
- case "Component":
16
- case "Fragment":
17
- return node.children;
18
- default:
19
- return [];
20
- }
21
- }
1
+ import {
2
+ childrenOf,
3
+ setParents
4
+ } from "./chunk-R4NGOY2K.mjs";
22
5
  export {
23
6
  childrenOf,
24
7
  setParents
@@ -0,0 +1,104 @@
1
+ // src/tags.ts
2
+ var SVG_TAGS = /* @__PURE__ */ new Set([
3
+ "svg",
4
+ "g",
5
+ "defs",
6
+ "symbol",
7
+ "use",
8
+ "switch",
9
+ "view",
10
+ "desc",
11
+ "metadata",
12
+ "path",
13
+ "circle",
14
+ "ellipse",
15
+ "line",
16
+ "polygon",
17
+ "polyline",
18
+ "rect",
19
+ "image",
20
+ "text",
21
+ "tspan",
22
+ "textPath",
23
+ "linearGradient",
24
+ "radialGradient",
25
+ "stop",
26
+ "pattern",
27
+ "mask",
28
+ "clipPath",
29
+ "marker",
30
+ "foreignObject",
31
+ "animate",
32
+ "animateMotion",
33
+ "animateTransform",
34
+ "mpath",
35
+ "set",
36
+ "filter",
37
+ "feBlend",
38
+ "feColorMatrix",
39
+ "feComponentTransfer",
40
+ "feComposite",
41
+ "feConvolveMatrix",
42
+ "feDiffuseLighting",
43
+ "feDisplacementMap",
44
+ "feDistantLight",
45
+ "feDropShadow",
46
+ "feFlood",
47
+ "feFuncA",
48
+ "feFuncB",
49
+ "feFuncG",
50
+ "feFuncR",
51
+ "feGaussianBlur",
52
+ "feImage",
53
+ "feMerge",
54
+ "feMergeNode",
55
+ "feMorphology",
56
+ "feOffset",
57
+ "fePointLight",
58
+ "feSpecularLighting",
59
+ "feSpotLight",
60
+ "feTile",
61
+ "feTurbulence"
62
+ ]);
63
+ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
64
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
65
+ "area",
66
+ "base",
67
+ "br",
68
+ "col",
69
+ "embed",
70
+ "hr",
71
+ "img",
72
+ "input",
73
+ "link",
74
+ "meta",
75
+ "param",
76
+ "source",
77
+ "track",
78
+ "wbr"
79
+ ]);
80
+ var DELEGATED_EVENTS = /* @__PURE__ */ new Set([
81
+ "click",
82
+ "dblclick",
83
+ "input",
84
+ "change",
85
+ "submit",
86
+ "focus",
87
+ "blur",
88
+ "keydown",
89
+ "keyup",
90
+ "keypress",
91
+ "mousedown",
92
+ "mouseup"
93
+ ]);
94
+ function isComponentTag(tag) {
95
+ return tag.length > 0 && (tag[0] !== tag[0].toLowerCase() || tag.includes("."));
96
+ }
97
+
98
+ export {
99
+ SVG_TAGS,
100
+ RAW_TEXT_ELEMENTS,
101
+ VOID_ELEMENTS,
102
+ DELEGATED_EVENTS,
103
+ isComponentTag
104
+ };
@@ -0,0 +1,80 @@
1
+ // src/a11y.ts
2
+ var INTERACTIVE = /* @__PURE__ */ new Set([
3
+ "a",
4
+ "button",
5
+ "input",
6
+ "select",
7
+ "textarea",
8
+ "summary",
9
+ "details",
10
+ "option",
11
+ "label"
12
+ ]);
13
+ var KEY_EVENTS = /* @__PURE__ */ new Set(["keydown", "keyup", "keypress"]);
14
+ function attributeNamed(node, name) {
15
+ return node.attributes.find((a) => "name" in a && a.name === name);
16
+ }
17
+ function hasSpread(node) {
18
+ return node.attributes.some((a) => a.kind === "Spread");
19
+ }
20
+ function staticValue(node, name) {
21
+ const attribute = attributeNamed(node, name);
22
+ if (!attribute || attribute.kind !== "Attribute" || !attribute.value) return void 0;
23
+ const value = attribute.value;
24
+ return value.kind === "static" ? value.value : void 0;
25
+ }
26
+ function isPresentational(node) {
27
+ const role = staticValue(node, "role");
28
+ if (role === "presentation" || role === "none") return true;
29
+ return staticValue(node, "aria-hidden") === "true";
30
+ }
31
+ function hasEvent(node, predicate) {
32
+ return node.attributes.some((a) => a.kind === "EventBinding" && predicate(a.name));
33
+ }
34
+ function checkAccessibility(root) {
35
+ const out = [];
36
+ const report = (node, code, message) => {
37
+ out.push({ code, message, severity: "warning", loc: node.loc });
38
+ };
39
+ const visit = (nodes) => {
40
+ for (const node of nodes) {
41
+ if (node.kind === "Element") check(node, report);
42
+ const children = "children" in node ? node.children : void 0;
43
+ if (children) visit(children);
44
+ }
45
+ };
46
+ visit(root.children);
47
+ return out;
48
+ }
49
+ function check(node, report) {
50
+ if (hasSpread(node)) return;
51
+ const tag = node.tag.toLowerCase();
52
+ if (tag === "img" && !attributeNamed(node, "alt") && !isPresentational(node)) {
53
+ report(node, "a11y-img-alt", 'An `img` needs an `alt`. Use `alt=""` when the image is decorative.');
54
+ }
55
+ if (tag === "a" && !attributeNamed(node, "href") && !attributeNamed(node, "role")) {
56
+ report(node, "a11y-anchor-href", "An `a` without `href` is not a link. Use a `button` for an action.");
57
+ }
58
+ if (tag === "iframe" && !attributeNamed(node, "title")) {
59
+ report(node, "a11y-iframe-title", "An `iframe` needs a `title` describing its content.");
60
+ }
61
+ const tabindex = staticValue(node, "tabindex") ?? staticValue(node, "tabIndex");
62
+ if (tabindex !== void 0 && Number(tabindex) > 0) {
63
+ report(
64
+ node,
65
+ "a11y-positive-tabindex",
66
+ "A positive `tabindex` reorders tab navigation for the entire page. Use `0`, or restructure the markup."
67
+ );
68
+ }
69
+ if (!INTERACTIVE.has(tag) && hasEvent(node, (name) => name === "click") && !attributeNamed(node, "role") && !hasEvent(node, (name) => KEY_EVENTS.has(name))) {
70
+ report(
71
+ node,
72
+ "a11y-click-without-keyboard",
73
+ `A click handler on \`${tag}\` is unreachable by keyboard. Use a \`button\`, or add a \`role\` and a key handler.`
74
+ );
75
+ }
76
+ }
77
+
78
+ export {
79
+ checkAccessibility
80
+ };
@@ -0,0 +1,192 @@
1
+ // src/directives.ts
2
+ var EVENT_MODIFIERS = /* @__PURE__ */ new Set(["capture", "once", "passive", "prevent", "stop", "self"]);
3
+ function requireHole(raw, what) {
4
+ if (raw.value && raw.value.kind === "hole") return raw.value.hole;
5
+ raw.report("invalid-binding", `${what} requires an expression value: ${raw.name}=\${…}`);
6
+ return -1;
7
+ }
8
+ var attribute = (raw, boolean) => ({
9
+ kind: "Attribute",
10
+ name: boolean ? raw.name.slice(1) : raw.name,
11
+ value: raw.value,
12
+ boolean,
13
+ loc: raw.loc
14
+ });
15
+ var CORE_DIRECTIVES = [
16
+ // Events: `@click=${h}`, `on:click=${h}` (native), `onClick=${h}`, each with
17
+ // optional dotted modifiers (`@click.capture.once`, `on:input.passive`).
18
+ {
19
+ id: "event",
20
+ match: (n) => n[0] === "@" || n.startsWith("on:") || /^on[A-Z]/.test(n),
21
+ build: (raw) => {
22
+ let syntax;
23
+ let rest;
24
+ if (raw.name[0] === "@") {
25
+ syntax = "at";
26
+ rest = raw.name.slice(1);
27
+ } else if (raw.name.startsWith("on:")) {
28
+ syntax = "colon";
29
+ rest = raw.name.slice(3);
30
+ } else {
31
+ syntax = "on";
32
+ rest = raw.name.slice(2);
33
+ }
34
+ const [raw_name, ...modifiers] = rest.split(".");
35
+ const name = raw_name.toLowerCase();
36
+ for (const m of modifiers) {
37
+ if (!EVENT_MODIFIERS.has(m)) {
38
+ raw.report("invalid-directive", `Unknown event modifier ".${m}" — expected one of ${[...EVENT_MODIFIERS].join(", ")}`);
39
+ }
40
+ }
41
+ return {
42
+ kind: "EventBinding",
43
+ name,
44
+ syntax,
45
+ modifiers,
46
+ hole: requireHole(raw, "event binding"),
47
+ loc: raw.loc
48
+ };
49
+ }
50
+ },
51
+ // Two-way binding: `bind:value=${signal}`.
52
+ {
53
+ id: "bind",
54
+ elementOnly: true,
55
+ match: (n) => n.startsWith("bind:"),
56
+ build: (raw) => ({
57
+ kind: "BindDirective",
58
+ name: raw.name.slice("bind:".length),
59
+ hole: requireHole(raw, "two-way binding"),
60
+ loc: raw.loc
61
+ })
62
+ },
63
+ // Dynamic class toggle: `class:active=${flag}`.
64
+ {
65
+ id: "class-directive",
66
+ elementOnly: true,
67
+ match: (n) => n.startsWith("class:"),
68
+ build: (raw) => ({
69
+ kind: "ClassDirective",
70
+ name: raw.name.slice("class:".length),
71
+ hole: requireHole(raw, "class directive"),
72
+ loc: raw.loc
73
+ })
74
+ },
75
+ // Dynamic style: `style:color=${c}`.
76
+ {
77
+ id: "style-directive",
78
+ elementOnly: true,
79
+ match: (n) => n.startsWith("style:"),
80
+ build: (raw) => ({
81
+ kind: "StyleDirective",
82
+ name: raw.name.slice("style:".length),
83
+ hole: requireHole(raw, "style directive"),
84
+ loc: raw.loc
85
+ })
86
+ },
87
+ // Load strategy: `load:visible[="200px"]`. Components only, an intrinsic element
88
+ // has no module to defer.
89
+ {
90
+ id: "load",
91
+ match: (n) => n.startsWith("load:"),
92
+ build: (raw) => {
93
+ if (raw.value && raw.value.kind !== "static") {
94
+ raw.report("invalid-binding", `'${raw.name}' needs a literal value, not an expression: the strategy is compile-time.`);
95
+ }
96
+ return {
97
+ kind: "LoadDirective",
98
+ strategy: raw.name.slice("load:".length),
99
+ modifier: raw.value && raw.value.kind === "static" ? raw.value.value : null,
100
+ ...raw.value && raw.value.kind !== "static" ? { dynamic: true } : {},
101
+ loc: raw.loc
102
+ };
103
+ }
104
+ },
105
+ // Custom directive: `use=${d}` or `use:tooltip[=${opts}]`.
106
+ {
107
+ id: "use",
108
+ match: (n) => n === "use" || n.startsWith("use:"),
109
+ build: (raw) => {
110
+ const named = raw.name.startsWith("use:");
111
+ return {
112
+ kind: "UseDirective",
113
+ name: named ? raw.name.slice("use:".length) : null,
114
+ hole: raw.value && raw.value.kind === "hole" ? raw.value.hole : null,
115
+ loc: raw.loc
116
+ };
117
+ }
118
+ },
119
+ // Conditional rendering: `if=${cond}`.
120
+ {
121
+ id: "if",
122
+ elementOnly: true,
123
+ match: (n) => n === "if",
124
+ build: (raw) => ({
125
+ kind: "IfDirective",
126
+ hole: requireHole(raw, "if directive"),
127
+ loc: raw.loc
128
+ })
129
+ },
130
+ // Loop rendering: `each=${items}` (a sibling `key` folds in at parse time).
131
+ {
132
+ id: "each",
133
+ elementOnly: true,
134
+ match: (n) => n === "each",
135
+ build: (raw) => ({
136
+ kind: "EachDirective",
137
+ hole: requireHole(raw, "each directive"),
138
+ key: null,
139
+ loc: raw.loc
140
+ })
141
+ },
142
+ // `else` (valueless).
143
+ {
144
+ id: "else",
145
+ elementOnly: true,
146
+ match: (n) => n === "else",
147
+ build: (raw) => {
148
+ if (raw.value !== null) raw.report("invalid-directive", "`else` takes no value");
149
+ return { kind: "ElseDirective", loc: raw.loc };
150
+ }
151
+ },
152
+ // Ref binding: `ref=${el}`.
153
+ {
154
+ id: "ref",
155
+ match: (n) => n === "ref",
156
+ build: (raw) => ({
157
+ kind: "RefBinding",
158
+ hole: requireHole(raw, "ref binding"),
159
+ loc: raw.loc
160
+ })
161
+ },
162
+ // Property binding: `.currentTime=${t}`.
163
+ {
164
+ id: "property",
165
+ match: (n) => n[0] === ".",
166
+ build: (raw) => ({
167
+ kind: "PropertyBinding",
168
+ name: raw.name.slice(1),
169
+ hole: requireHole(raw, "property binding"),
170
+ loc: raw.loc
171
+ })
172
+ },
173
+ // Boolean attribute (lit `?disabled`): a plain attribute flagged boolean.
174
+ {
175
+ id: "boolean",
176
+ match: (n) => n[0] === "?",
177
+ build: (raw) => attribute(raw, true)
178
+ }
179
+ ];
180
+ function resolveAttribute(raw, directives = CORE_DIRECTIVES, ctx = { component: false }) {
181
+ for (const d of directives) {
182
+ if (d.elementOnly && ctx.component) continue;
183
+ if (d.match(raw.name)) return d.build(raw);
184
+ }
185
+ return attribute(raw, false);
186
+ }
187
+
188
+ export {
189
+ EVENT_MODIFIERS,
190
+ CORE_DIRECTIVES,
191
+ resolveAttribute
192
+ };
@@ -0,0 +1,26 @@
1
+ // src/ast.ts
2
+ function setParents(root) {
3
+ const visit = (node, parent) => {
4
+ node.parent = parent;
5
+ const kids = childrenOf(node);
6
+ for (const child of kids) visit(child, node);
7
+ };
8
+ visit(root, null);
9
+ return root;
10
+ }
11
+ function childrenOf(node) {
12
+ switch (node.kind) {
13
+ case "Root":
14
+ case "Element":
15
+ case "Component":
16
+ case "Fragment":
17
+ return node.children;
18
+ default:
19
+ return [];
20
+ }
21
+ }
22
+
23
+ export {
24
+ setParents,
25
+ childrenOf
26
+ };
@@ -0,0 +1,102 @@
1
+ // src/reader.ts
2
+ var Reader = class {
3
+ // offset within the current static piece
4
+ constructor(pieces) {
5
+ this.pieces = pieces;
6
+ this.pi = 0;
7
+ // current piece index
8
+ this.oi = 0;
9
+ this.normalize();
10
+ }
11
+ /** Skip fully-consumed static pieces so `current()` is live text or a hole. */
12
+ normalize() {
13
+ while (this.pi < this.pieces.length) {
14
+ const p = this.pieces[this.pi];
15
+ if (p.kind === "static" && this.oi >= p.text.length) {
16
+ this.pi++;
17
+ this.oi = 0;
18
+ continue;
19
+ }
20
+ break;
21
+ }
22
+ }
23
+ eof() {
24
+ return this.pi >= this.pieces.length;
25
+ }
26
+ /** Absolute source offset of the cursor. */
27
+ pos() {
28
+ if (this.eof()) {
29
+ const last = this.pieces[this.pieces.length - 1];
30
+ return last ? last.kind === "static" ? last.start + last.text.length : last.end : 0;
31
+ }
32
+ const p = this.pieces[this.pi];
33
+ return p.kind === "static" ? p.start + this.oi : p.start;
34
+ }
35
+ /** True when the cursor sits exactly on a hole marker. */
36
+ atHole() {
37
+ return !this.eof() && this.pieces[this.pi].kind === "hole";
38
+ }
39
+ /** True when advancing one char would land on a hole (e.g. the `<` in `<${Tag}`). */
40
+ holeFollows() {
41
+ if (this.eof()) return false;
42
+ const p = this.pieces[this.pi];
43
+ if (p.kind !== "static") return false;
44
+ if (this.oi + 1 < p.text.length) return false;
45
+ const next = this.pieces[this.pi + 1];
46
+ return next !== void 0 && next.kind === "hole";
47
+ }
48
+ /** Consume the hole at the cursor. Caller must have checked {@link atHole}. */
49
+ takeHole() {
50
+ const p = this.pieces[this.pi];
51
+ if (p.kind !== "hole") throw new Error("takeHole called off a hole");
52
+ this.pi++;
53
+ this.oi = 0;
54
+ this.normalize();
55
+ return { index: p.index, loc: { start: p.start, end: p.end } };
56
+ }
57
+ /** Char `k` ahead within the current static segment, or '' at a boundary/hole. */
58
+ peek(k = 0) {
59
+ if (this.eof()) return "";
60
+ const p = this.pieces[this.pi];
61
+ if (p.kind !== "static") return "";
62
+ return p.text[this.oi + k] ?? "";
63
+ }
64
+ /** Whether the current static segment starts with `s` at the cursor. */
65
+ startsWith(s) {
66
+ if (this.eof()) return false;
67
+ const p = this.pieces[this.pi];
68
+ if (p.kind !== "static") return false;
69
+ return p.text.startsWith(s, this.oi);
70
+ }
71
+ /** Advance one character inside the current static segment. */
72
+ advance() {
73
+ if (this.eof()) return "";
74
+ const p = this.pieces[this.pi];
75
+ if (p.kind !== "static") return "";
76
+ const ch = p.text[this.oi++] ?? "";
77
+ this.normalize();
78
+ return ch;
79
+ }
80
+ /** Advance while `pred` holds and we stay inside one static segment. */
81
+ readWhile(pred) {
82
+ let out = "";
83
+ while (!this.eof() && !this.atHole()) {
84
+ const ch = this.peek();
85
+ if (ch === "" || !pred(ch)) break;
86
+ out += ch;
87
+ this.oi++;
88
+ }
89
+ this.normalize();
90
+ return out;
91
+ }
92
+ skipWhitespace() {
93
+ this.readWhile((ch) => /\s/.test(ch));
94
+ }
95
+ span(start) {
96
+ return { start, end: this.pos() };
97
+ }
98
+ };
99
+
100
+ export {
101
+ Reader
102
+ };