@fluixi/ts-plugin 0.1.0-alpha.8 → 1.0.0-alpha.99

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/index.js CHANGED
@@ -1,37 +1,41 @@
1
1
  "use strict";
2
2
 
3
3
  // ../template-parser/dist/index.mjs
4
- function x(e) {
5
- let t = (i2, n) => {
6
- i2.parent = n;
7
- let r = R(i2);
8
- for (let s2 of r) t(s2, i2);
4
+ function setParents(root) {
5
+ const visit = (node, parent) => {
6
+ node.parent = parent;
7
+ const kids = childrenOf(node);
8
+ for (const child of kids) visit(child, node);
9
9
  };
10
- return t(e, null), e;
10
+ visit(root, null);
11
+ return root;
11
12
  }
12
- function R(e) {
13
- switch (e.kind) {
13
+ function childrenOf(node) {
14
+ switch (node.kind) {
14
15
  case "Root":
15
16
  case "Element":
16
17
  case "Component":
17
18
  case "Fragment":
18
- return e.children;
19
+ return node.children;
19
20
  default:
20
21
  return [];
21
22
  }
22
23
  }
23
- var m = class {
24
- constructor(t) {
25
- this.pieces = t;
24
+ var Reader = class {
25
+ // offset within the current static piece
26
+ constructor(pieces) {
27
+ this.pieces = pieces;
26
28
  this.pi = 0;
27
29
  this.oi = 0;
28
30
  this.normalize();
29
31
  }
32
+ /** Skip fully-consumed static pieces so `current()` is live text or a hole. */
30
33
  normalize() {
31
- for (; this.pi < this.pieces.length; ) {
32
- let t = this.pieces[this.pi];
33
- if (t.kind === "static" && this.oi >= t.text.length) {
34
- this.pi++, this.oi = 0;
34
+ while (this.pi < this.pieces.length) {
35
+ const p = this.pieces[this.pi];
36
+ if (p.kind === "static" && this.oi >= p.text.length) {
37
+ this.pi++;
38
+ this.oi = 0;
35
39
  continue;
36
40
  }
37
41
  break;
@@ -40,174 +44,449 @@ var m = class {
40
44
  eof() {
41
45
  return this.pi >= this.pieces.length;
42
46
  }
47
+ /** Absolute source offset of the cursor. */
43
48
  pos() {
44
49
  if (this.eof()) {
45
- let i2 = this.pieces[this.pieces.length - 1];
46
- return i2 ? i2.kind === "static" ? i2.start + i2.text.length : i2.end : 0;
50
+ const last = this.pieces[this.pieces.length - 1];
51
+ return last ? last.kind === "static" ? last.start + last.text.length : last.end : 0;
47
52
  }
48
- let t = this.pieces[this.pi];
49
- return t.kind === "static" ? t.start + this.oi : t.start;
53
+ const p = this.pieces[this.pi];
54
+ return p.kind === "static" ? p.start + this.oi : p.start;
50
55
  }
56
+ /** True when the cursor sits exactly on a hole marker. */
51
57
  atHole() {
52
58
  return !this.eof() && this.pieces[this.pi].kind === "hole";
53
59
  }
60
+ /** True when advancing one char would land on a hole (e.g. the `<` in `<${Tag}`). */
54
61
  holeFollows() {
55
62
  if (this.eof()) return false;
56
- let t = this.pieces[this.pi];
57
- if (t.kind !== "static" || this.oi + 1 < t.text.length) return false;
58
- let i2 = this.pieces[this.pi + 1];
59
- return i2 !== void 0 && i2.kind === "hole";
63
+ const p = this.pieces[this.pi];
64
+ if (p.kind !== "static") return false;
65
+ if (this.oi + 1 < p.text.length) return false;
66
+ const next = this.pieces[this.pi + 1];
67
+ return next !== void 0 && next.kind === "hole";
60
68
  }
69
+ /** Consume the hole at the cursor. Caller must have checked {@link atHole}. */
61
70
  takeHole() {
62
- let t = this.pieces[this.pi];
63
- if (t.kind !== "hole") throw new Error("takeHole called off a hole");
64
- return this.pi++, this.oi = 0, this.normalize(), { index: t.index, loc: { start: t.start, end: t.end } };
71
+ const p = this.pieces[this.pi];
72
+ if (p.kind !== "hole") throw new Error("takeHole called off a hole");
73
+ this.pi++;
74
+ this.oi = 0;
75
+ this.normalize();
76
+ return { index: p.index, loc: { start: p.start, end: p.end } };
65
77
  }
66
- peek(t = 0) {
78
+ /** Char `k` ahead within the current static segment, or '' at a boundary/hole. */
79
+ peek(k = 0) {
67
80
  if (this.eof()) return "";
68
- let i2 = this.pieces[this.pi];
69
- return i2.kind !== "static" ? "" : i2.text[this.oi + t] ?? "";
81
+ const p = this.pieces[this.pi];
82
+ if (p.kind !== "static") return "";
83
+ return p.text[this.oi + k] ?? "";
70
84
  }
71
- startsWith(t) {
85
+ /** Whether the current static segment starts with `s` at the cursor. */
86
+ startsWith(s) {
72
87
  if (this.eof()) return false;
73
- let i2 = this.pieces[this.pi];
74
- return i2.kind !== "static" ? false : i2.text.startsWith(t, this.oi);
88
+ const p = this.pieces[this.pi];
89
+ if (p.kind !== "static") return false;
90
+ return p.text.startsWith(s, this.oi);
75
91
  }
92
+ /** Advance one character inside the current static segment. */
76
93
  advance() {
77
94
  if (this.eof()) return "";
78
- let t = this.pieces[this.pi];
79
- if (t.kind !== "static") return "";
80
- let i2 = t.text[this.oi++] ?? "";
81
- return this.normalize(), i2;
82
- }
83
- readWhile(t) {
84
- let i2 = "";
85
- for (; !this.eof() && !this.atHole(); ) {
86
- let n = this.peek();
87
- if (n === "" || !t(n)) break;
88
- i2 += n, this.oi++;
95
+ const p = this.pieces[this.pi];
96
+ if (p.kind !== "static") return "";
97
+ const ch = p.text[this.oi++] ?? "";
98
+ this.normalize();
99
+ return ch;
100
+ }
101
+ /** Advance while `pred` holds and we stay inside one static segment. */
102
+ readWhile(pred) {
103
+ let out = "";
104
+ while (!this.eof() && !this.atHole()) {
105
+ const ch = this.peek();
106
+ if (ch === "" || !pred(ch)) break;
107
+ out += ch;
108
+ this.oi++;
89
109
  }
90
- return this.normalize(), i2;
110
+ this.normalize();
111
+ return out;
91
112
  }
92
113
  skipWhitespace() {
93
- this.readWhile((t) => /\s/.test(t));
114
+ this.readWhile((ch) => /\s/.test(ch));
94
115
  }
95
- span(t) {
96
- return { start: t, end: this.pos() };
116
+ span(start) {
117
+ return { start, end: this.pos() };
97
118
  }
98
119
  };
99
- var y = /* @__PURE__ */ new Set(["capture", "once", "passive", "prevent", "stop", "self"]);
100
- function p(e, t) {
101
- return e.value && e.value.kind === "hole" ? e.value.hole : (e.report("invalid-binding", `${t} requires an expression value: ${e.name}=\${\u2026}`), -1);
102
- }
103
- var D = (e, t) => ({ kind: "Attribute", name: t ? e.name.slice(1) : e.name, value: e.value, boolean: t, loc: e.loc });
104
- var f = [{ id: "event", match: (e) => e[0] === "@" || e.startsWith("on:") || /^on[A-Z]/.test(e), build: (e) => {
105
- let t, i2;
106
- e.name[0] === "@" ? (t = "at", i2 = e.name.slice(1)) : e.name.startsWith("on:") ? (t = "colon", i2 = e.name.slice(3)) : (t = "on", i2 = e.name.slice(2));
107
- let [n, ...r] = i2.split("."), s2 = n.toLowerCase();
108
- for (let o of r) y.has(o) || e.report("invalid-directive", `Unknown event modifier ".${o}" \u2014 expected one of ${[...y].join(", ")}`);
109
- return { kind: "EventBinding", name: s2, syntax: t, modifiers: r, hole: p(e, "event binding"), loc: e.loc };
110
- } }, { id: "bind", elementOnly: true, match: (e) => e.startsWith("bind:"), build: (e) => ({ kind: "BindDirective", name: e.name.slice(5), hole: p(e, "two-way binding"), loc: e.loc }) }, { id: "class-directive", elementOnly: true, match: (e) => e.startsWith("class:"), build: (e) => ({ kind: "ClassDirective", name: e.name.slice(6), hole: p(e, "class directive"), loc: e.loc }) }, { id: "style-directive", elementOnly: true, match: (e) => e.startsWith("style:"), build: (e) => ({ kind: "StyleDirective", name: e.name.slice(6), hole: p(e, "style directive"), loc: e.loc }) }, { id: "load", match: (e) => e.startsWith("load:"), build: (e) => ({ kind: "LoadDirective", strategy: e.name.slice(5), modifier: e.value && e.value.kind === "static" ? e.value.value : null, loc: e.loc }) }, { id: "use", match: (e) => e === "use" || e.startsWith("use:"), build: (e) => ({ kind: "UseDirective", name: e.name.startsWith("use:") ? e.name.slice(4) : null, hole: e.value && e.value.kind === "hole" ? e.value.hole : null, loc: e.loc }) }, { id: "if", elementOnly: true, match: (e) => e === "if", build: (e) => ({ kind: "IfDirective", hole: p(e, "if directive"), loc: e.loc }) }, { id: "each", elementOnly: true, match: (e) => e === "each", build: (e) => ({ kind: "EachDirective", hole: p(e, "each directive"), key: null, loc: e.loc }) }, { id: "else", elementOnly: true, match: (e) => e === "else", build: (e) => (e.value !== null && e.report("invalid-directive", "`else` takes no value"), { kind: "ElseDirective", loc: e.loc }) }, { id: "ref", match: (e) => e === "ref", build: (e) => ({ kind: "RefBinding", hole: p(e, "ref binding"), loc: e.loc }) }, { id: "property", match: (e) => e[0] === ".", build: (e) => ({ kind: "PropertyBinding", name: e.name.slice(1), hole: p(e, "property binding"), loc: e.loc }) }, { id: "boolean", match: (e) => e[0] === "?", build: (e) => D(e, true) }];
111
- function k(e, t = f, i2 = { component: false }) {
112
- for (let n of t) if (!(n.elementOnly && i2.component) && n.match(e.name)) return n.build(e);
113
- return D(e, false);
114
- }
115
- var E = /* @__PURE__ */ new Set(["svg", "path", "circle", "rect", "line", "polygon", "polyline", "ellipse", "g", "defs", "clipPath", "text"]);
116
- var S = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
117
- var T = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
118
- function C(e) {
119
- return e.length > 0 && (e[0] !== e[0].toLowerCase() || e.includes("."));
120
- }
121
- var P = /* @__PURE__ */ new Set(["a", "button", "input", "select", "textarea", "summary", "details", "option", "label"]);
122
- var W = /* @__PURE__ */ new Set(["keydown", "keyup", "keypress"]);
123
- function u(e, t) {
124
- return e.attributes.find((i2) => "name" in i2 && i2.name === t);
125
- }
126
- function w(e) {
127
- return e.attributes.some((t) => t.kind === "Spread");
128
- }
129
- function v(e, t) {
130
- let i2 = u(e, t);
131
- if (!i2 || i2.kind !== "Attribute" || !i2.value) return;
132
- let n = i2.value;
133
- return n.kind === "static" ? n.value : void 0;
134
- }
135
- function H(e) {
136
- let t = v(e, "role");
137
- return t === "presentation" || t === "none" ? true : v(e, "aria-hidden") === "true";
138
- }
139
- function A(e, t) {
140
- return e.attributes.some((i2) => i2.kind === "EventBinding" && t(i2.name));
141
- }
142
- function B(e) {
143
- let t = [], i2 = (r, s2, o) => {
144
- t.push({ code: s2, message: o, severity: "warning", loc: r.loc });
145
- }, n = (r) => {
146
- for (let s2 of r) {
147
- s2.kind === "Element" && L(s2, i2);
148
- let o = "children" in s2 ? s2.children : void 0;
149
- o && n(o);
120
+ var EVENT_MODIFIERS = /* @__PURE__ */ new Set(["capture", "once", "passive", "prevent", "stop", "self"]);
121
+ function requireHole(raw, what) {
122
+ if (raw.value && raw.value.kind === "hole") return raw.value.hole;
123
+ raw.report("invalid-binding", `${what} requires an expression value: ${raw.name}=\${\u2026}`);
124
+ return -1;
125
+ }
126
+ var attribute = (raw, boolean) => ({
127
+ kind: "Attribute",
128
+ name: boolean ? raw.name.slice(1) : raw.name,
129
+ value: raw.value,
130
+ boolean,
131
+ loc: raw.loc
132
+ });
133
+ var CORE_DIRECTIVES = [
134
+ // Events: `@click=${h}`, `on:click=${h}` (native), `onClick=${h}`, each with
135
+ // optional dotted modifiers (`@click.capture.once`, `on:input.passive`).
136
+ {
137
+ id: "event",
138
+ match: (n) => n[0] === "@" || n.startsWith("on:") || /^on[A-Z]/.test(n),
139
+ build: (raw) => {
140
+ let syntax;
141
+ let rest;
142
+ if (raw.name[0] === "@") {
143
+ syntax = "at";
144
+ rest = raw.name.slice(1);
145
+ } else if (raw.name.startsWith("on:")) {
146
+ syntax = "colon";
147
+ rest = raw.name.slice(3);
148
+ } else {
149
+ syntax = "on";
150
+ rest = raw.name.slice(2);
151
+ }
152
+ const [raw_name, ...modifiers] = rest.split(".");
153
+ const name = raw_name.toLowerCase();
154
+ for (const m of modifiers) {
155
+ if (!EVENT_MODIFIERS.has(m)) {
156
+ raw.report("invalid-directive", `Unknown event modifier ".${m}" \u2014 expected one of ${[...EVENT_MODIFIERS].join(", ")}`);
157
+ }
158
+ }
159
+ return {
160
+ kind: "EventBinding",
161
+ name,
162
+ syntax,
163
+ modifiers,
164
+ hole: requireHole(raw, "event binding"),
165
+ loc: raw.loc
166
+ };
167
+ }
168
+ },
169
+ // Two-way binding: `bind:value=${signal}`.
170
+ {
171
+ id: "bind",
172
+ elementOnly: true,
173
+ match: (n) => n.startsWith("bind:"),
174
+ build: (raw) => ({
175
+ kind: "BindDirective",
176
+ name: raw.name.slice("bind:".length),
177
+ hole: requireHole(raw, "two-way binding"),
178
+ loc: raw.loc
179
+ })
180
+ },
181
+ // Dynamic class toggle: `class:active=${flag}`.
182
+ {
183
+ id: "class-directive",
184
+ elementOnly: true,
185
+ match: (n) => n.startsWith("class:"),
186
+ build: (raw) => ({
187
+ kind: "ClassDirective",
188
+ name: raw.name.slice("class:".length),
189
+ hole: requireHole(raw, "class directive"),
190
+ loc: raw.loc
191
+ })
192
+ },
193
+ // Dynamic style: `style:color=${c}`.
194
+ {
195
+ id: "style-directive",
196
+ elementOnly: true,
197
+ match: (n) => n.startsWith("style:"),
198
+ build: (raw) => ({
199
+ kind: "StyleDirective",
200
+ name: raw.name.slice("style:".length),
201
+ hole: requireHole(raw, "style directive"),
202
+ loc: raw.loc
203
+ })
204
+ },
205
+ // Load strategy: `load:visible[="200px"]`. Components only, an intrinsic element
206
+ // has no module to defer.
207
+ {
208
+ id: "load",
209
+ match: (n) => n.startsWith("load:"),
210
+ build: (raw) => ({
211
+ kind: "LoadDirective",
212
+ strategy: raw.name.slice("load:".length),
213
+ modifier: raw.value && raw.value.kind === "static" ? raw.value.value : null,
214
+ loc: raw.loc
215
+ })
216
+ },
217
+ // Custom directive: `use=${d}` or `use:tooltip[=${opts}]`.
218
+ {
219
+ id: "use",
220
+ match: (n) => n === "use" || n.startsWith("use:"),
221
+ build: (raw) => {
222
+ const named = raw.name.startsWith("use:");
223
+ return {
224
+ kind: "UseDirective",
225
+ name: named ? raw.name.slice("use:".length) : null,
226
+ hole: raw.value && raw.value.kind === "hole" ? raw.value.hole : null,
227
+ loc: raw.loc
228
+ };
229
+ }
230
+ },
231
+ // Conditional rendering: `if=${cond}`.
232
+ {
233
+ id: "if",
234
+ elementOnly: true,
235
+ match: (n) => n === "if",
236
+ build: (raw) => ({
237
+ kind: "IfDirective",
238
+ hole: requireHole(raw, "if directive"),
239
+ loc: raw.loc
240
+ })
241
+ },
242
+ // Loop rendering: `each=${items}` (a sibling `key` folds in at parse time).
243
+ {
244
+ id: "each",
245
+ elementOnly: true,
246
+ match: (n) => n === "each",
247
+ build: (raw) => ({
248
+ kind: "EachDirective",
249
+ hole: requireHole(raw, "each directive"),
250
+ key: null,
251
+ loc: raw.loc
252
+ })
253
+ },
254
+ // `else` (valueless).
255
+ {
256
+ id: "else",
257
+ elementOnly: true,
258
+ match: (n) => n === "else",
259
+ build: (raw) => {
260
+ if (raw.value !== null) raw.report("invalid-directive", "`else` takes no value");
261
+ return { kind: "ElseDirective", loc: raw.loc };
150
262
  }
263
+ },
264
+ // Ref binding: `ref=${el}`.
265
+ {
266
+ id: "ref",
267
+ match: (n) => n === "ref",
268
+ build: (raw) => ({
269
+ kind: "RefBinding",
270
+ hole: requireHole(raw, "ref binding"),
271
+ loc: raw.loc
272
+ })
273
+ },
274
+ // Property binding: `.currentTime=${t}`.
275
+ {
276
+ id: "property",
277
+ match: (n) => n[0] === ".",
278
+ build: (raw) => ({
279
+ kind: "PropertyBinding",
280
+ name: raw.name.slice(1),
281
+ hole: requireHole(raw, "property binding"),
282
+ loc: raw.loc
283
+ })
284
+ },
285
+ // Boolean attribute (lit `?disabled`): a plain attribute flagged boolean.
286
+ {
287
+ id: "boolean",
288
+ match: (n) => n[0] === "?",
289
+ build: (raw) => attribute(raw, true)
290
+ }
291
+ ];
292
+ function resolveAttribute(raw, directives = CORE_DIRECTIVES, ctx = { component: false }) {
293
+ for (const d of directives) {
294
+ if (d.elementOnly && ctx.component) continue;
295
+ if (d.match(raw.name)) return d.build(raw);
296
+ }
297
+ return attribute(raw, false);
298
+ }
299
+ var SVG_TAGS = /* @__PURE__ */ new Set([
300
+ "svg",
301
+ "path",
302
+ "circle",
303
+ "rect",
304
+ "line",
305
+ "polygon",
306
+ "polyline",
307
+ "ellipse",
308
+ "g",
309
+ "defs",
310
+ "clipPath",
311
+ "text"
312
+ ]);
313
+ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
314
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
315
+ "area",
316
+ "base",
317
+ "br",
318
+ "col",
319
+ "embed",
320
+ "hr",
321
+ "img",
322
+ "input",
323
+ "link",
324
+ "meta",
325
+ "param",
326
+ "source",
327
+ "track",
328
+ "wbr"
329
+ ]);
330
+ function isComponentTag(tag) {
331
+ return tag.length > 0 && (tag[0] !== tag[0].toLowerCase() || tag.includes("."));
332
+ }
333
+ var INTERACTIVE = /* @__PURE__ */ new Set([
334
+ "a",
335
+ "button",
336
+ "input",
337
+ "select",
338
+ "textarea",
339
+ "summary",
340
+ "details",
341
+ "option",
342
+ "label"
343
+ ]);
344
+ var KEY_EVENTS = /* @__PURE__ */ new Set(["keydown", "keyup", "keypress"]);
345
+ function attributeNamed(node, name) {
346
+ return node.attributes.find((a) => "name" in a && a.name === name);
347
+ }
348
+ function hasSpread(node) {
349
+ return node.attributes.some((a) => a.kind === "Spread");
350
+ }
351
+ function staticValue(node, name) {
352
+ const attribute2 = attributeNamed(node, name);
353
+ if (!attribute2 || attribute2.kind !== "Attribute" || !attribute2.value) return void 0;
354
+ const value = attribute2.value;
355
+ return value.kind === "static" ? value.value : void 0;
356
+ }
357
+ function isPresentational(node) {
358
+ const role = staticValue(node, "role");
359
+ if (role === "presentation" || role === "none") return true;
360
+ return staticValue(node, "aria-hidden") === "true";
361
+ }
362
+ function hasEvent(node, predicate) {
363
+ return node.attributes.some((a) => a.kind === "EventBinding" && predicate(a.name));
364
+ }
365
+ function checkAccessibility(root) {
366
+ const out = [];
367
+ const report = (node, code, message) => {
368
+ out.push({ code, message, severity: "warning", loc: node.loc });
151
369
  };
152
- return n(e.children), t;
153
- }
154
- function L(e, t) {
155
- if (w(e)) return;
156
- let i2 = e.tag.toLowerCase();
157
- i2 === "img" && !u(e, "alt") && !H(e) && t(e, "a11y-img-alt", 'An `img` needs an `alt`. Use `alt=""` when the image is decorative.'), i2 === "a" && !u(e, "href") && !u(e, "role") && t(e, "a11y-anchor-href", "An `a` without `href` is not a link. Use a `button` for an action."), i2 === "iframe" && !u(e, "title") && t(e, "a11y-iframe-title", "An `iframe` needs a `title` describing its content.");
158
- let n = v(e, "tabindex") ?? v(e, "tabIndex");
159
- n !== void 0 && Number(n) > 0 && t(e, "a11y-positive-tabindex", "A positive `tabindex` reorders tab navigation for the entire page. Use `0`, or restructure the markup."), !P.has(i2) && A(e, (r) => r === "click") && !u(e, "role") && !A(e, (r) => W.has(r)) && t(e, "a11y-click-without-keyboard", `A click handler on \`${i2}\` is unreachable by keyboard. Use a \`button\`, or add a \`role\` and a key handler.`);
160
- }
161
- var V = /[A-Za-z0-9\-_:@.?]/;
162
- var N = class {
163
- constructor(t, i2) {
370
+ const visit = (nodes) => {
371
+ for (const node of nodes) {
372
+ if (node.kind === "Element") check(node, report);
373
+ const children = "children" in node ? node.children : void 0;
374
+ if (children) visit(children);
375
+ }
376
+ };
377
+ visit(root.children);
378
+ return out;
379
+ }
380
+ function check(node, report) {
381
+ if (hasSpread(node)) return;
382
+ const tag = node.tag.toLowerCase();
383
+ if (tag === "img" && !attributeNamed(node, "alt") && !isPresentational(node)) {
384
+ report(node, "a11y-img-alt", 'An `img` needs an `alt`. Use `alt=""` when the image is decorative.');
385
+ }
386
+ if (tag === "a" && !attributeNamed(node, "href") && !attributeNamed(node, "role")) {
387
+ report(node, "a11y-anchor-href", "An `a` without `href` is not a link. Use a `button` for an action.");
388
+ }
389
+ if (tag === "iframe" && !attributeNamed(node, "title")) {
390
+ report(node, "a11y-iframe-title", "An `iframe` needs a `title` describing its content.");
391
+ }
392
+ const tabindex = staticValue(node, "tabindex") ?? staticValue(node, "tabIndex");
393
+ if (tabindex !== void 0 && Number(tabindex) > 0) {
394
+ report(
395
+ node,
396
+ "a11y-positive-tabindex",
397
+ "A positive `tabindex` reorders tab navigation for the entire page. Use `0`, or restructure the markup."
398
+ );
399
+ }
400
+ if (!INTERACTIVE.has(tag) && hasEvent(node, (name) => name === "click") && !attributeNamed(node, "role") && !hasEvent(node, (name) => KEY_EVENTS.has(name))) {
401
+ report(
402
+ node,
403
+ "a11y-click-without-keyboard",
404
+ `A click handler on \`${tag}\` is unreachable by keyboard. Use a \`button\`, or add a \`role\` and a key handler.`
405
+ );
406
+ }
407
+ }
408
+ var NAME_CHAR = /[A-Za-z0-9\-_:@.?]/;
409
+ var Parser = class {
410
+ constructor(pieces, opts) {
164
411
  this.diagnostics = [];
165
- this.r = new m(t), this.svg = i2.svg ?? false, this.directives = i2.directives ?? f, this.accessibility = i2.accessibility ?? true;
412
+ this.r = new Reader(pieces);
413
+ this.svg = opts.svg ?? false;
414
+ this.directives = opts.directives ?? CORE_DIRECTIVES;
415
+ this.accessibility = opts.accessibility ?? true;
166
416
  }
167
417
  parse() {
168
- let t = this.r.pos(), i2 = [];
169
- for (; !this.r.eof() && (i2.push(...this.parseChildren()), !this.r.eof()); ) {
170
- let r = this.r.pos();
171
- this.consumeCloseTag(), this.report("stray-close-tag", "error", "Close tag without a matching open tag", this.r.span(r));
418
+ const start = this.r.pos();
419
+ const children = [];
420
+ while (!this.r.eof()) {
421
+ children.push(...this.parseChildren());
422
+ if (this.r.eof()) break;
423
+ const s = this.r.pos();
424
+ this.consumeCloseTag();
425
+ this.report("stray-close-tag", "error", "Close tag without a matching open tag", this.r.span(s));
172
426
  }
173
- let n = { kind: "Root", children: i2, loc: this.r.span(t) };
174
- return x(n), this.validateTree(n), this.accessibility && this.diagnostics.push(...B(n)), { root: n, diagnostics: this.diagnostics };
427
+ const root = { kind: "Root", children, loc: this.r.span(start) };
428
+ setParents(root);
429
+ this.validateTree(root);
430
+ if (this.accessibility) {
431
+ this.diagnostics.push(...checkAccessibility(root));
432
+ }
433
+ return { root, diagnostics: this.diagnostics };
175
434
  }
176
- validateTree(t) {
177
- let i2 = (n) => {
178
- let r = null;
179
- for (let s2 of n) s2.kind === "Text" && /^\s*$/.test(s2.value) || (s2.kind === "Element" || s2.kind === "Component" ? (s2.attributes.some((l2) => l2.kind === "ElseDirective") && (r != null && (r.kind === "Element" || r.kind === "Component") && r.attributes.some((a2) => a2.kind === "IfDirective") || this.report("else-without-if", "error", "`else` must immediately follow an element with `if`", s2.loc)), r = s2) : r = null, "children" in s2 && s2.children && i2(s2.children));
435
+ /** Cross-node validation that needs the built tree (sibling relationships). */
436
+ validateTree(root) {
437
+ const visit = (nodes) => {
438
+ let prevBranch = null;
439
+ for (const node of nodes) {
440
+ if (node.kind === "Text" && /^\s*$/.test(node.value)) continue;
441
+ if (node.kind === "Element" || node.kind === "Component") {
442
+ const hasElse = node.attributes.some((a) => a.kind === "ElseDirective");
443
+ if (hasElse) {
444
+ const prevHasIf = prevBranch != null && (prevBranch.kind === "Element" || prevBranch.kind === "Component") && prevBranch.attributes.some((a) => a.kind === "IfDirective");
445
+ if (!prevHasIf) {
446
+ this.report("else-without-if", "error", "`else` must immediately follow an element with `if`", node.loc);
447
+ }
448
+ }
449
+ prevBranch = node;
450
+ } else {
451
+ prevBranch = null;
452
+ }
453
+ if ("children" in node && node.children) visit(node.children);
454
+ }
180
455
  };
181
- i2(t.children);
456
+ visit(root.children);
182
457
  }
458
+ // --- content ------------------------------------------------------------
459
+ /** Parse sibling nodes until EOF or a `</` close the caller must consume. */
183
460
  parseChildren() {
184
- let t = [];
185
- for (; !this.r.eof() && !this.r.startsWith("</"); ) {
461
+ const out = [];
462
+ while (!this.r.eof()) {
463
+ if (this.r.startsWith("</")) break;
186
464
  if (this.r.startsWith("<!--")) {
187
- t.push(this.parseComment());
465
+ out.push(this.parseComment());
188
466
  continue;
189
467
  }
190
468
  if (this.isFragmentStart()) {
191
- t.push(this.parseFragment());
469
+ out.push(this.parseFragment());
192
470
  continue;
193
471
  }
194
472
  if (this.isDynamicTagStart()) {
195
- t.push(this.parseDynamicComponent());
473
+ out.push(this.parseDynamicComponent());
196
474
  continue;
197
475
  }
198
476
  if (this.isTagStart()) {
199
- t.push(this.parseElement());
477
+ out.push(this.parseElement());
200
478
  continue;
201
479
  }
202
480
  if (this.r.atHole()) {
203
- let n = this.r.takeHole(), r = { kind: "Expression", hole: n.index, loc: n.loc };
204
- t.push(r);
481
+ const h = this.r.takeHole();
482
+ const node = { kind: "Expression", hole: h.index, loc: h.loc };
483
+ out.push(node);
205
484
  continue;
206
485
  }
207
- let i2 = this.readText();
208
- i2 && t.push(i2);
486
+ const text = this.readText();
487
+ if (text) out.push(text);
209
488
  }
210
- return t;
489
+ return out;
211
490
  }
212
491
  isTagStart() {
213
492
  return this.r.peek() === "<" && /[A-Za-z]/.test(this.r.peek(1));
@@ -215,239 +494,306 @@ var N = class {
215
494
  isFragmentStart() {
216
495
  return this.r.peek() === "<" && this.r.peek(1) === ">";
217
496
  }
497
+ /** `<${Comp} …>`: a component whose tag is an interpolated expression. */
218
498
  isDynamicTagStart() {
219
499
  return this.r.peek() === "<" && this.r.holeFollows();
220
500
  }
501
+ /** Parse `<${Comp} …/>` or `<${Comp} …>…</${Comp}>` into a dynamic ComponentNode. */
221
502
  parseDynamicComponent() {
222
- let t = this.r.pos();
503
+ const start = this.r.pos();
223
504
  this.r.advance();
224
- let i2 = this.r.takeHole().index, n = this.parseAttributes(true);
505
+ const tagHole = this.r.takeHole().index;
506
+ const attributes = this.parseAttributes(true);
225
507
  this.r.skipWhitespace();
226
- let r = false, s2 = [];
227
- return this.r.startsWith("/>") ? (this.r.advance(), this.r.advance(), r = true) : (this.r.peek() === ">" && this.r.advance(), s2 = this.parseChildren(), this.r.startsWith("</") ? (this.r.advance(), this.r.advance(), this.r.atHole() ? this.r.takeHole() : this.readName(), this.r.skipWhitespace(), this.r.peek() === ">" && this.r.advance()) : this.report("unclosed-tag", "error", "Unclosed dynamic component", this.r.span(t))), { kind: "Component", tag: "", tagHole: i2, attributes: n, children: s2, selfClosing: r, loc: this.r.span(t) };
508
+ let selfClosing = false;
509
+ let children = [];
510
+ if (this.r.startsWith("/>")) {
511
+ this.r.advance();
512
+ this.r.advance();
513
+ selfClosing = true;
514
+ } else {
515
+ if (this.r.peek() === ">") this.r.advance();
516
+ children = this.parseChildren();
517
+ if (this.r.startsWith("</")) {
518
+ this.r.advance();
519
+ this.r.advance();
520
+ if (this.r.atHole()) this.r.takeHole();
521
+ else this.readName();
522
+ this.r.skipWhitespace();
523
+ if (this.r.peek() === ">") this.r.advance();
524
+ } else {
525
+ this.report("unclosed-tag", "error", "Unclosed dynamic component", this.r.span(start));
526
+ }
527
+ }
528
+ return { kind: "Component", tag: "", tagHole, attributes, children, selfClosing, loc: this.r.span(start) };
228
529
  }
530
+ /** A raw text run (preserved verbatim; whitespace is normalized at lowering). */
229
531
  readText() {
230
- let t = this.r.pos(), i2 = "";
231
- for (; !this.r.eof() && !this.r.atHole() && !(this.r.startsWith("</") || this.r.startsWith("<!--") || this.isTagStart() || this.isFragmentStart() || this.isDynamicTagStart()); ) i2 += this.r.advance();
232
- return i2 ? { kind: "Text", value: i2, raw: false, loc: this.r.span(t) } : null;
532
+ const start = this.r.pos();
533
+ let value = "";
534
+ while (!this.r.eof() && !this.r.atHole()) {
535
+ if (this.r.startsWith("</") || this.r.startsWith("<!--") || this.isTagStart() || this.isFragmentStart() || this.isDynamicTagStart()) break;
536
+ value += this.r.advance();
537
+ }
538
+ if (!value) return null;
539
+ return { kind: "Text", value, raw: false, loc: this.r.span(start) };
233
540
  }
234
541
  parseComment() {
235
- let t = this.r.pos();
236
- this.r.advance(), this.r.advance(), this.r.advance(), this.r.advance();
237
- let i2 = "";
238
- for (; !this.r.eof() && !this.r.startsWith("-->"); ) {
542
+ const start = this.r.pos();
543
+ this.r.advance();
544
+ this.r.advance();
545
+ this.r.advance();
546
+ this.r.advance();
547
+ let value = "";
548
+ while (!this.r.eof() && !this.r.startsWith("-->")) {
239
549
  if (this.r.atHole()) {
240
- this.r.takeHole(), i2 += "\0";
550
+ this.r.takeHole();
551
+ value += "\0";
241
552
  continue;
242
553
  }
243
- i2 += this.r.advance();
554
+ value += this.r.advance();
244
555
  }
245
- return this.r.startsWith("-->") ? (this.r.advance(), this.r.advance(), this.r.advance()) : this.report("unclosed-comment", "warning", "Unterminated comment", this.r.span(t)), { kind: "Comment", value: i2, loc: this.r.span(t) };
556
+ if (this.r.startsWith("-->")) {
557
+ this.r.advance();
558
+ this.r.advance();
559
+ this.r.advance();
560
+ } else {
561
+ this.report("unclosed-comment", "warning", "Unterminated comment", this.r.span(start));
562
+ }
563
+ return { kind: "Comment", value, loc: this.r.span(start) };
246
564
  }
247
565
  parseFragment() {
248
- let t = this.r.pos();
249
- this.r.advance(), this.r.advance();
250
- let i2 = this.parseChildren();
566
+ const start = this.r.pos();
567
+ this.r.advance();
568
+ this.r.advance();
569
+ const children = this.parseChildren();
251
570
  if (this.r.startsWith("</")) {
252
- let n = this.consumeCloseTag();
253
- n && this.report("mismatched-close-tag", "error", `Expected </> to close fragment, got </${n}>`, this.r.span(t));
254
- } else this.report("unclosed-tag", "error", "Unterminated fragment", this.r.span(t));
255
- return { kind: "Fragment", children: i2, loc: this.r.span(t) };
571
+ const name = this.consumeCloseTag();
572
+ if (name) this.report("mismatched-close-tag", "error", `Expected </> to close fragment, got </${name}>`, this.r.span(start));
573
+ } else {
574
+ this.report("unclosed-tag", "error", "Unterminated fragment", this.r.span(start));
575
+ }
576
+ return { kind: "Fragment", children, loc: this.r.span(start) };
256
577
  }
257
578
  parseElement() {
258
- let t = this.r.pos();
579
+ const start = this.r.pos();
259
580
  this.r.advance();
260
- let i2 = this.readName(), n = C(i2), r = this.parseAttributes(n);
261
- this.foldEachKey(r, t), this.r.skipWhitespace();
262
- let s2 = i2.toLowerCase(), o = !n && S.has(s2), l2 = !n && T.has(s2), a2 = false, c = [];
263
- if (this.r.startsWith("/>")) this.r.advance(), this.r.advance(), a2 = true;
264
- else if (this.r.peek() === ">" && this.r.advance(), !l2) if (c = o ? this.parseRawText(i2) : this.parseChildren(), this.r.startsWith("</")) {
265
- let g = this.consumeCloseTag();
266
- g && g !== i2 && this.report("mismatched-close-tag", "error", `Expected </${i2}>, got </${g}>`, this.r.span(t));
267
- } else this.report("unclosed-tag", "error", `Unclosed <${i2}>`, this.r.span(t));
268
- let h = this.r.span(t);
269
- if (n) return { kind: "Component", tag: i2, tagHole: null, attributes: r, children: c, selfClosing: a2, loc: h };
270
- let d = this.svg || E.has(i2) ? "svg" : "html";
271
- return { kind: "Element", tag: i2, namespace: d, attributes: r, children: c, selfClosing: a2, rawText: o, loc: h };
272
- }
273
- parseRawText(t) {
274
- let i2 = [], n = "</" + t.toLowerCase(), r = "", s2 = this.r.pos(), o = () => {
275
- r && i2.push({ kind: "Text", value: r, raw: true, loc: this.r.span(s2) }), r = "";
581
+ const tag = this.readName();
582
+ const component = isComponentTag(tag);
583
+ const attributes = this.parseAttributes(component);
584
+ this.foldEachKey(attributes, start);
585
+ this.r.skipWhitespace();
586
+ const lower = tag.toLowerCase();
587
+ const rawText = !component && RAW_TEXT_ELEMENTS.has(lower);
588
+ const isVoid = !component && VOID_ELEMENTS.has(lower);
589
+ let selfClosing = false;
590
+ let children = [];
591
+ if (this.r.startsWith("/>")) {
592
+ this.r.advance();
593
+ this.r.advance();
594
+ selfClosing = true;
595
+ } else {
596
+ if (this.r.peek() === ">") this.r.advance();
597
+ if (!isVoid) {
598
+ children = rawText ? this.parseRawText(tag) : this.parseChildren();
599
+ if (this.r.startsWith("</")) {
600
+ const name = this.consumeCloseTag();
601
+ if (name && name !== tag) {
602
+ this.report("mismatched-close-tag", "error", `Expected </${tag}>, got </${name}>`, this.r.span(start));
603
+ }
604
+ } else {
605
+ this.report("unclosed-tag", "error", `Unclosed <${tag}>`, this.r.span(start));
606
+ }
607
+ }
608
+ }
609
+ const loc = this.r.span(start);
610
+ if (component) {
611
+ return { kind: "Component", tag, tagHole: null, attributes, children, selfClosing, loc };
612
+ }
613
+ const namespace = this.svg || SVG_TAGS.has(tag) ? "svg" : "html";
614
+ return { kind: "Element", tag, namespace, attributes, children, selfClosing, rawText, loc };
615
+ }
616
+ /** Read a raw-text element body: only holes break the text run. */
617
+ parseRawText(tag) {
618
+ const out = [];
619
+ const close = "</" + tag.toLowerCase();
620
+ let text = "";
621
+ let start = this.r.pos();
622
+ const flush = () => {
623
+ if (text) out.push({ kind: "Text", value: text, raw: true, loc: this.r.span(start) });
624
+ text = "";
276
625
  };
277
- for (; !this.r.eof() && !this.startsWithCloseFor(n); ) {
626
+ while (!this.r.eof()) {
627
+ if (this.startsWithCloseFor(close)) break;
278
628
  if (this.r.atHole()) {
279
- o();
280
- let l2 = this.r.takeHole();
281
- i2.push({ kind: "Expression", hole: l2.index, loc: l2.loc }), s2 = this.r.pos();
629
+ flush();
630
+ const h = this.r.takeHole();
631
+ out.push({ kind: "Expression", hole: h.index, loc: h.loc });
632
+ start = this.r.pos();
282
633
  continue;
283
634
  }
284
- r || (s2 = this.r.pos()), r += this.r.advance();
635
+ if (!text) start = this.r.pos();
636
+ text += this.r.advance();
285
637
  }
286
- return o(), i2;
287
- }
288
- startsWithCloseFor(t) {
289
- let i2 = 0;
290
- for (; i2 < t.length; ) {
291
- let n = this.r.peek(i2);
292
- if (n === "" || n.toLowerCase() !== t[i2]) return false;
293
- i2++;
638
+ flush();
639
+ return out;
640
+ }
641
+ startsWithCloseFor(close) {
642
+ let i = 0;
643
+ while (i < close.length) {
644
+ const ch = this.r.peek(i);
645
+ if (ch === "" || ch.toLowerCase() !== close[i]) return false;
646
+ i++;
294
647
  }
295
648
  return true;
296
649
  }
297
- parseAttributes(t) {
298
- let i2 = [];
299
- for (; !this.r.eof() && (this.r.skipWhitespace(), !(this.r.peek() === ">" || this.r.startsWith("/>"))); ) {
650
+ // --- attributes ---------------------------------------------------------
651
+ parseAttributes(component) {
652
+ const props = [];
653
+ while (!this.r.eof()) {
654
+ this.r.skipWhitespace();
655
+ if (this.r.peek() === ">" || this.r.startsWith("/>")) break;
300
656
  if (this.r.atHole()) {
301
- let a2 = this.r.takeHole();
302
- i2.push({ kind: "Spread", hole: a2.index, loc: a2.loc });
657
+ const h = this.r.takeHole();
658
+ props.push({ kind: "Spread", hole: h.index, loc: h.loc });
303
659
  continue;
304
660
  }
305
661
  if (this.r.startsWith("...")) {
306
- let a2 = this.r.pos();
307
- if (this.r.advance(), this.r.advance(), this.r.advance(), this.r.atHole()) {
308
- let c = this.r.takeHole();
309
- i2.push({ kind: "Spread", hole: c.index, loc: this.r.span(a2) });
310
- } else this.report("invalid-binding", "error", "Spread `...` must be followed by ${\u2026}", this.r.span(a2));
662
+ const s = this.r.pos();
663
+ this.r.advance();
664
+ this.r.advance();
665
+ this.r.advance();
666
+ if (this.r.atHole()) {
667
+ const h = this.r.takeHole();
668
+ props.push({ kind: "Spread", hole: h.index, loc: this.r.span(s) });
669
+ } else {
670
+ this.report("invalid-binding", "error", "Spread `...` must be followed by ${\u2026}", this.r.span(s));
671
+ }
311
672
  continue;
312
673
  }
313
- let n = this.r.pos(), r = this.readName();
314
- if (!r) {
674
+ const nameStart = this.r.pos();
675
+ const name = this.readName();
676
+ if (!name) {
315
677
  this.r.advance();
316
678
  continue;
317
679
  }
318
- let s2 = this.r.span(n);
680
+ const nameLoc = this.r.span(nameStart);
319
681
  this.r.skipWhitespace();
320
- let o = null;
321
- this.r.peek() === "=" && (this.r.advance(), this.r.skipWhitespace(), o = this.parseAttrValue());
322
- let l2 = { name: r, nameLoc: s2, value: o, loc: this.r.span(n), report: (a2, c) => this.report(a2, "error", c, this.r.span(n)) };
323
- i2.push(k(l2, this.directives, { component: t }));
682
+ let value = null;
683
+ if (this.r.peek() === "=") {
684
+ this.r.advance();
685
+ this.r.skipWhitespace();
686
+ value = this.parseAttrValue();
687
+ }
688
+ const raw = {
689
+ name,
690
+ nameLoc,
691
+ value,
692
+ loc: this.r.span(nameStart),
693
+ report: (code, message) => this.report(code, "error", message, this.r.span(nameStart))
694
+ };
695
+ props.push(resolveAttribute(raw, this.directives, { component }));
324
696
  }
325
- return i2;
697
+ return props;
326
698
  }
327
699
  parseAttrValue() {
328
- if (this.r.atHole()) return { kind: "hole", hole: this.r.takeHole().index };
329
- let t = this.r.peek();
330
- return t === '"' || t === "'" ? this.classifyParts(this.readQuotedParts(t)) : { kind: "static", value: this.r.readWhile((n) => !/[\s>]/.test(n)) };
700
+ if (this.r.atHole()) {
701
+ const h = this.r.takeHole();
702
+ return { kind: "hole", hole: h.index };
703
+ }
704
+ const quote = this.r.peek();
705
+ if (quote === '"' || quote === "'") {
706
+ return this.classifyParts(this.readQuotedParts(quote));
707
+ }
708
+ const value = this.r.readWhile((ch) => !/[\s>]/.test(ch));
709
+ return { kind: "static", value };
331
710
  }
332
- readQuotedParts(t) {
711
+ readQuotedParts(quote) {
333
712
  this.r.advance();
334
- let i2 = [], n = "";
335
- for (; !this.r.eof() && this.r.peek() !== t; ) {
713
+ const parts = [];
714
+ let text = "";
715
+ while (!this.r.eof() && this.r.peek() !== quote) {
336
716
  if (this.r.atHole()) {
337
- n && (i2.push({ text: n }), n = ""), i2.push({ hole: this.r.takeHole().index });
717
+ if (text) {
718
+ parts.push({ text });
719
+ text = "";
720
+ }
721
+ parts.push({ hole: this.r.takeHole().index });
338
722
  continue;
339
723
  }
340
- let r = this.r.advance();
341
- if (r === "") break;
342
- n += r;
724
+ const ch = this.r.advance();
725
+ if (ch === "") break;
726
+ text += ch;
343
727
  }
344
- return n && i2.push({ text: n }), this.r.peek() === t && this.r.advance(), i2;
345
- }
346
- classifyParts(t) {
347
- let i2 = t.filter((n) => "hole" in n);
348
- return i2.length === 0 ? { kind: "static", value: t.map((n) => "text" in n ? n.text : "").join("") } : t.length === 1 ? { kind: "hole", hole: i2[0].hole } : { kind: "mixed", parts: t };
349
- }
350
- foldEachKey(t, i2) {
351
- let n = null, r = 0, s2 = 0, o = 0, l2 = 0;
352
- for (let d of t) d.kind === "EachDirective" ? (n = d, s2++) : d.kind === "IfDirective" ? r++ : d.kind === "ElseDirective" ? o++ : d.kind === "RefBinding" && l2++;
353
- let a2 = this.r.span(i2);
354
- s2 > 1 && this.report("duplicate-directive", "error", "Multiple `each` directives on one element", a2), r > 1 && this.report("duplicate-directive", "error", "Multiple `if` directives on one element", a2), l2 > 1 && this.report("duplicate-directive", "error", "Multiple `ref` bindings on one element", a2), r > 0 && s2 > 0 && this.report("unsupported-combination", "error", "`if` and `each` cannot both apply to one element \u2014 wrap one in another element", a2), r > 0 && o > 0 && this.report("invalid-directive", "error", "`if` and `else` cannot be on the same element", a2);
355
- let c = t.findIndex((d) => d.kind === "Attribute" && d.name === "key");
356
- if (!n) {
357
- c !== -1 && this.report("invalid-directive", "error", "`key` requires an `each` directive on the same element", a2);
728
+ if (text) parts.push({ text });
729
+ if (this.r.peek() === quote) this.r.advance();
730
+ return parts;
731
+ }
732
+ classifyParts(parts) {
733
+ const holes = parts.filter((p) => "hole" in p);
734
+ if (holes.length === 0) {
735
+ return { kind: "static", value: parts.map((p) => "text" in p ? p.text : "").join("") };
736
+ }
737
+ if (parts.length === 1) return { kind: "hole", hole: holes[0].hole };
738
+ return { kind: "mixed", parts };
739
+ }
740
+ /** Fold `key` into `each`, and validate an element's directive combination. */
741
+ foldEachKey(attrs, elLoc) {
742
+ let each = null;
743
+ let ifCount = 0;
744
+ let eachCount = 0;
745
+ let elseCount = 0;
746
+ let refCount = 0;
747
+ for (const a of attrs) {
748
+ if (a.kind === "EachDirective") {
749
+ each = a;
750
+ eachCount++;
751
+ } else if (a.kind === "IfDirective") ifCount++;
752
+ else if (a.kind === "ElseDirective") elseCount++;
753
+ else if (a.kind === "RefBinding") refCount++;
754
+ }
755
+ const span = this.r.span(elLoc);
756
+ if (eachCount > 1) this.report("duplicate-directive", "error", "Multiple `each` directives on one element", span);
757
+ if (ifCount > 1) this.report("duplicate-directive", "error", "Multiple `if` directives on one element", span);
758
+ if (refCount > 1) this.report("duplicate-directive", "error", "Multiple `ref` bindings on one element", span);
759
+ if (ifCount > 0 && eachCount > 0) {
760
+ this.report("unsupported-combination", "error", "`if` and `each` cannot both apply to one element \u2014 wrap one in another element", span);
761
+ }
762
+ if (ifCount > 0 && elseCount > 0) {
763
+ this.report("invalid-directive", "error", "`if` and `else` cannot be on the same element", span);
764
+ }
765
+ const keyIdx = attrs.findIndex((a) => a.kind === "Attribute" && a.name === "key");
766
+ if (!each) {
767
+ if (keyIdx !== -1) this.report("invalid-directive", "error", "`key` requires an `each` directive on the same element", span);
358
768
  return;
359
769
  }
360
- if (c === -1) return;
361
- let h = t[c];
362
- h.kind === "Attribute" && h.value && (h.value.kind === "static" ? n.key = { static: h.value.value } : h.value.kind === "hole" && (n.key = { hole: h.value.hole })), t.splice(c, 1);
770
+ if (keyIdx === -1) return;
771
+ const key = attrs[keyIdx];
772
+ if (key.kind === "Attribute" && key.value) {
773
+ if (key.value.kind === "static") each.key = { static: key.value.value };
774
+ else if (key.value.kind === "hole") each.key = { hole: key.value.hole };
775
+ }
776
+ attrs.splice(keyIdx, 1);
363
777
  }
778
+ // --- low level ----------------------------------------------------------
364
779
  readName() {
365
- return this.r.readWhile((t) => V.test(t));
780
+ return this.r.readWhile((ch) => NAME_CHAR.test(ch));
366
781
  }
782
+ /** Consume `</name>` (or `</>`), returning the close-tag name (may be ''). */
367
783
  consumeCloseTag() {
368
- this.r.advance(), this.r.advance();
369
- let t = this.readName();
370
- return this.r.skipWhitespace(), this.r.peek() === ">" && this.r.advance(), t;
784
+ this.r.advance();
785
+ this.r.advance();
786
+ const name = this.readName();
787
+ this.r.skipWhitespace();
788
+ if (this.r.peek() === ">") this.r.advance();
789
+ return name;
371
790
  }
372
- report(t, i2, n, r) {
373
- this.diagnostics.push({ code: t, severity: i2, message: n, loc: r });
791
+ report(code, severity, message, loc) {
792
+ this.diagnostics.push({ code, severity, message, loc });
374
793
  }
375
794
  };
376
- function b(e, t = {}) {
377
- return new N(e, t).parse();
378
- }
379
- function I(e) {
380
- let t = [], i2 = 0;
381
- return e.forEach((n, r) => {
382
- t.push({ kind: "static", text: n, start: i2 }), i2 += n.length, r < e.length - 1 && t.push({ kind: "hole", index: r, start: i2, end: i2 });
383
- }), t;
384
- }
385
- function Q(e, t = {}) {
386
- return b(I(e), t);
387
- }
388
-
389
- // src/collect.ts
390
- var UNUSED_CODES = /* @__PURE__ */ new Set([6133, 6196, 6198, 6199, 6205, 6138, 6192]);
391
- function isUnusedCode(code) {
392
- return UNUSED_CODES.has(code);
393
- }
394
- function usedComponentTags(ts, sourceFile) {
395
- const tags = /* @__PURE__ */ new Set();
396
- const visit = (node) => {
397
- if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && (node.tag.text === "html" || node.tag.text === "svg")) {
398
- collectTags(Q(templateStatics(ts, node.template)).root.children, tags);
399
- }
400
- ts.forEachChild(node, visit);
401
- };
402
- visit(sourceFile);
403
- return tags;
404
- }
405
- function templateStatics(ts, tpl) {
406
- if (ts.isNoSubstitutionTemplateLiteral(tpl)) return [tpl.text];
407
- const out = [tpl.head.text];
408
- for (const span of tpl.templateSpans) out.push(span.literal.text);
409
- return out;
410
- }
411
- function collectTags(nodes, out) {
412
- for (const node of nodes) {
413
- if (node.kind === "Component" && node.tag) out.add(node.tag.split(".")[0]);
414
- if ("children" in node && node.children) collectTags(node.children, out);
415
- }
416
- }
417
- function shouldSuppress(ts, sourceFile, diagnostic, used) {
418
- if (diagnostic.start === void 0 || !isUnusedCode(diagnostic.code)) return false;
419
- const spanText = sourceFile.text.substr(diagnostic.start, diagnostic.length ?? 0);
420
- const decl = importDeclarationAt(ts, sourceFile, diagnostic.start);
421
- if (decl) {
422
- const names = importedNames(ts, decl);
423
- if (names.includes(spanText)) return used.has(spanText);
424
- return names.some((n) => used.has(n));
425
- }
426
- return used.has(spanText);
427
- }
428
- function importDeclarationAt(ts, sourceFile, pos) {
429
- let found;
430
- const visit = (node) => {
431
- if (found) return;
432
- if (ts.isImportDeclaration(node) && node.getStart(sourceFile) <= pos && node.getEnd() >= pos) {
433
- found = node;
434
- return;
435
- }
436
- ts.forEachChild(node, visit);
437
- };
438
- visit(sourceFile);
439
- return found;
440
- }
441
- function importedNames(ts, decl) {
442
- const bindings = decl.importClause?.namedBindings;
443
- const names = [];
444
- if (decl.importClause?.name) names.push(decl.importClause.name.text);
445
- if (bindings && ts.isNamedImports(bindings)) {
446
- for (const el of bindings.elements) names.push(el.name.text);
447
- } else if (bindings && ts.isNamespaceImport(bindings)) {
448
- names.push(bindings.name.text);
449
- }
450
- return names;
795
+ function parseTemplate(pieces, opts = {}) {
796
+ return new Parser(pieces, opts).parse();
451
797
  }
452
798
 
453
799
  // src/pieces.ts
@@ -463,9 +809,9 @@ function templatePieces(ts, tpl, sf) {
463
809
  const pieces = [
464
810
  { kind: "static", text: rawContent(ts, tpl.head, sf), start: tpl.head.getStart(sf) + 1 }
465
811
  ];
466
- tpl.templateSpans.forEach((span, i2) => {
812
+ tpl.templateSpans.forEach((span, i) => {
467
813
  const e = span.expression;
468
- pieces.push({ kind: "hole", index: i2, start: e.getStart(sf), end: e.getEnd() });
814
+ pieces.push({ kind: "hole", index: i, start: e.getStart(sf), end: e.getEnd() });
469
815
  pieces.push({
470
816
  kind: "static",
471
817
  text: rawContent(ts, span.literal, sf),
@@ -486,14 +832,22 @@ function parseCached(ts, sf, tpl) {
486
832
  const key = tpl.getStart(sf);
487
833
  const hit = byTemplate.get(key);
488
834
  if (hit) return hit;
489
- const result = b(templatePieces(ts, tpl, sf));
835
+ const result = parseTemplate(templatePieces(ts, tpl, sf));
490
836
  byTemplate.set(key, result);
491
837
  return result;
492
838
  }
493
839
  var templates = /* @__PURE__ */ new WeakMap();
840
+ function mayHaveTemplate(text) {
841
+ return text.includes("html`") || text.includes("svg`");
842
+ }
843
+ var NONE = [];
494
844
  function templatesIn(ts, sf) {
495
845
  const hit = templates.get(sf);
496
846
  if (hit) return hit;
847
+ if (!mayHaveTemplate(sf.text)) {
848
+ templates.set(sf, NONE);
849
+ return NONE;
850
+ }
497
851
  const found = [];
498
852
  const visit = (node) => {
499
853
  if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && (node.tag.text === "html" || node.tag.text === "svg")) {
@@ -502,7 +856,7 @@ function templatesIn(ts, sf) {
502
856
  ts.forEachChild(node, visit);
503
857
  };
504
858
  visit(sf);
505
- found.sort((a2, b2) => a2.getStart(sf) - b2.getStart(sf));
859
+ found.sort((a, b) => a.getStart(sf) - b.getStart(sf));
506
860
  templates.set(sf, found);
507
861
  return found;
508
862
  }
@@ -516,22 +870,101 @@ function templateAtCached(ts, sf, pos) {
516
870
  return match;
517
871
  }
518
872
 
873
+ // src/collect.ts
874
+ var UNUSED_CODES = /* @__PURE__ */ new Set([6133, 6196, 6198, 6199, 6205, 6138, 6192]);
875
+ function isUnusedCode(code) {
876
+ return UNUSED_CODES.has(code);
877
+ }
878
+ var tagCache = /* @__PURE__ */ new WeakMap();
879
+ function usedComponentTags(ts, sourceFile) {
880
+ const hit = tagCache.get(sourceFile);
881
+ if (hit) return hit;
882
+ const tags = /* @__PURE__ */ new Set();
883
+ for (const template of templatesIn(ts, sourceFile)) {
884
+ collectTags(parseCached(ts, sourceFile, template.template).root.children, tags);
885
+ }
886
+ tagCache.set(sourceFile, tags);
887
+ return tags;
888
+ }
889
+ function collectTags(nodes, out) {
890
+ for (const node of nodes) {
891
+ if (node.kind === "Component" && node.tag) out.add(node.tag.split(".")[0]);
892
+ if ("children" in node && node.children) collectTags(node.children, out);
893
+ }
894
+ }
895
+ function shouldSuppress(ts, sourceFile, diagnostic, used) {
896
+ if (diagnostic.start === void 0 || !isUnusedCode(diagnostic.code)) return false;
897
+ const spanText = sourceFile.text.substr(diagnostic.start, diagnostic.length ?? 0);
898
+ const decl = importDeclarationAt(ts, sourceFile, diagnostic.start);
899
+ if (decl) {
900
+ const names = importedNames(ts, decl);
901
+ if (names.includes(spanText)) return used.has(spanText);
902
+ return names.some((n) => used.has(n));
903
+ }
904
+ return used.has(spanText);
905
+ }
906
+ function importDeclarationAt(ts, sourceFile, pos) {
907
+ let found;
908
+ const visit = (node) => {
909
+ if (found) return;
910
+ if (ts.isImportDeclaration(node) && node.getStart(sourceFile) <= pos && node.getEnd() >= pos) {
911
+ found = node;
912
+ return;
913
+ }
914
+ ts.forEachChild(node, visit);
915
+ };
916
+ visit(sourceFile);
917
+ return found;
918
+ }
919
+ function importedNames(ts, decl) {
920
+ const bindings = decl.importClause?.namedBindings;
921
+ const names = [];
922
+ if (decl.importClause?.name) names.push(decl.importClause.name.text);
923
+ if (bindings && ts.isNamedImports(bindings)) {
924
+ for (const el of bindings.elements) names.push(el.name.text);
925
+ } else if (bindings && ts.isNamespaceImport(bindings)) {
926
+ names.push(bindings.name.text);
927
+ }
928
+ return names;
929
+ }
930
+
519
931
  // ../compiler/dist/resolve/builtins.mjs
520
- var s = ["Show", "For", "Index", "Switch", "Match", "Portal", "Dynamic", "ErrorBoundary"];
521
- var i = ["Suspense", "SuspenseList", "Await"];
522
- var u2 = ["Router", "Outlet", "Redirect", "Link"];
523
- var p2 = [...s, ...i, ...u2];
524
- var a = /* @__PURE__ */ new Set([...s, ...i]);
525
- function l(o = {}) {
526
- let { controlFlowModule: e = "@fluixi/dom", coreModule: r = "@fluixi/core", routerModule: c = "@fluixi/core/router-next" } = o, n = {};
527
- for (let t of s) n[t] = e;
528
- for (let t of i) n[t] = r;
529
- for (let t of u2) n[t] = c;
530
- return n;
932
+ var DOM_CONTROL_FLOW = [
933
+ "Show",
934
+ "For",
935
+ "Index",
936
+ "Switch",
937
+ "Match",
938
+ "Portal",
939
+ "Dynamic",
940
+ "ErrorBoundary"
941
+ ];
942
+ var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
943
+ var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
944
+ var BUILTIN_COMPONENTS = [
945
+ ...DOM_CONTROL_FLOW,
946
+ ...CORE_CONTROL_FLOW,
947
+ ...ROUTER_COMPONENTS
948
+ ];
949
+ var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
950
+ ...DOM_CONTROL_FLOW,
951
+ ...CORE_CONTROL_FLOW
952
+ ]);
953
+ function builtinComponentMap(modules = {}) {
954
+ const {
955
+ controlFlowModule = "@fluixi/dom",
956
+ coreModule = "@fluixi/core",
957
+ routerModule = "@fluixi/core/router"
958
+ } = modules;
959
+ const map = {};
960
+ for (const name of DOM_CONTROL_FLOW) map[name] = controlFlowModule;
961
+ for (const name of CORE_CONTROL_FLOW) map[name] = coreModule;
962
+ for (const name of ROUTER_COMPONENTS) map[name] = routerModule;
963
+ return map;
531
964
  }
532
965
 
533
966
  // src/auto-import.ts
534
- var AUTO_IMPORTED = l();
967
+ var AUTO_IMPORTED = builtinComponentMap();
535
968
  var exportsByProgram = /* @__PURE__ */ new WeakMap();
536
969
  function moduleExports(ts, program, host, from, moduleName) {
537
970
  let cache2 = exportsByProgram.get(program);
@@ -604,7 +1037,7 @@ function findExport(ts, host, options, fileName, name, depth) {
604
1037
  return void 0;
605
1038
  }
606
1039
  function declaredName(ts, statement, name) {
607
- const exported = ts.canHaveModifiers(statement) ? ts.getModifiers(statement)?.some((m2) => m2.kind === ts.SyntaxKind.ExportKeyword) : false;
1040
+ const exported = ts.canHaveModifiers(statement) ? ts.getModifiers(statement)?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) : false;
608
1041
  if (!exported) return void 0;
609
1042
  if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name?.text === name) {
610
1043
  return statement.name;
@@ -627,7 +1060,7 @@ function resolveRelative(ts, host, options, from, specifier) {
627
1060
  function autoImportedSymbol(ts, program, host, from, name) {
628
1061
  const moduleName = AUTO_IMPORTED[name];
629
1062
  if (!moduleName) return void 0;
630
- const symbol = moduleExports(ts, program, host, from, moduleName)?.find((s2) => s2.name === name);
1063
+ const symbol = moduleExports(ts, program, host, from, moduleName)?.find((s) => s.name === name);
631
1064
  if (!symbol) return void 0;
632
1065
  if (!(symbol.flags & ts.SymbolFlags.Alias)) return symbol;
633
1066
  try {
@@ -648,7 +1081,7 @@ function componentQuickInfo(ts, ls, host, fileName, position) {
648
1081
  if (!hit) return void 0;
649
1082
  const checker = program.getTypeChecker();
650
1083
  const flags = ts.SymbolFlags.Value | ts.SymbolFlags.Function | ts.SymbolFlags.Class | ts.SymbolFlags.Alias;
651
- const symbol = checker.getSymbolsInScope(template, flags).find((s2) => s2.name === hit.name) ?? autoImportedSymbol(ts, program, host, sf, hit.name);
1084
+ const symbol = checker.getSymbolsInScope(template, flags).find((s) => s.name === hit.name) ?? autoImportedSymbol(ts, program, host, sf, hit.name);
652
1085
  const decl = symbol?.valueDeclaration ?? symbol?.declarations?.[0];
653
1086
  if (!decl) return void 0;
654
1087
  const declFile = decl.getSourceFile();
@@ -785,21 +1218,21 @@ function holeRoles(nodes, out) {
785
1218
  };
786
1219
  for (const node of nodes) {
787
1220
  if (node.kind === "Element" || node.kind === "Component") {
788
- for (const a2 of node.attributes) {
789
- if (a2.kind === "EventBinding") out.set(a2.hole, { kind: "event", event: a2.name.toLowerCase() });
790
- if (node.kind === "Element" && a2.kind === "RefBinding") out.set(a2.hole, { kind: "refEl", tag: node.tag });
791
- if (node.kind === "Element" && a2.kind === "UseDirective" && a2.hole != null) out.set(a2.hole, { kind: "refEl", tag: node.tag });
1221
+ for (const a of node.attributes) {
1222
+ if (a.kind === "EventBinding") out.set(a.hole, { kind: "event", event: a.name.toLowerCase() });
1223
+ if (node.kind === "Element" && a.kind === "RefBinding") out.set(a.hole, { kind: "refEl", tag: node.tag });
1224
+ if (node.kind === "Element" && a.kind === "UseDirective" && a.hole != null) out.set(a.hole, { kind: "refEl", tag: node.tag });
792
1225
  }
793
- const eachDir = node.attributes.find((a2) => a2.kind === "EachDirective");
1226
+ const eachDir = node.attributes.find((a) => a.kind === "EachDirective");
794
1227
  if (eachDir && eachDir.kind === "EachDirective") {
795
1228
  renderChildren(node, { kind: "each", eachHole: eachDir.hole });
796
1229
  }
797
1230
  if (node.kind === "Component") {
798
1231
  const propHole = (name) => {
799
- const a2 = node.attributes.find(
800
- (x2) => x2.kind === "Attribute" && x2.name === name && x2.value != null && x2.value.kind === "hole"
1232
+ const a = node.attributes.find(
1233
+ (x) => x.kind === "Attribute" && x.name === name && x.value != null && x.value.kind === "hole"
801
1234
  );
802
- return a2 && a2.kind === "Attribute" && a2.value && a2.value.kind === "hole" ? a2.value.hole : void 0;
1235
+ return a && a.kind === "Attribute" && a.value && a.value.kind === "hole" ? a.value.hole : void 0;
803
1236
  };
804
1237
  const eachHole = propHole("each");
805
1238
  if (node.tag === "For" && eachHole !== void 0) renderChildren(node, { kind: "each", eachHole });
@@ -812,7 +1245,7 @@ function holeRoles(nodes, out) {
812
1245
  }
813
1246
  }
814
1247
  function resolveGlobalType(ts, checker, location, name) {
815
- const sym = checker.getSymbolsInScope(location, ts.SymbolFlags.Type).find((s2) => s2.getName() === name);
1248
+ const sym = checker.getSymbolsInScope(location, ts.SymbolFlags.Type).find((s) => s.getName() === name);
816
1249
  return sym ? checker.getDeclaredTypeOfSymbol(sym) : void 0;
817
1250
  }
818
1251
  function resolveElementType(ts, checker, location, tag) {
@@ -825,7 +1258,7 @@ function inferParamAt(ts, program, sf, position) {
825
1258
  const template = templateAtCached(ts, sf, position);
826
1259
  if (!template || ts.isNoSubstitutionTemplateLiteral(template.template)) return void 0;
827
1260
  const spans = template.template.templateSpans;
828
- const holeExprs = spans.map((s2) => s2.expression);
1261
+ const holeExprs = spans.map((s) => s.expression);
829
1262
  const holeIndex = holeExprs.findIndex((e) => position >= e.getStart(sf) && position <= e.getEnd());
830
1263
  if (holeIndex === -1) return void 0;
831
1264
  const roles = /* @__PURE__ */ new Map();
@@ -874,7 +1307,7 @@ function inferParamsIn(ts, program, sf) {
874
1307
  for (const template of templatesIn(ts, sf)) {
875
1308
  const tpl = template.template;
876
1309
  if (ts.isNoSubstitutionTemplateLiteral(tpl)) continue;
877
- const holeExprs = tpl.templateSpans.map((s2) => s2.expression);
1310
+ const holeExprs = tpl.templateSpans.map((s) => s.expression);
878
1311
  const roles = /* @__PURE__ */ new Map();
879
1312
  holeRoles(parseCached(ts, sf, tpl).root.children, roles);
880
1313
  for (const [holeIndex, role] of roles) {
@@ -949,8 +1382,8 @@ function componentPropCompletions(ts, ls, host, fileName, position) {
949
1382
  if (!propsType) return void 0;
950
1383
  const already = new Set(comp.attributeNames);
951
1384
  const entries = [];
952
- for (const p3 of propsType.getProperties()) {
953
- const name = p3.getName();
1385
+ for (const p of propsType.getProperties()) {
1386
+ const name = p.getName();
954
1387
  if (name === "children" || already.has(name)) continue;
955
1388
  entries.push(propEntry(ts, name, span));
956
1389
  }
@@ -1004,10 +1437,10 @@ function propNameAt(ts, sf, tpl, position) {
1004
1437
  for (const node of nodes) {
1005
1438
  if (node.kind === "Component") {
1006
1439
  const c = node;
1007
- for (const a2 of c.attributes) {
1008
- if ((a2.kind === "Attribute" || a2.kind === "PropertyBinding" || a2.kind === "BindDirective") && "loc" in a2) {
1009
- const start = a2.loc.start;
1010
- if (position >= start && position <= start + a2.name.length) hit = { tag: c.tag, prop: a2.name, start };
1440
+ for (const a of c.attributes) {
1441
+ if ((a.kind === "Attribute" || a.kind === "PropertyBinding" || a.kind === "BindDirective") && "loc" in a) {
1442
+ const start = a.loc.start;
1443
+ if (position >= start && position <= start + a.name.length) hit = { tag: c.tag, prop: a.name, start };
1011
1444
  }
1012
1445
  }
1013
1446
  }
@@ -1052,7 +1485,7 @@ function propEntry(ts, name, replacementSpan) {
1052
1485
  sortText: "0_" + name,
1053
1486
  insertText: name,
1054
1487
  // Without a span the editor filters these against whatever word *it* computes at the
1055
- // cursor, and inside a template literal that is not the attribute name — so the list
1488
+ // cursor, and inside a template literal that is not the attribute name, so the list
1056
1489
  // showed in full until the first keystroke and then emptied. Saying exactly which
1057
1490
  // characters are being replaced makes filtering match what is typed.
1058
1491
  replacementSpan
@@ -1068,7 +1501,7 @@ function attrNameSpan(text, position) {
1068
1501
  }
1069
1502
  function componentTypeOf(ts, program, checker, host, sf, template, name) {
1070
1503
  const flags = ts.SymbolFlags.Value | ts.SymbolFlags.Function | ts.SymbolFlags.Class | ts.SymbolFlags.Alias;
1071
- const symbol = checker.getSymbolsInScope(template, flags).find((s2) => s2.name === name) ?? autoImportedSymbol(ts, program, host, sf, name);
1504
+ const symbol = checker.getSymbolsInScope(template, flags).find((s) => s.name === name) ?? autoImportedSymbol(ts, program, host, sf, name);
1072
1505
  if (!symbol) return void 0;
1073
1506
  const resolved = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
1074
1507
  const decl = resolved.valueDeclaration ?? resolved.declarations?.[0];
@@ -1076,8 +1509,8 @@ function componentTypeOf(ts, program, checker, host, sf, template, name) {
1076
1509
  }
1077
1510
  function firstParamType(ts, checker, type) {
1078
1511
  for (const sig of checker.getSignaturesOfType(type, ts.SignatureKind.Call)) {
1079
- const p3 = sig.getParameters()[0];
1080
- if (p3) return checker.getTypeOfSymbolAtLocation(p3, p3.valueDeclaration ?? sig.getDeclaration());
1512
+ const p = sig.getParameters()[0];
1513
+ if (p) return checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration ?? sig.getDeclaration());
1081
1514
  }
1082
1515
  return void 0;
1083
1516
  }
@@ -1108,8 +1541,8 @@ function firstChildOrCloseStart(c) {
1108
1541
  }
1109
1542
  function attributeNames(c) {
1110
1543
  const out = [];
1111
- for (const a2 of c.attributes) {
1112
- if (a2.kind === "Attribute" || a2.kind === "PropertyBinding" || a2.kind === "BindDirective") out.push(a2.name);
1544
+ for (const a of c.attributes) {
1545
+ if (a.kind === "Attribute" || a.kind === "PropertyBinding" || a.kind === "BindDirective") out.push(a.name);
1113
1546
  }
1114
1547
  return out;
1115
1548
  }
@@ -1126,13 +1559,13 @@ function paramMemberCompletions(ts, ls, fileName, position) {
1126
1559
  const checker = program.getTypeChecker();
1127
1560
  const already = /* @__PURE__ */ new Set();
1128
1561
  const entries = [];
1129
- for (const p3 of checker.getApparentType(info.type).getProperties()) {
1130
- const name = p3.getName();
1562
+ for (const p of checker.getApparentType(info.type).getProperties()) {
1563
+ const name = p.getName();
1131
1564
  if (already.has(name) || name.startsWith("__")) continue;
1132
1565
  already.add(name);
1133
1566
  entries.push({
1134
1567
  name,
1135
- kind: memberKind(ts, p3),
1568
+ kind: memberKind(ts, p),
1136
1569
  kindModifiers: "",
1137
1570
  sortText: "0_" + name,
1138
1571
  insertText: name
@@ -1220,8 +1653,8 @@ function elementAtAttributeArea(ts, sf, tpl, position) {
1220
1653
  const openEnd = firstAttributeEnd(el);
1221
1654
  if (position > openStart && position <= openEnd) {
1222
1655
  const present = /* @__PURE__ */ new Set();
1223
- for (const a2 of el.attributes) {
1224
- if ("loc" in a2 && a2.loc) present.add(writtenName(sf.text, a2.loc.start));
1656
+ for (const a of el.attributes) {
1657
+ if ("loc" in a && a.loc) present.add(writtenName(sf.text, a.loc.start));
1225
1658
  }
1226
1659
  hit = { tag: el.tag, present };
1227
1660
  }
@@ -1240,8 +1673,8 @@ function writtenName(text, start) {
1240
1673
  }
1241
1674
  function firstAttributeEnd(el) {
1242
1675
  let end = el.loc.start + 1 + el.tag.length;
1243
- for (const a2 of el.attributes) {
1244
- if ("loc" in a2 && a2.loc) end = Math.max(end, a2.loc.end);
1676
+ for (const a of el.attributes) {
1677
+ if ("loc" in a && a.loc) end = Math.max(end, a.loc.end);
1245
1678
  }
1246
1679
  return end + 1;
1247
1680
  }
@@ -1256,8 +1689,8 @@ function elementAttributeCompletions(ts, ls, host, fileName, position) {
1256
1689
  const props = attributesFor(ts, program, host, sf, hit.tag);
1257
1690
  if (!props) return void 0;
1258
1691
  const entries = [];
1259
- for (const p3 of props) {
1260
- const name = p3.getName();
1692
+ for (const p of props) {
1693
+ const name = p.getName();
1261
1694
  if (name === "children" || hit.present.has(name)) continue;
1262
1695
  entries.push({
1263
1696
  name,
@@ -1275,9 +1708,9 @@ function attributeNameAt(ts, sf, tpl, position) {
1275
1708
  for (const node of nodes) {
1276
1709
  if (node.kind === "Element") {
1277
1710
  const el = node;
1278
- for (const a2 of el.attributes) {
1279
- if (!("loc" in a2) || !a2.loc) continue;
1280
- const start = a2.loc.start;
1711
+ for (const a of el.attributes) {
1712
+ if (!("loc" in a) || !a.loc) continue;
1713
+ const start = a.loc.start;
1281
1714
  const name = writtenName(sf.text, start);
1282
1715
  if (name && position >= start && position <= start + name.length) {
1283
1716
  hit = { tag: el.tag, name, start };
@@ -1300,7 +1733,7 @@ function elementAttributeHover(ts, ls, host, fileName, position) {
1300
1733
  const hit = attributeNameAt(ts, sf, tpl.template, position);
1301
1734
  if (!hit) return void 0;
1302
1735
  const props = attributesFor(ts, program, host, sf, hit.tag);
1303
- const symbol = props?.find((p3) => p3.getName() === hit.name);
1736
+ const symbol = props?.find((p) => p.getName() === hit.name);
1304
1737
  if (!symbol) return void 0;
1305
1738
  const decl = symbol.valueDeclaration ?? symbol.declarations?.[0];
1306
1739
  if (!decl) return void 0;
@@ -1340,7 +1773,7 @@ function accessorDiagnostics(ts, program, sf) {
1340
1773
  for (const template of templatesIn(ts, sf)) {
1341
1774
  const tpl = template.template;
1342
1775
  if (ts.isNoSubstitutionTemplateLiteral(tpl)) continue;
1343
- const holes = tpl.templateSpans.map((s2) => s2.expression);
1776
+ const holes = tpl.templateSpans.map((s) => s.expression);
1344
1777
  const visit = (nodes, parent) => {
1345
1778
  for (const node of nodes) {
1346
1779
  if (node.kind === "Expression" && parent?.kind === "Element") {
@@ -1373,7 +1806,7 @@ function isAccessor(ts, checker, node) {
1373
1806
  const signatures = checker.getTypeAtLocation(node).getCallSignatures();
1374
1807
  if (signatures.length !== 1) return false;
1375
1808
  const signature = signatures[0];
1376
- if (signature.getParameters().some((p3) => !isOptional(ts, p3))) return false;
1809
+ if (signature.getParameters().some((p) => !isOptional(ts, p))) return false;
1377
1810
  const returned = signature.getReturnType();
1378
1811
  return !(returned.flags & (ts.TypeFlags.Void | ts.TypeFlags.Never));
1379
1812
  }
@@ -1450,10 +1883,392 @@ function templateFixAll(ts, ls, fileName, errorCodes) {
1450
1883
  textChanges.push({ span: { start: at, length: 0 }, newText: "()" });
1451
1884
  }
1452
1885
  if (textChanges.length === 0) return void 0;
1453
- textChanges.sort((a2, b2) => b2.span.start - a2.span.start);
1886
+ textChanges.sort((a, b) => b.span.start - a.span.start);
1454
1887
  return { changes: [{ fileName, textChanges }], commands: void 0 };
1455
1888
  }
1456
1889
 
1890
+ // src/rules.ts
1891
+ var RULE = {
1892
+ envNotPublic: 9101,
1893
+ serverReadInBrowser: 9102,
1894
+ importMetaEnv: 9103,
1895
+ secretInEnvPublic: 9104,
1896
+ secretInBrowser: 9105,
1897
+ audienceUnchecked: 9106,
1898
+ weakAlgorithm: 9107,
1899
+ dpopBareVerify: 9108,
1900
+ guardWithoutRoles: 9109,
1901
+ weakCookie: 9110,
1902
+ localStorageTokens: 9111
1903
+ };
1904
+ var SECRETISH = /(SECRET|PASSWORD|PASSWD|PRIVATE_KEY|CLIENT_SECRET|CREDENTIALS?)($|_)/;
1905
+ var VITE_BUILTINS = /* @__PURE__ */ new Set(["DEV", "PROD", "SSR", "MODE", "BASE_URL"]);
1906
+ function isServerFile(fileName) {
1907
+ const f = fileName.replace(/\\/g, "/");
1908
+ return /\.server\.[cm]?[jt]sx?$/.test(f) || /\/src\/api\//.test(f) || /\/src\/middleware\.[cm]?[jt]s$/.test(f) || /\/(fluixi|vite)\.config\.[cm]?[jt]s$/.test(f) || /\/src\/entry-server\.[cm]?[jt]sx?$/.test(f) || // Tests run under Node, never in a page.
1909
+ /\.(spec|test)\.[cm]?[jt]sx?$/.test(f) || /\/(tests?|__tests__)\//.test(f);
1910
+ }
1911
+ function importsOf(ts, sf) {
1912
+ const out = /* @__PURE__ */ new Map();
1913
+ for (const stmt of sf.statements) {
1914
+ if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier)) continue;
1915
+ const bindings = stmt.importClause?.namedBindings;
1916
+ if (!bindings || !ts.isNamedImports(bindings)) continue;
1917
+ for (const el of bindings.elements) {
1918
+ out.set(el.name.text, { module: stmt.moduleSpecifier.text, name: (el.propertyName ?? el.name).text });
1919
+ }
1920
+ }
1921
+ return out;
1922
+ }
1923
+ function sideOf(ts, test) {
1924
+ if (ts.isParenthesizedExpression(test)) return sideOf(ts, test.expression);
1925
+ if (ts.isPrefixUnaryExpression(test) && test.operator === ts.SyntaxKind.ExclamationToken) {
1926
+ const inner = sideOf(ts, test.operand);
1927
+ return inner === "server" ? "browser" : inner === "browser" ? "server" : null;
1928
+ }
1929
+ if (ts.isPropertyAccessExpression(test) && test.name.text === "SSR" && ts.isPropertyAccessExpression(test.expression) && test.expression.name.text === "env" && ts.isMetaProperty(test.expression.expression)) {
1930
+ return "server";
1931
+ }
1932
+ if (ts.isBinaryExpression(test)) {
1933
+ const op = test.operatorToken.kind;
1934
+ const eq = op === ts.SyntaxKind.EqualsEqualsEqualsToken || op === ts.SyntaxKind.EqualsEqualsToken;
1935
+ const ne = op === ts.SyntaxKind.ExclamationEqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken;
1936
+ if (!eq && !ne) return null;
1937
+ const typeofGlobal = (n) => ts.isTypeOfExpression(n) && ts.isIdentifier(n.expression) && ["window", "document"].includes(n.expression.text);
1938
+ const undef = (n) => ts.isStringLiteral(n) && n.text === "undefined";
1939
+ if (typeofGlobal(test.left) && undef(test.right) || typeofGlobal(test.right) && undef(test.left)) {
1940
+ return eq ? "server" : "browser";
1941
+ }
1942
+ }
1943
+ return null;
1944
+ }
1945
+ var isUseServer = (ts, body) => {
1946
+ if (!body || !ts.isBlock(body)) return false;
1947
+ const first = body.statements[0];
1948
+ return !!first && ts.isExpressionStatement(first) && ts.isStringLiteral(first.expression) && first.expression.text === "use server";
1949
+ };
1950
+ function inServerContext(ts, node, sf) {
1951
+ const first = sf.statements[0];
1952
+ if (first && ts.isExpressionStatement(first) && ts.isStringLiteral(first.expression) && first.expression.text === "use server") {
1953
+ return true;
1954
+ }
1955
+ for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent) {
1956
+ if ((ts.isFunctionDeclaration(parent) || ts.isFunctionExpression(parent) || ts.isArrowFunction(parent)) && isUseServer(ts, parent.body)) {
1957
+ return true;
1958
+ }
1959
+ if (ts.isIfStatement(parent) || ts.isConditionalExpression(parent)) {
1960
+ const side = sideOf(ts, ts.isIfStatement(parent) ? parent.expression : parent.condition);
1961
+ const whenTrue = ts.isIfStatement(parent) ? parent.thenStatement : parent.whenTrue;
1962
+ const whenFalse = ts.isIfStatement(parent) ? parent.elseStatement : parent.whenFalse;
1963
+ if (side === "server" && child === whenTrue) return true;
1964
+ if (side === "browser" && child === whenFalse) return true;
1965
+ }
1966
+ if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken && child === parent.right && sideOf(ts, parent.left) === "server") {
1967
+ return true;
1968
+ }
1969
+ }
1970
+ return false;
1971
+ }
1972
+ function publicEnvNames(ts, program, fileName, host) {
1973
+ const checker = program.getTypeChecker();
1974
+ let moduleSymbol;
1975
+ if (host) {
1976
+ const resolved = ts.resolveModuleName("@fluixi/start/env", fileName, program.getCompilerOptions(), host).resolvedModule;
1977
+ const target = resolved && program.getSourceFile(resolved.resolvedFileName);
1978
+ if (target) moduleSymbol = checker.getSymbolAtLocation(target);
1979
+ }
1980
+ moduleSymbol ??= checker.getAmbientModules().find((m) => m.name.replace(/"/g, "") === "@fluixi/start/env");
1981
+ const iface = moduleSymbol && checker.getExportsOfModule(moduleSymbol).find((s) => s.name === "PublicEnv");
1982
+ if (!iface) return null;
1983
+ const names = checker.getPropertiesOfType(checker.getDeclaredTypeOfSymbol(iface)).map((p) => p.name);
1984
+ return names.length ? new Set(names) : null;
1985
+ }
1986
+ var propsOf = (ts, obj) => {
1987
+ const map = /* @__PURE__ */ new Map();
1988
+ for (const p of obj.properties) {
1989
+ if (ts.isPropertyAssignment(p) && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name))) map.set(p.name.text, p);
1990
+ }
1991
+ return map;
1992
+ };
1993
+ var isFalse = (ts, e) => !!e && e.kind === ts.SyntaxKind.FalseKeyword;
1994
+ var OAUTH_CONFIG_CALLS = /* @__PURE__ */ new Set([
1995
+ "createAuthService",
1996
+ "createBrowserClient",
1997
+ "createServerClient",
1998
+ "createServiceClient",
1999
+ "createTokenIntrospector",
2000
+ "oauthRoutes",
2001
+ "authServerModule",
2002
+ "sessionLocals"
2003
+ ]);
2004
+ function envAuthDiagnostics(ts, program, fileName, host) {
2005
+ const sf = program.getSourceFile(fileName);
2006
+ if (!sf || sf.isDeclarationFile || /[\\/]node_modules[\\/]/.test(fileName)) return [];
2007
+ const text = sf.text;
2008
+ const isConfig = /[\\/]fluixi\.config\.[cm]?[jt]s$/.test(fileName);
2009
+ if (!isConfig && !/fluixi|\$env|import\.meta\.env|process\.env/.test(text)) return [];
2010
+ const out = [];
2011
+ const add = (node, code, category, messageText) => out.push({ start: node.getStart(sf), length: node.getWidth(sf), code, category, messageText, source: "fluixi" });
2012
+ const imports = importsOf(ts, sf);
2013
+ const serverFile = isServerFile(fileName);
2014
+ const browserSide = (node) => !serverFile && !inServerContext(ts, node, sf);
2015
+ const fromModule = (callee, prefix) => {
2016
+ if (!ts.isIdentifier(callee)) return null;
2017
+ const hit = imports.get(callee.text);
2018
+ return hit && (hit.module === prefix || hit.module.startsWith(prefix + "/")) ? hit.name : null;
2019
+ };
2020
+ let publicNames;
2021
+ const isPublic = (key) => {
2022
+ if (publicNames === void 0) publicNames = publicEnvNames(ts, program, fileName, host);
2023
+ return publicNames === null || publicNames.has(key) || key.startsWith("VITE_");
2024
+ };
2025
+ const envNotPublic = (lit) => {
2026
+ if (!browserSide(lit) || isPublic(lit.text)) return;
2027
+ add(
2028
+ lit,
2029
+ RULE.envNotPublic,
2030
+ ts.DiagnosticCategory.Warning,
2031
+ `${lit.text} is not in env.public, so the browser has no value for it, and the build refuses this read in browser code. If it is public, add it to env.public in fluixi.config.ts. If it is a secret, read it on the server and pass the page what it needs.`
2032
+ );
2033
+ };
2034
+ const dpopVerifiers = /* @__PURE__ */ new Set();
2035
+ const guardsWithoutRoles = /* @__PURE__ */ new Set();
2036
+ const visit = (node) => {
2037
+ if (ts.isCallExpression(node)) {
2038
+ const callee = node.expression;
2039
+ const envFn = ts.isIdentifier(callee) && callee.text === "$env" ? "env" : fromModule(callee, "@fluixi/start");
2040
+ const oauthFn = fromModule(callee, "@fluixi/oauth2");
2041
+ const sessionFn = fromModule(callee, "@fluixi/session");
2042
+ const arg0 = node.arguments[0];
2043
+ if (envFn === "env" && arg0 && ts.isStringLiteral(arg0)) envNotPublic(arg0);
2044
+ if (envFn === "pickEnv" && arg0 && ts.isObjectLiteralExpression(arg0)) {
2045
+ for (const p of arg0.properties) {
2046
+ if (!ts.isPropertyAssignment(p)) continue;
2047
+ if (ts.isStringLiteral(p.initializer)) envNotPublic(p.initializer);
2048
+ else if (ts.isObjectLiteralExpression(p.initializer)) {
2049
+ const key = propsOf(ts, p.initializer).get("key")?.initializer;
2050
+ if (key && ts.isStringLiteral(key)) envNotPublic(key);
2051
+ }
2052
+ }
2053
+ }
2054
+ if (envFn === "serverEnv" && browserSide(node)) {
2055
+ add(
2056
+ callee,
2057
+ RULE.serverReadInBrowser,
2058
+ ts.DiagnosticCategory.Warning,
2059
+ 'serverEnv() in code the browser runs throws there: server-only values are not in the bundle. Read it in an API route, middleware or a "use server" function.'
2060
+ );
2061
+ }
2062
+ if (ts.isIdentifier(callee) && dpopVerifiers.has(callee.text)) {
2063
+ add(
2064
+ callee,
2065
+ RULE.dpopBareVerify,
2066
+ ts.DiagnosticCategory.Error,
2067
+ `${callee.text} requires DPoP, and a bare token carries no proof, so every call is refused. Use ${callee.text}.fromRequest(request).`
2068
+ );
2069
+ }
2070
+ if (ts.isIdentifier(callee) && guardsWithoutRoles.has(callee.text)) {
2071
+ const req = node.arguments[1];
2072
+ if (req && ts.isObjectLiteralExpression(req)) {
2073
+ const props = propsOf(ts, req);
2074
+ const role = props.get("role") ?? props.get("allRoles");
2075
+ if (role) {
2076
+ add(
2077
+ role.name,
2078
+ RULE.guardWithoutRoles,
2079
+ ts.DiagnosticCategory.Error,
2080
+ `${callee.text} was built without \`roles\`, so a role requirement throws on the first request. Pass one of rolesFrom to createApiGuard.`
2081
+ );
2082
+ }
2083
+ }
2084
+ }
2085
+ const configs = [];
2086
+ if (oauthFn && OAUTH_CONFIG_CALLS.has(oauthFn) || oauthFn === "createTokenVerifier" || sessionFn === "createSessionCookie") {
2087
+ if (arg0 && ts.isObjectLiteralExpression(arg0)) {
2088
+ configs.push(arg0);
2089
+ const nested = propsOf(ts, arg0).get("config")?.initializer;
2090
+ if (oauthFn === "createAuthService" && nested && ts.isObjectLiteralExpression(nested)) configs.push(nested);
2091
+ }
2092
+ }
2093
+ for (const obj of configs) {
2094
+ const props = propsOf(ts, obj);
2095
+ const tokens = props.get("tokens")?.initializer;
2096
+ const browserTokens = tokens && ts.isStringLiteral(tokens) && tokens.text === "browser" || oauthFn === "createBrowserClient";
2097
+ for (const secret of ["clientSecret", "privateKey"]) {
2098
+ const p = props.get(secret);
2099
+ if (p && (browserTokens || browserSide(p) && oauthFn !== "createTokenVerifier")) {
2100
+ add(
2101
+ p.name,
2102
+ RULE.secretInBrowser,
2103
+ ts.DiagnosticCategory.Error,
2104
+ `${secret} in ${browserTokens ? "a tokens: 'browser' client" : "code the browser runs"} ships to every visitor, and anything shipped to a browser is not a secret. A browser client uses PKCE without one; keep ${secret} on the server.`
2105
+ );
2106
+ }
2107
+ }
2108
+ if (oauthFn === "createTokenVerifier") {
2109
+ const audience = props.get("audience");
2110
+ if (audience && isFalse(ts, audience.initializer) && !props.has("authorizedParty") && !props.has("require")) {
2111
+ add(
2112
+ audience,
2113
+ RULE.audienceUnchecked,
2114
+ ts.DiagnosticCategory.Warning,
2115
+ "audience: false with no authorizedParty or require accepts a token minted for any client of the same issuer. Pin authorizedParty to your client id, or check a claim in require."
2116
+ );
2117
+ }
2118
+ const algs = props.get("algorithms")?.initializer;
2119
+ if (algs && ts.isArrayLiteralExpression(algs)) {
2120
+ for (const el of algs.elements) {
2121
+ if (ts.isStringLiteral(el) && (/^HS/.test(el.text) || el.text === "none")) {
2122
+ add(
2123
+ el,
2124
+ RULE.weakAlgorithm,
2125
+ ts.DiagnosticCategory.Error,
2126
+ el.text === "none" ? '"none" accepts an unsigned token as valid.' : `${el.text} verifies with a shared secret; with a provider's public key it lets anyone who has that key sign tokens. Use RS256 or ES256.`
2127
+ );
2128
+ }
2129
+ }
2130
+ }
2131
+ }
2132
+ const cookieKey = props.get(sessionFn === "createSessionCookie" ? "secret" : "cookieSecret");
2133
+ if (cookieKey && ts.isStringLiteral(cookieKey.initializer) && cookieKey.initializer.text.length < 32) {
2134
+ add(
2135
+ cookieKey.initializer,
2136
+ RULE.weakCookie,
2137
+ ts.DiagnosticCategory.Error,
2138
+ "The session cookie is encrypted with a key derived from this, and under 32 characters it is short enough to guess. Read a long random value with serverEnv."
2139
+ );
2140
+ }
2141
+ const secure = props.get(sessionFn === "createSessionCookie" ? "secure" : "secureCookie");
2142
+ if (secure && isFalse(ts, secure.initializer)) {
2143
+ add(
2144
+ secure,
2145
+ RULE.weakCookie,
2146
+ ts.DiagnosticCategory.Warning,
2147
+ "The session cookie will also be sent over plain http. Keep this for local work only: derive it, e.g. from whether the app URL is https."
2148
+ );
2149
+ }
2150
+ const storage = props.get("storage")?.initializer;
2151
+ if (storage && ts.isStringLiteral(storage) && storage.text === "local" && browserTokens) {
2152
+ add(
2153
+ storage,
2154
+ RULE.localStorageTokens,
2155
+ ts.DiagnosticCategory.Suggestion,
2156
+ "storage: 'local' keeps the refresh token after the tab closes, so injected script can reach it for longer. 'session', the default, ends with the tab."
2157
+ );
2158
+ }
2159
+ }
2160
+ }
2161
+ if (ts.isPropertyAccessExpression(node)) {
2162
+ const obj = node.expression;
2163
+ if (ts.isIdentifier(obj) && obj.text === "process" && node.name.text === "env" && browserSide(node)) {
2164
+ add(
2165
+ node,
2166
+ RULE.serverReadInBrowser,
2167
+ ts.DiagnosticCategory.Warning,
2168
+ "process.env does not exist in the browser. Use $env('NAME'), which reads the public set there and anything on the server."
2169
+ );
2170
+ }
2171
+ if (ts.isPropertyAccessExpression(obj) && obj.name.text === "env" && ts.isMetaProperty(obj.expression) && !VITE_BUILTINS.has(node.name.text) && !node.name.text.startsWith("VITE_")) {
2172
+ add(
2173
+ node,
2174
+ RULE.importMetaEnv,
2175
+ ts.DiagnosticCategory.Warning,
2176
+ `import.meta.env.${node.name.text} is undefined in the browser: Vite only defines VITE_ names there. Use $env('${node.name.text}') and declare it in env.public if it is public.`
2177
+ );
2178
+ }
2179
+ }
2180
+ if (/[\\/]fluixi\.config\.[cm]?[jt]s$/.test(fileName) && ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "public" && ts.isArrayLiteralExpression(node.initializer) && ts.isObjectLiteralExpression(node.parent) && ts.isPropertyAssignment(node.parent.parent) && ts.isIdentifier(node.parent.parent.name) && node.parent.parent.name.text === "env") {
2181
+ for (const el of node.initializer.elements) {
2182
+ if (ts.isStringLiteral(el) && SECRETISH.test(el.text)) {
2183
+ add(
2184
+ el,
2185
+ RULE.secretInEnvPublic,
2186
+ ts.DiagnosticCategory.Error,
2187
+ `${el.text} reads like a secret, and env.public puts its value in the browser bundle; the build refuses it. Remove it and read it with serverEnv() on the server. If the name only looks like a secret, set FLUIXI_ALLOW_PUBLIC_SECRETS=true.`
2188
+ );
2189
+ }
2190
+ }
2191
+ }
2192
+ ts.forEachChild(node, visit);
2193
+ };
2194
+ const collect = (node) => {
2195
+ if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer && ts.isCallExpression(node.initializer)) {
2196
+ const fn = fromModule(node.initializer.expression, "@fluixi/oauth2");
2197
+ const opts = node.initializer.arguments[0];
2198
+ if (opts && ts.isObjectLiteralExpression(opts)) {
2199
+ const props = propsOf(ts, opts);
2200
+ if (fn === "createTokenVerifier" && props.get("dpop")?.initializer.kind === ts.SyntaxKind.TrueKeyword) dpopVerifiers.add(node.name.text);
2201
+ if (fn === "createApiGuard" && !props.has("roles") && !opts.properties.some((p) => ts.isSpreadAssignment(p))) {
2202
+ guardsWithoutRoles.add(node.name.text);
2203
+ }
2204
+ }
2205
+ }
2206
+ ts.forEachChild(node, collect);
2207
+ };
2208
+ collect(sf);
2209
+ visit(sf);
2210
+ return out.map((d) => ({ ...d, file: sf }));
2211
+ }
2212
+ var CONFIG_NAMES = ["fluixi.config.ts", "fluixi.config.mts", "fluixi.config.js", "fluixi.config.mjs"];
2213
+ function findConfig(fileName, host) {
2214
+ let dir = fileName.replace(/\\/g, "/").replace(/\/[^/]*$/, "");
2215
+ for (; ; ) {
2216
+ for (const name of CONFIG_NAMES) if (host.fileExists(`${dir}/${name}`)) return `${dir}/${name}`;
2217
+ const up = dir.replace(/\/[^/]*$/, "");
2218
+ if (!up || up === dir) return null;
2219
+ dir = up;
2220
+ }
2221
+ }
2222
+ function envPublicFix(ts, program, fileName, position, host) {
2223
+ const sf = program.getSourceFile(fileName);
2224
+ if (!sf) return null;
2225
+ let literal;
2226
+ const find = (node) => {
2227
+ if (literal || position < node.getFullStart() || position > node.getEnd()) return;
2228
+ if (ts.isStringLiteral(node) && position >= node.getStart(sf) && position <= node.getEnd()) literal = node;
2229
+ else ts.forEachChild(node, find);
2230
+ };
2231
+ find(sf);
2232
+ if (!literal || SECRETISH.test(literal.text)) return null;
2233
+ const configPath = findConfig(fileName, host);
2234
+ const configText = configPath && host.readFile(configPath);
2235
+ if (!configPath || !configText) return null;
2236
+ const config = ts.createSourceFile(configPath, configText, ts.ScriptTarget.Latest, true);
2237
+ let list;
2238
+ const search = (node) => {
2239
+ if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "public" && ts.isArrayLiteralExpression(node.initializer) && ts.isPropertyAssignment(node.parent.parent) && ts.isIdentifier(node.parent.parent.name) && node.parent.parent.name.text === "env") {
2240
+ list = node.initializer;
2241
+ }
2242
+ if (!list) ts.forEachChild(node, search);
2243
+ };
2244
+ search(config);
2245
+ if (!list) return null;
2246
+ const quote = list.elements.find(ts.isStringLiteral)?.getText(config).startsWith('"') ? '"' : "'";
2247
+ const entry = `${quote}${literal.text}${quote}`;
2248
+ const last = list.elements[list.elements.length - 1];
2249
+ let change;
2250
+ if (!last) {
2251
+ change = { span: { start: list.getStart(config) + 1, length: 0 }, newText: entry };
2252
+ } else {
2253
+ const multiline = configText.slice(list.getStart(config), last.getStart(config)).includes("\n");
2254
+ const lineStart = configText.lastIndexOf("\n", last.getStart(config)) + 1;
2255
+ const indent = configText.slice(lineStart, last.getStart(config));
2256
+ const trailingComma = list.elements.hasTrailingComma;
2257
+ const at = trailingComma ? configText.indexOf(",", last.getEnd()) + 1 : last.getEnd();
2258
+ const lead = trailingComma ? "" : ",";
2259
+ change = {
2260
+ span: { start: at, length: 0 },
2261
+ newText: multiline ? `${lead}
2262
+ ${indent}${entry}${trailingComma ? "," : ""}` : `${lead} ${entry}`
2263
+ };
2264
+ }
2265
+ return {
2266
+ fixName: "fluixiAddEnvPublic",
2267
+ description: `Add ${literal.text} to env.public`,
2268
+ changes: [{ fileName: configPath, textChanges: [change] }]
2269
+ };
2270
+ }
2271
+
1457
2272
  // src/navigation.ts
1458
2273
  var spansByFile = /* @__PURE__ */ new WeakMap();
1459
2274
  function tagSpans(ts, sf) {
@@ -1489,12 +2304,12 @@ function closingTagName(text, end, tag) {
1489
2304
  }
1490
2305
  function tagAt(ts, sf, position) {
1491
2306
  if (!templateAtCached(ts, sf, position)) return void 0;
1492
- return tagSpans(ts, sf).find((s2) => position >= s2.start && position <= s2.start + s2.length);
2307
+ return tagSpans(ts, sf).find((s) => position >= s.start && position <= s.start + s.length);
1493
2308
  }
1494
2309
  function symbolFor(ts, program, host, location, name) {
1495
2310
  const checker = program.getTypeChecker();
1496
2311
  const flags = ts.SymbolFlags.Value | ts.SymbolFlags.Function | ts.SymbolFlags.Class | ts.SymbolFlags.Alias;
1497
- const symbol = checker.getSymbolsInScope(location, flags).find((s2) => s2.name === name);
2312
+ const symbol = checker.getSymbolsInScope(location, flags).find((s) => s.name === name);
1498
2313
  if (!symbol) return autoImportedSymbol(ts, program, host, location.getSourceFile(), name);
1499
2314
  return symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
1500
2315
  }
@@ -1584,8 +2399,8 @@ function templateReferences(ts, ls, host, fileName, position) {
1584
2399
  if (!program || !sf) return [];
1585
2400
  const hit = symbolAt(ts, program, host, sf, position);
1586
2401
  if (!hit) return [];
1587
- return tagOccurrences(ts, program, host, hit.symbol, hit.name).map(({ fileName: f2, span }) => ({
1588
- fileName: f2,
2402
+ return tagOccurrences(ts, program, host, hit.symbol, hit.name).map(({ fileName: f, span }) => ({
2403
+ fileName: f,
1589
2404
  textSpan: span,
1590
2405
  isWriteAccess: false,
1591
2406
  isDefinition: false
@@ -1597,8 +2412,8 @@ function templateRenameLocations(ts, ls, host, fileName, position) {
1597
2412
  if (!program || !sf) return [];
1598
2413
  const hit = symbolAt(ts, program, host, sf, position);
1599
2414
  if (!hit) return [];
1600
- return tagOccurrences(ts, program, host, hit.symbol, hit.name).map(({ fileName: f2, span }) => ({
1601
- fileName: f2,
2415
+ return tagOccurrences(ts, program, host, hit.symbol, hit.name).map(({ fileName: f, span }) => ({
2416
+ fileName: f,
1602
2417
  textSpan: span
1603
2418
  }));
1604
2419
  }
@@ -1610,6 +2425,22 @@ function init(modules) {
1610
2425
  create(info) {
1611
2426
  const ls = info.languageService;
1612
2427
  const host = info.languageServiceHost;
2428
+ const logged = /* @__PURE__ */ new Set();
2429
+ const report = (what, error) => {
2430
+ const message = error instanceof Error ? error.message : String(error);
2431
+ if (logged.has(`${what}: ${message}`)) return;
2432
+ logged.add(`${what}: ${message}`);
2433
+ const text = error instanceof Error ? error.stack ?? message : message;
2434
+ info.project?.projectService?.logger?.info(`[fluixi] ${what} failed: ${text}`);
2435
+ };
2436
+ const guarded = (what, run) => {
2437
+ try {
2438
+ return run();
2439
+ } catch (error) {
2440
+ report(what, error);
2441
+ return [];
2442
+ }
2443
+ };
1613
2444
  const proxy = /* @__PURE__ */ Object.create(null);
1614
2445
  for (const key of Object.keys(ls)) {
1615
2446
  const member = ls[key];
@@ -1620,8 +2451,8 @@ function init(modules) {
1620
2451
  isMemberCompletion: false,
1621
2452
  isNewIdentifierLocation: true,
1622
2453
  // Re-ask on every keystroke instead of letting the editor filter what it already
1623
- // has. Inside a template the valid set changes with the cursor — a tag name, then
1624
- // that tag's props — and a list cached from one position is wrong at the next.
2454
+ // has. Inside a template the valid set changes with the cursor, a tag name, then
2455
+ // that tag's props: and a list cached from one position is wrong at the next.
1625
2456
  // Without this the props appear only after enough typing to force a fresh
1626
2457
  // request, which reads as completion working intermittently.
1627
2458
  isIncomplete: true,
@@ -1630,8 +2461,8 @@ function init(modules) {
1630
2461
  const IMPLICIT_ANY = /* @__PURE__ */ new Set([7006, 7044]);
1631
2462
  const dedupe = (items) => {
1632
2463
  const seen = /* @__PURE__ */ new Set();
1633
- return items.filter((i2) => {
1634
- const key = `${i2.fileName}:${i2.textSpan.start}:${i2.textSpan.length}`;
2464
+ return items.filter((i) => {
2465
+ const key = `${i.fileName}:${i.textSpan.start}:${i.textSpan.length}`;
1635
2466
  if (seen.has(key)) return false;
1636
2467
  seen.add(key);
1637
2468
  return true;
@@ -1650,13 +2481,21 @@ function init(modules) {
1650
2481
  };
1651
2482
  proxy.getSemanticDiagnostics = (fileName) => {
1652
2483
  const base = reliableFilter(fileName, ls.getSemanticDiagnostics(fileName));
1653
- try {
1654
- return base.concat(templateDiagnostics(ts, ls, fileName));
1655
- } catch {
1656
- return base;
1657
- }
2484
+ return base.concat(
2485
+ guarded("template diagnostics", () => templateDiagnostics(ts, ls, fileName)),
2486
+ guarded("env and auth rules", () => rulesFor(fileName, false))
2487
+ );
2488
+ };
2489
+ proxy.getSuggestionDiagnostics = (fileName) => reliableFilter(fileName, ls.getSuggestionDiagnostics(fileName)).concat(
2490
+ guarded("env and auth rules", () => rulesFor(fileName, true))
2491
+ );
2492
+ const rulesFor = (fileName, suggestions) => {
2493
+ const program = ls.getProgram();
2494
+ if (!program) return [];
2495
+ return envAuthDiagnostics(ts, program, fileName, host).filter(
2496
+ (d) => d.category === ts.DiagnosticCategory.Suggestion === suggestions
2497
+ );
1658
2498
  };
1659
- proxy.getSuggestionDiagnostics = (fileName) => reliableFilter(fileName, ls.getSuggestionDiagnostics(fileName));
1660
2499
  proxy.getQuickInfoAtPosition = (fileName, position) => {
1661
2500
  try {
1662
2501
  const prop = componentPropHover(ts, ls, host, fileName, position);
@@ -1750,6 +2589,11 @@ function init(modules) {
1750
2589
  );
1751
2590
  try {
1752
2591
  const own = templateCodeFixes(ts, ls, fileName, start, end, errorCodes);
2592
+ const program = ls.getProgram();
2593
+ if (program && errorCodes.includes(RULE.envNotPublic)) {
2594
+ const fix = envPublicFix(ts, program, fileName, start, host);
2595
+ if (fix) own.push(fix);
2596
+ }
1753
2597
  return own.length ? [...base, ...own] : base;
1754
2598
  } catch {
1755
2599
  return base;
@@ -1768,3 +2612,5 @@ function init(modules) {
1768
2612
  };
1769
2613
  }
1770
2614
  module.exports = init;
2615
+ /*! @fluixi/template-parser v1.0.0-alpha.99 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2616
+ /*! @fluixi/compiler v1.0.0-alpha.99 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */