@fluixi/ts-plugin 0.1.0-alpha.3 → 0.1.0-alpha.30

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 = (i, n) => {
6
- i.parent = n;
7
- let r = B(i);
8
- for (let s of r) t(s, i);
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 B(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 i = this.pieces[this.pieces.length - 1];
46
- return i ? i.kind === "static" ? i.start + i.text.length : i.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 i = this.pieces[this.pi + 1];
59
- return i !== void 0 && i.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 i = this.pieces[this.pi];
69
- return i.kind !== "static" ? "" : i.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 i = this.pieces[this.pi];
74
- return i.kind !== "static" ? false : i.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 i = t.text[this.oi++] ?? "";
81
- return this.normalize(), i;
82
- }
83
- readWhile(t) {
84
- let i = "";
85
- for (; !this.eof() && !this.atHole(); ) {
86
- let n = this.peek();
87
- if (n === "" || !t(n)) break;
88
- i += 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(), i;
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 E = (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, i;
106
- e.name[0] === "@" ? (t = "at", i = e.name.slice(1)) : e.name.startsWith("on:") ? (t = "colon", i = e.name.slice(3)) : (t = "on", i = e.name.slice(2));
107
- let [n, ...r] = i.split("."), s = 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: s, 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: "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) => E(e, true) }];
111
- function k(e, t = f, i = { component: false }) {
112
- for (let n of t) if (!(n.elementOnly && i.component) && n.match(e.name)) return n.build(e);
113
- return E(e, false);
114
- }
115
- var D = /* @__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((i) => "name" in i && i.name === t);
125
- }
126
- function w(e) {
127
- return e.attributes.some((t) => t.kind === "Spread");
128
- }
129
- function v(e, t) {
130
- let i = u(e, t);
131
- if (!i || i.kind !== "Attribute" || !i.value) return;
132
- let n = i.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((i) => i.kind === "EventBinding" && t(i.name));
141
- }
142
- function R(e) {
143
- let t = [], i = (r, s, o) => {
144
- t.push({ code: s, message: o, severity: "warning", loc: r.loc });
145
- }, n = (r) => {
146
- for (let s of r) {
147
- s.kind === "Element" && V(s, i);
148
- let o = "children" in s ? s.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 V(e, t) {
155
- if (w(e)) return;
156
- let i = e.tag.toLowerCase();
157
- i === "img" && !u(e, "alt") && !H(e) && t(e, "a11y-img-alt", 'An `img` needs an `alt`. Use `alt=""` when the image is decorative.'), i === "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."), i === "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(i) && A(e, (r) => r === "click") && !u(e, "role") && !A(e, (r) => W.has(r)) && t(e, "a11y-click-without-keyboard", `A click handler on \`${i}\` is unreachable by keyboard. Use a \`button\`, or add a \`role\` and a key handler.`);
160
- }
161
- var I = /[A-Za-z0-9\-_:@.?]/;
162
- var b = class {
163
- constructor(t, i) {
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 = i.svg ?? false, this.directives = i.directives ?? f, this.accessibility = i.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(), i = [];
169
- for (; !this.r.eof() && (i.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: i, loc: this.r.span(t) };
174
- return x(n), this.validateTree(n), this.accessibility && this.diagnostics.push(...R(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 i = (n) => {
178
- let r = null;
179
- for (let s of n) s.kind === "Text" && /^\s*$/.test(s.value) || (s.kind === "Element" || s.kind === "Component" ? (s.attributes.some((l) => l.kind === "ElseDirective") && (r != null && (r.kind === "Element" || r.kind === "Component") && r.attributes.some((a) => a.kind === "IfDirective") || this.report("else-without-if", "error", "`else` must immediately follow an element with `if`", s.loc)), r = s) : r = null, "children" in s && s.children && i(s.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
- i(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 i = this.readText();
208
- i && t.push(i);
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,175 +494,380 @@ var b = 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 i = 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, s = [];
227
- return this.r.startsWith("/>") ? (this.r.advance(), this.r.advance(), r = true) : (this.r.peek() === ">" && this.r.advance(), s = 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: i, attributes: n, children: s, 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(), i = "";
231
- for (; !this.r.eof() && !this.r.atHole() && !(this.r.startsWith("</") || this.r.startsWith("<!--") || this.isTagStart() || this.isFragmentStart() || this.isDynamicTagStart()); ) i += this.r.advance();
232
- return i ? { kind: "Text", value: i, 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 i = "";
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(), i += "\0";
550
+ this.r.takeHole();
551
+ value += "\0";
241
552
  continue;
242
553
  }
243
- i += this.r.advance();
554
+ value += this.r.advance();
555
+ }
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));
244
562
  }
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: i, loc: this.r.span(t) };
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 i = 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: i, 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 i = this.readName(), n = C(i), r = this.parseAttributes(n);
261
- this.foldEachKey(r, t), this.r.skipWhitespace();
262
- let s = i.toLowerCase(), o = !n && S.has(s), l = !n && T.has(s), a = false, c = [];
263
- if (this.r.startsWith("/>")) this.r.advance(), this.r.advance(), a = true;
264
- else if (this.r.peek() === ">" && this.r.advance(), !l) if (c = o ? this.parseRawText(i) : this.parseChildren(), this.r.startsWith("</")) {
265
- let g = this.consumeCloseTag();
266
- g && g !== i && this.report("mismatched-close-tag", "error", `Expected </${i}>, got </${g}>`, this.r.span(t));
267
- } else this.report("unclosed-tag", "error", `Unclosed <${i}>`, this.r.span(t));
268
- let h = this.r.span(t);
269
- if (n) return { kind: "Component", tag: i, tagHole: null, attributes: r, children: c, selfClosing: a, loc: h };
270
- let d = this.svg || D.has(i) ? "svg" : "html";
271
- return { kind: "Element", tag: i, namespace: d, attributes: r, children: c, selfClosing: a, rawText: o, loc: h };
272
- }
273
- parseRawText(t) {
274
- let i = [], n = "</" + t.toLowerCase(), r = "", s = this.r.pos(), o = () => {
275
- r && i.push({ kind: "Text", value: r, raw: true, loc: this.r.span(s) }), 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 l = this.r.takeHole();
281
- i.push({ kind: "Expression", hole: l.index, loc: l.loc }), s = 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 || (s = this.r.pos()), r += this.r.advance();
635
+ if (!text) start = this.r.pos();
636
+ text += this.r.advance();
285
637
  }
286
- return o(), i;
638
+ flush();
639
+ return out;
287
640
  }
288
- startsWithCloseFor(t) {
641
+ startsWithCloseFor(close) {
289
642
  let i = 0;
290
- for (; i < t.length; ) {
291
- let n = this.r.peek(i);
292
- if (n === "" || n.toLowerCase() !== t[i]) return false;
643
+ while (i < close.length) {
644
+ const ch = this.r.peek(i);
645
+ if (ch === "" || ch.toLowerCase() !== close[i]) return false;
293
646
  i++;
294
647
  }
295
648
  return true;
296
649
  }
297
- parseAttributes(t) {
298
- let i = [];
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 a = this.r.takeHole();
302
- i.push({ kind: "Spread", hole: a.index, loc: a.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 a = this.r.pos();
307
- if (this.r.advance(), this.r.advance(), this.r.advance(), this.r.atHole()) {
308
- let c = this.r.takeHole();
309
- i.push({ kind: "Spread", hole: c.index, loc: this.r.span(a) });
310
- } else this.report("invalid-binding", "error", "Spread `...` must be followed by ${\u2026}", this.r.span(a));
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 s = 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 l = { name: r, nameLoc: s, value: o, loc: this.r.span(n), report: (a, c) => this.report(a, "error", c, this.r.span(n)) };
323
- i.push(k(l, 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 i;
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 i = [], 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 && (i.push({ text: n }), n = ""), i.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;
727
+ }
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++;
343
754
  }
344
- return n && i.push({ text: n }), this.r.peek() === t && this.r.advance(), i;
345
- }
346
- classifyParts(t) {
347
- let i = t.filter((n) => "hole" in n);
348
- return i.length === 0 ? { kind: "static", value: t.map((n) => "text" in n ? n.text : "").join("") } : t.length === 1 ? { kind: "hole", hole: i[0].hole } : { kind: "mixed", parts: t };
349
- }
350
- foldEachKey(t, i) {
351
- let n = null, r = 0, s = 0, o = 0, l = 0;
352
- for (let d of t) d.kind === "EachDirective" ? (n = d, s++) : d.kind === "IfDirective" ? r++ : d.kind === "ElseDirective" ? o++ : d.kind === "RefBinding" && l++;
353
- let a = this.r.span(i);
354
- s > 1 && this.report("duplicate-directive", "error", "Multiple `each` directives on one element", a), r > 1 && this.report("duplicate-directive", "error", "Multiple `if` directives on one element", a), l > 1 && this.report("duplicate-directive", "error", "Multiple `ref` bindings on one element", a), r > 0 && s > 0 && this.report("unsupported-combination", "error", "`if` and `each` cannot both apply to one element \u2014 wrap one in another element", a), r > 0 && o > 0 && this.report("invalid-directive", "error", "`if` and `else` cannot be on the same element", a);
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", a);
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) => I.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, i, n, r) {
373
- this.diagnostics.push({ code: t, severity: i, message: n, loc: r });
791
+ report(code, severity, message, loc) {
792
+ this.diagnostics.push({ code, severity, message, loc });
374
793
  }
375
794
  };
376
- function N(e, t = {}) {
377
- return new b(e, t).parse();
795
+ function parseTemplate(pieces, opts = {}) {
796
+ return new Parser(pieces, opts).parse();
797
+ }
798
+
799
+ // src/pieces.ts
800
+ function rawContent(ts, node, sf) {
801
+ const text = node.getText(sf);
802
+ const closesWithSubstitution = ts.isTemplateHead(node) || ts.isTemplateMiddle(node);
803
+ return text.slice(1, closesWithSubstitution ? -2 : -1);
378
804
  }
379
- function L(e) {
380
- let t = [], i = 0;
381
- return e.forEach((n, r) => {
382
- t.push({ kind: "static", text: n, start: i }), i += n.length, r < e.length - 1 && t.push({ kind: "hole", index: r, start: i, end: i });
383
- }), t;
805
+ function templatePieces(ts, tpl, sf) {
806
+ if (ts.isNoSubstitutionTemplateLiteral(tpl)) {
807
+ return [{ kind: "static", text: rawContent(ts, tpl, sf), start: tpl.getStart(sf) + 1 }];
808
+ }
809
+ const pieces = [
810
+ { kind: "static", text: rawContent(ts, tpl.head, sf), start: tpl.head.getStart(sf) + 1 }
811
+ ];
812
+ tpl.templateSpans.forEach((span, i) => {
813
+ const e = span.expression;
814
+ pieces.push({ kind: "hole", index: i, start: e.getStart(sf), end: e.getEnd() });
815
+ pieces.push({
816
+ kind: "static",
817
+ text: rawContent(ts, span.literal, sf),
818
+ start: span.literal.getStart(sf) + 1
819
+ });
820
+ });
821
+ return pieces;
822
+ }
823
+
824
+ // src/cache.ts
825
+ var parsed = /* @__PURE__ */ new WeakMap();
826
+ function parseCached(ts, sf, tpl) {
827
+ let byTemplate = parsed.get(sf);
828
+ if (!byTemplate) {
829
+ byTemplate = /* @__PURE__ */ new Map();
830
+ parsed.set(sf, byTemplate);
831
+ }
832
+ const key = tpl.getStart(sf);
833
+ const hit = byTemplate.get(key);
834
+ if (hit) return hit;
835
+ const result = parseTemplate(templatePieces(ts, tpl, sf));
836
+ byTemplate.set(key, result);
837
+ return result;
838
+ }
839
+ var templates = /* @__PURE__ */ new WeakMap();
840
+ function mayHaveTemplate(text) {
841
+ return text.includes("html`") || text.includes("svg`");
842
+ }
843
+ var NONE = [];
844
+ function templatesIn(ts, sf) {
845
+ const hit = templates.get(sf);
846
+ if (hit) return hit;
847
+ if (!mayHaveTemplate(sf.text)) {
848
+ templates.set(sf, NONE);
849
+ return NONE;
850
+ }
851
+ const found = [];
852
+ const visit = (node) => {
853
+ if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && (node.tag.text === "html" || node.tag.text === "svg")) {
854
+ found.push(node);
855
+ }
856
+ ts.forEachChild(node, visit);
857
+ };
858
+ visit(sf);
859
+ found.sort((a, b) => a.getStart(sf) - b.getStart(sf));
860
+ templates.set(sf, found);
861
+ return found;
384
862
  }
385
- function Q(e, t = {}) {
386
- return N(L(e), t);
863
+ function templateAtCached(ts, sf, pos) {
864
+ let match;
865
+ for (const tpl of templatesIn(ts, sf)) {
866
+ const start = tpl.template.getStart(sf);
867
+ if (start > pos) break;
868
+ if (pos <= tpl.template.getEnd()) match = tpl;
869
+ }
870
+ return match;
387
871
  }
388
872
 
389
873
  // src/collect.ts
@@ -391,23 +875,17 @@ var UNUSED_CODES = /* @__PURE__ */ new Set([6133, 6196, 6198, 6199, 6205, 6138,
391
875
  function isUnusedCode(code) {
392
876
  return UNUSED_CODES.has(code);
393
877
  }
878
+ var tagCache = /* @__PURE__ */ new WeakMap();
394
879
  function usedComponentTags(ts, sourceFile) {
880
+ const hit = tagCache.get(sourceFile);
881
+ if (hit) return hit;
395
882
  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);
883
+ for (const template of templatesIn(ts, sourceFile)) {
884
+ collectTags(parseCached(ts, sourceFile, template.template).root.children, tags);
885
+ }
886
+ tagCache.set(sourceFile, tags);
403
887
  return tags;
404
888
  }
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
889
  function collectTags(nodes, out) {
412
890
  for (const node of nodes) {
413
891
  if (node.kind === "Component" && node.tag) out.add(node.tag.split(".")[0]);
@@ -450,84 +928,43 @@ function importedNames(ts, decl) {
450
928
  return names;
451
929
  }
452
930
 
453
- // src/pieces.ts
454
- function templatePieces(ts, tpl, sf) {
455
- if (ts.isNoSubstitutionTemplateLiteral(tpl)) {
456
- return [{ kind: "static", text: tpl.text, start: tpl.getStart(sf) + 1 }];
457
- }
458
- const pieces = [{ kind: "static", text: tpl.head.text, start: tpl.head.getStart(sf) + 1 }];
459
- tpl.templateSpans.forEach((span, i) => {
460
- const e = span.expression;
461
- pieces.push({ kind: "hole", index: i, start: e.getStart(sf), end: e.getEnd() });
462
- pieces.push({ kind: "static", text: span.literal.text, start: span.literal.getStart(sf) + 1 });
463
- });
464
- return pieces;
465
- }
466
-
467
- // src/cache.ts
468
- var parsed = /* @__PURE__ */ new WeakMap();
469
- function parseCached(ts, sf, tpl) {
470
- let byTemplate = parsed.get(sf);
471
- if (!byTemplate) {
472
- byTemplate = /* @__PURE__ */ new Map();
473
- parsed.set(sf, byTemplate);
474
- }
475
- const key = tpl.getStart(sf);
476
- const hit = byTemplate.get(key);
477
- if (hit) return hit;
478
- const result = N(templatePieces(ts, tpl, sf));
479
- byTemplate.set(key, result);
480
- return result;
481
- }
482
- var templates = /* @__PURE__ */ new WeakMap();
483
- function templatesIn(ts, sf) {
484
- const hit = templates.get(sf);
485
- if (hit) return hit;
486
- const found = [];
487
- const visit = (node) => {
488
- if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && (node.tag.text === "html" || node.tag.text === "svg")) {
489
- found.push(node);
490
- }
491
- ts.forEachChild(node, visit);
492
- };
493
- visit(sf);
494
- found.sort((a, b2) => a.getStart(sf) - b2.getStart(sf));
495
- templates.set(sf, found);
496
- return found;
497
- }
498
- function templateAtCached(ts, sf, pos) {
499
- let match;
500
- for (const tpl of templatesIn(ts, sf)) {
501
- const start = tpl.template.getStart(sf);
502
- if (start > pos) break;
503
- if (pos <= tpl.template.getEnd()) match = tpl;
504
- }
505
- return match;
931
+ // ../compiler/dist/resolve/builtins.mjs
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;
506
964
  }
507
965
 
508
966
  // src/auto-import.ts
509
- var DOM = "@fluixi/dom";
510
- var CORE = "@fluixi/core";
511
- var ROUTER = "@fluixi/core/router-next";
512
- var AUTO_IMPORTED = {
513
- // Control flow. Suspense and Await live in core; dom doesn't export them.
514
- Show: DOM,
515
- For: DOM,
516
- Index: DOM,
517
- Switch: DOM,
518
- Match: DOM,
519
- Portal: DOM,
520
- Dynamic: DOM,
521
- ErrorBoundary: DOM,
522
- Suspense: CORE,
523
- SuspenseList: CORE,
524
- Await: CORE,
525
- // Router. `Routes` isn't a component and `lazy` is a call, so neither appears.
526
- Router: ROUTER,
527
- Outlet: ROUTER,
528
- Redirect: ROUTER,
529
- Link: ROUTER
530
- };
967
+ var AUTO_IMPORTED = builtinComponentMap();
531
968
  var exportsByProgram = /* @__PURE__ */ new WeakMap();
532
969
  function moduleExports(ts, program, host, from, moduleName) {
533
970
  let cache2 = exportsByProgram.get(program);
@@ -600,7 +1037,7 @@ function findExport(ts, host, options, fileName, name, depth) {
600
1037
  return void 0;
601
1038
  }
602
1039
  function declaredName(ts, statement, name) {
603
- 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;
604
1041
  if (!exported) return void 0;
605
1042
  if ((ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) && statement.name?.text === name) {
606
1043
  return statement.name;
@@ -793,7 +1230,7 @@ function holeRoles(nodes, out) {
793
1230
  if (node.kind === "Component") {
794
1231
  const propHole = (name) => {
795
1232
  const a = node.attributes.find(
796
- (x2) => x2.kind === "Attribute" && x2.name === name && x2.value != null && x2.value.kind === "hole"
1233
+ (x) => x.kind === "Attribute" && x.name === name && x.value != null && x.value.kind === "hole"
797
1234
  );
798
1235
  return a && a.kind === "Attribute" && a.value && a.value.kind === "hole" ? a.value.hole : void 0;
799
1236
  };
@@ -924,7 +1361,7 @@ function contains(outer, inner) {
924
1361
  }
925
1362
 
926
1363
  // src/props.ts
927
- function componentPropCompletions(ts, ls, fileName, position) {
1364
+ function componentPropCompletions(ts, ls, host, fileName, position) {
928
1365
  const program = ls.getProgram();
929
1366
  const sf = program?.getSourceFile(fileName);
930
1367
  if (!program || !sf) return void 0;
@@ -932,28 +1369,27 @@ function componentPropCompletions(ts, ls, fileName, position) {
932
1369
  if (!template) return void 0;
933
1370
  const comp = componentTagAtAttrArea(ts, sf, template.template, position);
934
1371
  if (!comp || !comp.tag) return void 0;
1372
+ const span = attrNameSpan(sf.text, position);
935
1373
  const cf = CONTROL_FLOW_PROPS[comp.tag];
936
1374
  if (cf) {
937
1375
  const already2 = new Set(comp.attributeNames);
938
- return cf.filter((n) => !already2.has(n)).map((name) => propEntry(ts, name));
1376
+ return cf.filter((n) => !already2.has(n)).map((name) => propEntry(ts, name, span));
939
1377
  }
940
1378
  const checker = program.getTypeChecker();
941
1379
  const rootName = comp.tag.split(".")[0];
942
- const decl = findDeclaration(ts, sf, rootName);
943
- if (!decl) return void 0;
944
- const compType = checker.getTypeAtLocation(decl);
945
- const propsType = firstParamType(ts, checker, compType);
1380
+ const compType = componentTypeOf(ts, program, checker, host, sf, template.template, rootName);
1381
+ const propsType = compType && firstParamType(ts, checker, compType);
946
1382
  if (!propsType) return void 0;
947
1383
  const already = new Set(comp.attributeNames);
948
1384
  const entries = [];
949
- for (const p2 of propsType.getProperties()) {
950
- const name = p2.getName();
1385
+ for (const p of propsType.getProperties()) {
1386
+ const name = p.getName();
951
1387
  if (name === "children" || already.has(name)) continue;
952
- entries.push(propEntry(ts, name));
1388
+ entries.push(propEntry(ts, name, span));
953
1389
  }
954
1390
  return entries.length ? entries : void 0;
955
1391
  }
956
- function componentPropHover(ts, ls, fileName, position) {
1392
+ function componentPropHover(ts, ls, host, fileName, position) {
957
1393
  const program = ls.getProgram();
958
1394
  const sf = program?.getSourceFile(fileName);
959
1395
  if (!program || !sf) return void 0;
@@ -968,11 +1404,13 @@ function componentPropHover(ts, ls, fileName, position) {
968
1404
  if (!typeText) return void 0;
969
1405
  } else if (hit.tag) {
970
1406
  const checker = program.getTypeChecker();
971
- const decl = findDeclaration(ts, sf, hit.tag.split(".")[0]);
972
- const propsType = decl && firstParamType(ts, checker, checker.getTypeAtLocation(decl));
1407
+ const root = hit.tag.split(".")[0];
1408
+ const compType = componentTypeOf(ts, program, checker, host, sf, template.template, root);
1409
+ const propsType = compType && firstParamType(ts, checker, compType);
973
1410
  const sym = propsType && propsType.getProperty(hit.prop);
974
1411
  if (!sym) return void 0;
975
- typeText = checker.typeToString(checker.getTypeOfSymbolAtLocation(sym, sym.valueDeclaration ?? decl));
1412
+ const at = sym.valueDeclaration ?? sym.declarations?.[0] ?? template.template;
1413
+ typeText = checker.typeToString(checker.getTypeOfSymbolAtLocation(sym, at));
976
1414
  }
977
1415
  if (!typeText) return void 0;
978
1416
  return {
@@ -1039,31 +1477,40 @@ var CONTROL_FLOW_PROPS = {
1039
1477
  Dynamic: ["component"],
1040
1478
  Await: ["value", "fallback"]
1041
1479
  };
1042
- function propEntry(ts, name) {
1043
- return { name, kind: ts.ScriptElementKind.memberVariableElement, kindModifiers: "", sortText: "0_" + name, insertText: name };
1480
+ function propEntry(ts, name, replacementSpan) {
1481
+ return {
1482
+ name,
1483
+ kind: ts.ScriptElementKind.memberVariableElement,
1484
+ kindModifiers: "",
1485
+ sortText: "0_" + name,
1486
+ insertText: name,
1487
+ // Without a span the editor filters these against whatever word *it* computes at the
1488
+ // cursor, and inside a template literal that is not the attribute name, so the list
1489
+ // showed in full until the first keystroke and then emptied. Saying exactly which
1490
+ // characters are being replaced makes filtering match what is typed.
1491
+ replacementSpan
1492
+ };
1044
1493
  }
1045
- function findDeclaration(ts, sf, name) {
1046
- for (const stmt of sf.statements) {
1047
- if ((ts.isFunctionDeclaration(stmt) || ts.isClassDeclaration(stmt)) && stmt.name?.text === name) return stmt.name;
1048
- if (ts.isVariableStatement(stmt)) {
1049
- for (const d of stmt.declarationList.declarations) {
1050
- if (ts.isIdentifier(d.name) && d.name.text === name) return d.name;
1051
- }
1052
- }
1053
- if (ts.isImportDeclaration(stmt)) {
1054
- const b2 = stmt.importClause?.namedBindings;
1055
- if (b2 && ts.isNamedImports(b2)) {
1056
- for (const el of b2.elements) if (el.name.text === name) return el.name;
1057
- }
1058
- if (stmt.importClause?.name?.text === name) return stmt.importClause.name;
1059
- }
1060
- }
1061
- return void 0;
1494
+ function attrNameSpan(text, position) {
1495
+ const isNameChar = (c) => !!c && /[A-Za-z0-9_$:@?.\-]/.test(c);
1496
+ let start = position;
1497
+ while (start > 0 && isNameChar(text[start - 1])) start--;
1498
+ let end = position;
1499
+ while (end < text.length && isNameChar(text[end])) end++;
1500
+ return { start, length: end - start };
1501
+ }
1502
+ function componentTypeOf(ts, program, checker, host, sf, template, name) {
1503
+ const flags = ts.SymbolFlags.Value | ts.SymbolFlags.Function | ts.SymbolFlags.Class | ts.SymbolFlags.Alias;
1504
+ const symbol = checker.getSymbolsInScope(template, flags).find((s) => s.name === name) ?? autoImportedSymbol(ts, program, host, sf, name);
1505
+ if (!symbol) return void 0;
1506
+ const resolved = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
1507
+ const decl = resolved.valueDeclaration ?? resolved.declarations?.[0];
1508
+ return decl ? checker.getTypeOfSymbolAtLocation(resolved, decl) : void 0;
1062
1509
  }
1063
1510
  function firstParamType(ts, checker, type) {
1064
1511
  for (const sig of checker.getSignaturesOfType(type, ts.SignatureKind.Call)) {
1065
- const p2 = sig.getParameters()[0];
1066
- if (p2) return checker.getTypeOfSymbolAtLocation(p2, p2.valueDeclaration ?? sig.getDeclaration());
1512
+ const p = sig.getParameters()[0];
1513
+ if (p) return checker.getTypeOfSymbolAtLocation(p, p.valueDeclaration ?? sig.getDeclaration());
1067
1514
  }
1068
1515
  return void 0;
1069
1516
  }
@@ -1076,7 +1523,7 @@ function componentTagAtAttrArea(ts, sf, tpl, position) {
1076
1523
  const c = node;
1077
1524
  const openStart = c.loc.start + 1 + (c.tag ? c.tag.length : 0);
1078
1525
  const openEnd = firstChildOrCloseStart(c);
1079
- if (position > openStart && position <= openEnd) {
1526
+ if (position > openStart && position < openEnd) {
1080
1527
  hit = { tag: c.tag, attributeNames: attributeNames(c) };
1081
1528
  }
1082
1529
  }
@@ -1112,13 +1559,13 @@ function paramMemberCompletions(ts, ls, fileName, position) {
1112
1559
  const checker = program.getTypeChecker();
1113
1560
  const already = /* @__PURE__ */ new Set();
1114
1561
  const entries = [];
1115
- for (const p2 of checker.getApparentType(info.type).getProperties()) {
1116
- const name = p2.getName();
1562
+ for (const p of checker.getApparentType(info.type).getProperties()) {
1563
+ const name = p.getName();
1117
1564
  if (already.has(name) || name.startsWith("__")) continue;
1118
1565
  already.add(name);
1119
1566
  entries.push({
1120
1567
  name,
1121
- kind: memberKind(ts, p2),
1568
+ kind: memberKind(ts, p),
1122
1569
  kindModifiers: "",
1123
1570
  sortText: "0_" + name,
1124
1571
  insertText: name
@@ -1242,8 +1689,8 @@ function elementAttributeCompletions(ts, ls, host, fileName, position) {
1242
1689
  const props = attributesFor(ts, program, host, sf, hit.tag);
1243
1690
  if (!props) return void 0;
1244
1691
  const entries = [];
1245
- for (const p2 of props) {
1246
- const name = p2.getName();
1692
+ for (const p of props) {
1693
+ const name = p.getName();
1247
1694
  if (name === "children" || hit.present.has(name)) continue;
1248
1695
  entries.push({
1249
1696
  name,
@@ -1286,7 +1733,7 @@ function elementAttributeHover(ts, ls, host, fileName, position) {
1286
1733
  const hit = attributeNameAt(ts, sf, tpl.template, position);
1287
1734
  if (!hit) return void 0;
1288
1735
  const props = attributesFor(ts, program, host, sf, hit.tag);
1289
- const symbol = props?.find((p2) => p2.getName() === hit.name);
1736
+ const symbol = props?.find((p) => p.getName() === hit.name);
1290
1737
  if (!symbol) return void 0;
1291
1738
  const decl = symbol.valueDeclaration ?? symbol.declarations?.[0];
1292
1739
  if (!decl) return void 0;
@@ -1359,7 +1806,7 @@ function isAccessor(ts, checker, node) {
1359
1806
  const signatures = checker.getTypeAtLocation(node).getCallSignatures();
1360
1807
  if (signatures.length !== 1) return false;
1361
1808
  const signature = signatures[0];
1362
- if (signature.getParameters().some((p2) => !isOptional(ts, p2))) return false;
1809
+ if (signature.getParameters().some((p) => !isOptional(ts, p))) return false;
1363
1810
  const returned = signature.getReturnType();
1364
1811
  return !(returned.flags & (ts.TypeFlags.Void | ts.TypeFlags.Never));
1365
1812
  }
@@ -1436,10 +1883,392 @@ function templateFixAll(ts, ls, fileName, errorCodes) {
1436
1883
  textChanges.push({ span: { start: at, length: 0 }, newText: "()" });
1437
1884
  }
1438
1885
  if (textChanges.length === 0) return void 0;
1439
- textChanges.sort((a, b2) => b2.span.start - a.span.start);
1886
+ textChanges.sort((a, b) => b.span.start - a.span.start);
1440
1887
  return { changes: [{ fileName, textChanges }], commands: void 0 };
1441
1888
  }
1442
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
+
1443
2272
  // src/navigation.ts
1444
2273
  var spansByFile = /* @__PURE__ */ new WeakMap();
1445
2274
  function tagSpans(ts, sf) {
@@ -1570,8 +2399,8 @@ function templateReferences(ts, ls, host, fileName, position) {
1570
2399
  if (!program || !sf) return [];
1571
2400
  const hit = symbolAt(ts, program, host, sf, position);
1572
2401
  if (!hit) return [];
1573
- return tagOccurrences(ts, program, host, hit.symbol, hit.name).map(({ fileName: f2, span }) => ({
1574
- fileName: f2,
2402
+ return tagOccurrences(ts, program, host, hit.symbol, hit.name).map(({ fileName: f, span }) => ({
2403
+ fileName: f,
1575
2404
  textSpan: span,
1576
2405
  isWriteAccess: false,
1577
2406
  isDefinition: false
@@ -1583,8 +2412,8 @@ function templateRenameLocations(ts, ls, host, fileName, position) {
1583
2412
  if (!program || !sf) return [];
1584
2413
  const hit = symbolAt(ts, program, host, sf, position);
1585
2414
  if (!hit) return [];
1586
- return tagOccurrences(ts, program, host, hit.symbol, hit.name).map(({ fileName: f2, span }) => ({
1587
- fileName: f2,
2415
+ return tagOccurrences(ts, program, host, hit.symbol, hit.name).map(({ fileName: f, span }) => ({
2416
+ fileName: f,
1588
2417
  textSpan: span
1589
2418
  }));
1590
2419
  }
@@ -1596,6 +2425,22 @@ function init(modules) {
1596
2425
  create(info) {
1597
2426
  const ls = info.languageService;
1598
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
+ };
1599
2444
  const proxy = /* @__PURE__ */ Object.create(null);
1600
2445
  for (const key of Object.keys(ls)) {
1601
2446
  const member = ls[key];
@@ -1605,6 +2450,12 @@ function init(modules) {
1605
2450
  isGlobalCompletion: false,
1606
2451
  isMemberCompletion: false,
1607
2452
  isNewIdentifierLocation: true,
2453
+ // Re-ask on every keystroke instead of letting the editor filter what it already
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.
2456
+ // Without this the props appear only after enough typing to force a fresh
2457
+ // request, which reads as completion working intermittently.
2458
+ isIncomplete: true,
1608
2459
  entries
1609
2460
  });
1610
2461
  const IMPLICIT_ANY = /* @__PURE__ */ new Set([7006, 7044]);
@@ -1630,16 +2481,24 @@ function init(modules) {
1630
2481
  };
1631
2482
  proxy.getSemanticDiagnostics = (fileName) => {
1632
2483
  const base = reliableFilter(fileName, ls.getSemanticDiagnostics(fileName));
1633
- try {
1634
- return base.concat(templateDiagnostics(ts, ls, fileName));
1635
- } catch {
1636
- return base;
1637
- }
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
+ );
1638
2498
  };
1639
- proxy.getSuggestionDiagnostics = (fileName) => reliableFilter(fileName, ls.getSuggestionDiagnostics(fileName));
1640
2499
  proxy.getQuickInfoAtPosition = (fileName, position) => {
1641
2500
  try {
1642
- const prop = componentPropHover(ts, ls, fileName, position);
2501
+ const prop = componentPropHover(ts, ls, host, fileName, position);
1643
2502
  if (prop) return prop;
1644
2503
  } catch {
1645
2504
  }
@@ -1662,7 +2521,7 @@ function init(modules) {
1662
2521
  };
1663
2522
  proxy.getCompletionsAtPosition = (fileName, position, options, formatting) => {
1664
2523
  try {
1665
- const props = componentPropCompletions(ts, ls, fileName, position);
2524
+ const props = componentPropCompletions(ts, ls, host, fileName, position);
1666
2525
  if (props) return completionList(props);
1667
2526
  } catch {
1668
2527
  }
@@ -1730,6 +2589,11 @@ function init(modules) {
1730
2589
  );
1731
2590
  try {
1732
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
+ }
1733
2597
  return own.length ? [...base, ...own] : base;
1734
2598
  } catch {
1735
2599
  return base;
@@ -1748,3 +2612,5 @@ function init(modules) {
1748
2612
  };
1749
2613
  }
1750
2614
  module.exports = init;
2615
+ /*! @fluixi/template-parser v0.1.0-alpha.4 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2616
+ /*! @fluixi/compiler v1.0.0-alpha.96 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */