driftjs-compiler 0.0.14 → 0.0.15

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-es.js CHANGED
@@ -1,8 +1,8 @@
1
- import { VOID_ELEMENTS as e, hasMatchingOuterParens as t } from "driftjs-shared";
2
- import * as n from "acorn";
3
- import * as r from "acorn-walk";
1
+ import { VOID_ELEMENTS as e } from "driftjs-shared";
2
+ import * as t from "acorn";
3
+ import * as n from "acorn-walk";
4
4
  //#region types/token.ts
5
- var i = {
5
+ var r = {
6
6
  TagOpen: "TagOpen",
7
7
  TagOpenSlash: "TagOpenSlash",
8
8
  TagClose: "TagClose",
@@ -26,7 +26,7 @@ var i = {
26
26
  BlockOpen: "BlockOpen",
27
27
  BlockClose: "BlockClose",
28
28
  EOF: "EOF"
29
- }, a = {
29
+ }, i = {
30
30
  Data: "Data",
31
31
  TagOpen: "TagOpen",
32
32
  EndTagOpen: "EndTagOpen",
@@ -40,9 +40,9 @@ var i = {
40
40
  Interpolation: "Interpolation",
41
41
  RawText: "RawText",
42
42
  EOF: "EOF"
43
- }, o = /* @__PURE__ */ function(e) {
43
+ }, a = /* @__PURE__ */ function(e) {
44
44
  return e[e.Start = 0] = "Start", e[e.Punctuator = 1] = "Punctuator", e[e.Keyword = 2] = "Keyword", e[e.IdentifierOrLiteral = 3] = "IdentifierOrLiteral", e[e.PostfixOp = 4] = "PostfixOp", e;
45
- }({}), s = {
45
+ }({}), o = {
46
46
  Program: "Program",
47
47
  Element: "Element",
48
48
  Text: "Text",
@@ -53,161 +53,161 @@ var i = {
53
53
  For: "For",
54
54
  Switch: "Switch",
55
55
  Async: "Async"
56
- }, c = class extends Error {
56
+ }, s = class extends Error {
57
57
  line;
58
58
  column;
59
59
  offset;
60
60
  constructor(e, t, n, r) {
61
61
  super(`LexerError [${t}:${n}]: ${e}`), this.line = t, this.column = n, this.offset = r, this.name = "DriftLexerError";
62
62
  }
63
- }, l = class extends Error {
63
+ }, c = class extends Error {
64
64
  line;
65
65
  column;
66
66
  offset;
67
67
  constructor(e, t, n, r) {
68
68
  super(`ParserError [${t}:${n}]: ${e}`), this.line = t, this.column = n, this.offset = r, this.name = "DriftParserError";
69
69
  }
70
- }, u = /* @__PURE__ */ function(e) {
71
- return e[e.RETURN = 0] = "RETURN", e[e.CREATE_ELEMENT = 1] = "CREATE_ELEMENT", e[e.CREATE_TEXT = 2] = "CREATE_TEXT", e[e.CREATE_COMMENT = 3] = "CREATE_COMMENT", e[e.APPEND_CHILD = 4] = "APPEND_CHILD", e[e.SET_ATTR = 5] = "SET_ATTR", e[e.CREATE_FRAGMENT = 6] = "CREATE_FRAGMENT", e[e.INTERPOLATE_TEXT = 7] = "INTERPOLATE_TEXT", e[e.EXEC_SCRIPT = 12] = "EXEC_SCRIPT", e[e.REACTIVE_IF = 13] = "REACTIVE_IF", e[e.REACTIVE_FOR = 14] = "REACTIVE_FOR", e[e.MOUNT_COMPONENT = 15] = "MOUNT_COMPONENT", e[e.REACTIVE_ASYNC = 16] = "REACTIVE_ASYNC", e;
72
- }({}), d = {
73
- [a.Data]: [
70
+ }, l = /* @__PURE__ */ function(e) {
71
+ return e[e.RETURN = 0] = "RETURN", e[e.CREATE_ELEMENT = 1] = "CREATE_ELEMENT", e[e.CREATE_TEXT = 2] = "CREATE_TEXT", e[e.CREATE_COMMENT = 3] = "CREATE_COMMENT", e[e.APPEND_CHILD = 4] = "APPEND_CHILD", e[e.SET_ATTR = 5] = "SET_ATTR", e[e.CREATE_FRAGMENT = 6] = "CREATE_FRAGMENT", e[e.INTERPOLATE_TEXT = 7] = "INTERPOLATE_TEXT", e[e.EXEC_SCRIPT = 12] = "EXEC_SCRIPT", e[e.REACTIVE_IF = 13] = "REACTIVE_IF", e[e.REACTIVE_FOR = 14] = "REACTIVE_FOR", e[e.MOUNT_COMPONENT = 15] = "MOUNT_COMPONENT", e[e.REACTIVE_ASYNC = 16] = "REACTIVE_ASYNC", e[e.REACTIVE_SWITCH = 17] = "REACTIVE_SWITCH", e;
72
+ }({}), u = {
73
+ [i.Data]: [
74
74
  {
75
- to: a.Comment,
75
+ to: i.Comment,
76
76
  when: "The next characters are <!--",
77
77
  emits: "Comment"
78
78
  },
79
79
  {
80
- to: a.EndTagOpen,
80
+ to: i.EndTagOpen,
81
81
  when: "The next characters are </",
82
82
  emits: "TagOpenSlash"
83
83
  },
84
84
  {
85
- to: a.TagOpen,
85
+ to: i.TagOpen,
86
86
  when: "The next character is '<' for a start tag",
87
87
  emits: "TagOpen"
88
88
  },
89
89
  {
90
- to: a.Interpolation,
90
+ to: i.Interpolation,
91
91
  when: "The next character is '{' in element content",
92
92
  emits: "Interpolation"
93
93
  },
94
94
  {
95
- to: a.Data,
95
+ to: i.Data,
96
96
  when: "Plain content is consumed up to the next control delimiter",
97
97
  emits: "Text"
98
98
  },
99
99
  {
100
- to: a.EOF,
100
+ to: i.EOF,
101
101
  when: "The source has been fully consumed",
102
102
  emits: "EOF"
103
103
  }
104
104
  ],
105
- [a.TagOpen]: [{
106
- to: a.BeforeAttributeName,
105
+ [i.TagOpen]: [{
106
+ to: i.BeforeAttributeName,
107
107
  when: "A valid opening tag name is consumed",
108
108
  emits: "Identifier"
109
109
  }],
110
- [a.EndTagOpen]: [{
111
- to: a.BeforeAttributeName,
110
+ [i.EndTagOpen]: [{
111
+ to: i.BeforeAttributeName,
112
112
  when: "A valid closing tag name is consumed",
113
113
  emits: "Identifier"
114
114
  }],
115
- [a.BeforeAttributeName]: [
115
+ [i.BeforeAttributeName]: [
116
116
  {
117
- to: a.AttributeName,
117
+ to: i.AttributeName,
118
118
  when: "An attribute name begins in an opening tag",
119
119
  emits: "Identifier"
120
120
  },
121
121
  {
122
- to: a.Data,
122
+ to: i.Data,
123
123
  when: "A tag is closed with '>' and raw-text mode does not apply",
124
124
  emits: "TagClose"
125
125
  },
126
126
  {
127
- to: a.RawText,
127
+ to: i.RawText,
128
128
  when: "A script/style start tag is closed with '>'",
129
129
  emits: "TagClose"
130
130
  },
131
131
  {
132
- to: a.Data,
132
+ to: i.Data,
133
133
  when: "A tag is self-closed with '/>'",
134
134
  emits: "TagSelfClose"
135
135
  }
136
136
  ],
137
- [a.AttributeName]: [{
138
- to: a.AfterAttributeName,
137
+ [i.AttributeName]: [{
138
+ to: i.AfterAttributeName,
139
139
  when: "The attribute identifier has been fully consumed",
140
140
  emits: "Identifier"
141
141
  }],
142
- [a.AfterAttributeName]: [{
143
- to: a.BeforeAttributeValue,
142
+ [i.AfterAttributeName]: [{
143
+ to: i.BeforeAttributeValue,
144
144
  when: "The next character is '='",
145
145
  emits: "Equals"
146
146
  }, {
147
- to: a.BeforeAttributeName,
147
+ to: i.BeforeAttributeName,
148
148
  when: "The attribute is boolean and the lexer moves to the next attribute or tag boundary",
149
149
  emits: "No token"
150
150
  }],
151
- [a.BeforeAttributeValue]: [{
152
- to: a.AttributeValueQuoted,
151
+ [i.BeforeAttributeValue]: [{
152
+ to: i.AttributeValueQuoted,
153
153
  when: "The attribute value starts with a quote",
154
154
  emits: "StringLiteral"
155
155
  }, {
156
- to: a.AttributeValueInterpolation,
156
+ to: i.AttributeValueInterpolation,
157
157
  when: "The attribute value starts with '{'",
158
158
  emits: "Interpolation"
159
159
  }],
160
- [a.AttributeValueQuoted]: [{
161
- to: a.BeforeAttributeName,
160
+ [i.AttributeValueQuoted]: [{
161
+ to: i.BeforeAttributeName,
162
162
  when: "The closing quote is consumed",
163
163
  emits: "StringLiteral"
164
164
  }],
165
- [a.AttributeValueInterpolation]: [{
166
- to: a.BeforeAttributeName,
165
+ [i.AttributeValueInterpolation]: [{
166
+ to: i.BeforeAttributeName,
167
167
  when: "The interpolation closes and the attribute value is complete",
168
168
  emits: "Interpolation"
169
169
  }],
170
- [a.Comment]: [{
171
- to: a.Data,
170
+ [i.Comment]: [{
171
+ to: i.Data,
172
172
  when: "The terminating --> delimiter is consumed",
173
173
  emits: "Comment"
174
174
  }],
175
- [a.Interpolation]: [{
176
- to: a.Data,
175
+ [i.Interpolation]: [{
176
+ to: i.Data,
177
177
  when: "A content interpolation closes with a matching brace",
178
178
  emits: "Interpolation"
179
179
  }, {
180
- to: a.BeforeAttributeName,
180
+ to: i.BeforeAttributeName,
181
181
  when: "An attribute interpolation closes with a matching brace",
182
182
  emits: "Interpolation"
183
183
  }],
184
- [a.RawText]: [
184
+ [i.RawText]: [
185
185
  {
186
- to: a.RawText,
186
+ to: i.RawText,
187
187
  when: "Plain raw-text content is consumed before the matching closing tag",
188
188
  emits: "Text"
189
189
  },
190
190
  {
191
- to: a.EndTagOpen,
191
+ to: i.EndTagOpen,
192
192
  when: "The matching raw-text closing tag begins with </",
193
193
  emits: "TagOpenSlash"
194
194
  },
195
195
  {
196
- to: a.EOF,
196
+ to: i.EOF,
197
197
  when: "The raw-text block reaches end of input before a closing tag appears",
198
198
  emits: "EOF"
199
199
  }
200
200
  ],
201
- [a.EOF]: [{
202
- to: a.EOF,
201
+ [i.EOF]: [{
202
+ to: i.EOF,
203
203
  when: "Additional parser requests are made after end of input",
204
204
  emits: "EOF"
205
205
  }]
206
206
  };
207
- function f(e) {
207
+ function d(e) {
208
208
  return e === "script" || e === "style";
209
209
  }
210
- var p = /* @__PURE__ */ new Set([
210
+ var f = /* @__PURE__ */ new Set([
211
211
  "if",
212
212
  "else",
213
213
  "for",
@@ -217,7 +217,7 @@ var p = /* @__PURE__ */ new Set([
217
217
  "async",
218
218
  "fallback",
219
219
  "catch"
220
- ]), m = /* @__PURE__ */ new Set([
220
+ ]), p = /* @__PURE__ */ new Set([
221
221
  "return",
222
222
  "yield",
223
223
  "await",
@@ -230,14 +230,14 @@ var p = /* @__PURE__ */ new Set([
230
230
  "do",
231
231
  "throw",
232
232
  "new"
233
- ]), h = class {
233
+ ]), m = class {
234
234
  source;
235
235
  offset = 0;
236
236
  line = 1;
237
237
  column = 1;
238
238
  emittedTokenCount = 0;
239
239
  eofToken = null;
240
- state = { kind: a.Data };
240
+ state = { kind: i.Data };
241
241
  blockDepth = 0;
242
242
  elementDepth = 0;
243
243
  blockElementDepthStack = [];
@@ -256,357 +256,357 @@ var p = /* @__PURE__ */ new Set([
256
256
  }
257
257
  readNextToken() {
258
258
  switch (this.state.kind) {
259
- case a.Data: return this.readDataToken();
260
- case a.TagOpen: return this.readTagNameToken(!1);
261
- case a.EndTagOpen: return this.readTagNameToken(!0);
262
- case a.BeforeAttributeName: return this.readBeforeAttributeNameToken();
263
- case a.AttributeName: return this.readAttributeNameToken();
264
- case a.AfterAttributeName: return this.readAfterAttributeNameToken();
265
- case a.BeforeAttributeValue: return this.readBeforeAttributeValueToken();
266
- case a.Comment:
267
- case a.Interpolation:
268
- case a.AttributeValueQuoted:
269
- case a.AttributeValueInterpolation: throw Error(`Lexer entered transient state '${this.state.kind}' unexpectedly.`);
270
- case a.RawText: return this.readRawTextToken();
271
- case a.EOF: return this.getOrCreateEOFToken();
259
+ case i.Data: return this.readDataToken();
260
+ case i.TagOpen: return this.readTagNameToken(!1);
261
+ case i.EndTagOpen: return this.readTagNameToken(!0);
262
+ case i.BeforeAttributeName: return this.readBeforeAttributeNameToken();
263
+ case i.AttributeName: return this.readAttributeNameToken();
264
+ case i.AfterAttributeName: return this.readAfterAttributeNameToken();
265
+ case i.BeforeAttributeValue: return this.readBeforeAttributeValueToken();
266
+ case i.Comment:
267
+ case i.Interpolation:
268
+ case i.AttributeValueQuoted:
269
+ case i.AttributeValueInterpolation: throw Error(`Lexer entered transient state '${this.state.kind}' unexpectedly.`);
270
+ case i.RawText: return this.readRawTextToken();
271
+ case i.EOF: return this.getOrCreateEOFToken();
272
272
  }
273
273
  }
274
274
  readDataToken() {
275
275
  let e = this.getLocation();
276
- if (this.isAtEnd()) return this.transitionTo({ kind: a.EOF }), this.getOrCreateEOFToken(e);
277
- if (this.startsWith("<!--")) return this.consumePattern("<!--"), this.transitionTo({ kind: a.Comment }), this.readCommentToken(e);
278
- if (this.startsWith("</")) return this.consumePattern("</"), this.transitionTo({ kind: a.EndTagOpen }), this.createToken(i.TagOpenSlash, "</", e);
279
- if (this.peek() === "<") return this.advance(), this.transitionTo({ kind: a.TagOpen }), this.createToken(i.TagOpen, "<", e);
276
+ if (this.isAtEnd()) return this.transitionTo({ kind: i.EOF }), this.getOrCreateEOFToken(e);
277
+ if (this.startsWith("<!--")) return this.consumePattern("<!--"), this.transitionTo({ kind: i.Comment }), this.readCommentToken(e);
278
+ if (this.startsWith("</")) return this.consumePattern("</"), this.transitionTo({ kind: i.EndTagOpen }), this.createToken(r.TagOpenSlash, "</", e);
279
+ if (this.peek() === "<") return this.advance(), this.transitionTo({ kind: i.TagOpen }), this.createToken(r.TagOpen, "<", e);
280
280
  if (this.peek() === "{") return this.advance(), this.transitionTo({
281
- kind: a.Interpolation,
281
+ kind: i.Interpolation,
282
282
  context: "content",
283
283
  tagName: null
284
284
  }), this.readInterpolationToken(e, "content", null);
285
285
  let t = this.blockDepth > 0 && this.blockElementDepthStack.length > 0 && this.elementDepth === this.blockElementDepthStack[this.blockElementDepthStack.length - 1];
286
- return this.peek() === "}" && t ? (this.advance(), this.blockDepth--, this.blockElementDepthStack.pop(), this.createToken(i.BlockClose, "}", e)) : this.peek() === "@" ? this.readDirectiveToken(e) : this.readTextToken();
286
+ return this.peek() === "}" && t ? (this.advance(), this.blockDepth--, this.blockElementDepthStack.pop(), this.createToken(r.BlockClose, "}", e)) : this.peek() === "@" ? this.readDirectiveToken(e) : this.readTextToken();
287
287
  }
288
288
  readDirectiveToken(e) {
289
289
  this.advance();
290
290
  let t = "";
291
291
  for (; !this.isAtEnd() && /[a-zA-Z]/.test(this.peek());) t += this.advance();
292
- if (!p.has(t)) throw new c(`Unknown directive '@${t}'`, e.line, e.column, e.offset);
293
- if (t === "if") return this.readDirectiveHeader(e, i.DirectiveIf);
292
+ if (!f.has(t)) throw new s(`Unknown directive '@${t}'`, e.line, e.column, e.offset);
293
+ if (t === "if") return this.readDirectiveHeader(e, r.DirectiveIf);
294
294
  if (t === "else") {
295
- if (this.skipWhitespace(), this.startsWith("if") && !/[a-zA-Z0-9_]/.test(this.peek(2))) return this.consumePattern("if"), this.readDirectiveHeader(e, i.DirectiveElseIf);
296
- if (this.skipWhitespace(), this.peek() === "{") return this.advance(), this.blockDepth++, this.blockElementDepthStack.push(this.elementDepth), this.createToken(i.DirectiveElse, "", e);
297
- throw new c("Expected '{' after @else directive", e.line, e.column, e.offset);
298
- } else if (t === "for") return this.readDirectiveHeader(e, i.DirectiveFor);
299
- else if (t === "switch") return this.readDirectiveHeader(e, i.DirectiveSwitch);
300
- else if (t === "case") return this.readDirectiveHeader(e, i.DirectiveCase);
301
- else if (t === "async") return this.readDirectiveHeader(e, i.DirectiveAsync);
302
- else if (t === "catch") return this.readDirectiveHeader(e, i.DirectiveCatch);
295
+ if (this.skipWhitespace(), this.startsWith("if") && !/[a-zA-Z0-9_]/.test(this.peek(2))) return this.consumePattern("if"), this.readDirectiveHeader(e, r.DirectiveElseIf);
296
+ if (this.skipWhitespace(), this.peek() === "{") return this.advance(), this.blockDepth++, this.blockElementDepthStack.push(this.elementDepth), this.createToken(r.DirectiveElse, "", e);
297
+ throw new s("Expected '{' after @else directive", e.line, e.column, e.offset);
298
+ } else if (t === "for") return this.readDirectiveHeader(e, r.DirectiveFor);
299
+ else if (t === "switch") return this.readDirectiveHeader(e, r.DirectiveSwitch);
300
+ else if (t === "case") return this.readDirectiveHeader(e, r.DirectiveCase);
301
+ else if (t === "async") return this.readDirectiveHeader(e, r.DirectiveAsync);
302
+ else if (t === "catch") return this.readDirectiveHeader(e, r.DirectiveCatch);
303
303
  else if (t === "fallback") {
304
- if (this.skipWhitespace(), this.peek() === "{") return this.advance(), this.blockDepth++, this.blockElementDepthStack.push(this.elementDepth), this.createToken(i.DirectiveFallback, "", e);
305
- throw new c("Expected '{' after @fallback directive", e.line, e.column, e.offset);
306
- } else return this.skipWhitespace(), this.peek() === "{" && (this.advance(), this.blockDepth++, this.blockElementDepthStack.push(this.elementDepth)), this.createToken(i.DirectiveDefault, "", e);
304
+ if (this.skipWhitespace(), this.peek() === "{") return this.advance(), this.blockDepth++, this.blockElementDepthStack.push(this.elementDepth), this.createToken(r.DirectiveFallback, "", e);
305
+ throw new s("Expected '{' after @fallback directive", e.line, e.column, e.offset);
306
+ } else return this.skipWhitespace(), this.peek() === "{" && (this.advance(), this.blockDepth++, this.blockElementDepthStack.push(this.elementDepth)), this.createToken(r.DirectiveDefault, "", e);
307
307
  }
308
308
  readDirectiveHeader(e, t) {
309
309
  this.skipWhitespace();
310
- let n = "", r = 0, i = 0, a = 0, s = [], l = null, u = !1, d = !1, f = !1, p = !1, h = !1, g = o.Start;
310
+ let n = "", r = 0, i = 0, o = 0, c = [], l = null, u = !1, d = !1, f = !1, m = !1, h = !1, g = a.Start;
311
311
  for (; !this.isAtEnd();) {
312
- let c = this.advance();
312
+ let s = this.advance();
313
313
  if (d) {
314
- n += c, c === "\n" && (d = !1);
314
+ n += s, s === "\n" && (d = !1);
315
315
  continue;
316
316
  }
317
317
  if (f) {
318
- n += c, c === "/" && n.endsWith("*/") && (f = !1);
318
+ n += s, s === "/" && n.endsWith("*/") && (f = !1);
319
319
  continue;
320
320
  }
321
- if (p) {
322
- n += c, u ? u = !1 : c === "\\" ? u = !0 : c === "[" ? h = !0 : c === "]" && h ? h = !1 : c === "/" && !h && (p = !1, g = o.IdentifierOrLiteral);
321
+ if (m) {
322
+ n += s, u ? u = !1 : s === "\\" ? u = !0 : s === "[" ? h = !0 : s === "]" && h ? h = !1 : s === "/" && !h && (m = !1, g = a.IdentifierOrLiteral);
323
323
  continue;
324
324
  }
325
325
  if (l !== null) {
326
- if (n += c, u) u = !1;
327
- else if (c === "\\") u = !0;
328
- else if (c === l) l = null, g = o.IdentifierOrLiteral;
329
- else if (l === "`" && c === "{" && n.endsWith("${")) {
326
+ if (n += s, u) u = !1;
327
+ else if (s === "\\") u = !0;
328
+ else if (s === l) l = null, g = a.IdentifierOrLiteral;
329
+ else if (l === "`" && s === "{" && n.endsWith("${")) {
330
330
  let e = 0;
331
331
  for (let t = n.length - 3; t >= 0 && n[t] === "\\"; t--) e++;
332
- e % 2 == 0 && (s.push(a), l = null, a++, g = o.Start);
332
+ e % 2 == 0 && (c.push(o), l = null, o++, g = a.Start);
333
333
  }
334
334
  continue;
335
335
  }
336
- if (c === "/" && !u) {
336
+ if (s === "/" && !u) {
337
337
  let e = this.peek();
338
338
  if (e === "/") {
339
- d = !0, n += c;
339
+ d = !0, n += s;
340
340
  continue;
341
341
  } else if (e === "*") {
342
- f = !0, n += c;
342
+ f = !0, n += s;
343
343
  continue;
344
344
  } else if (this.isRegexStart(g)) {
345
- p = !0, h = !1, n += c;
345
+ m = !0, h = !1, n += s;
346
346
  continue;
347
- } else g = o.Punctuator;
347
+ } else g = a.Punctuator;
348
348
  }
349
- if (c === "\"" || c === "'" || c === "`") {
350
- l = c, n += c;
349
+ if (s === "\"" || s === "'" || s === "`") {
350
+ l = s, n += s;
351
351
  continue;
352
352
  }
353
- if (c === "(") {
354
- r++, g = o.Start, n += c;
353
+ if (s === "(") {
354
+ r++, g = a.Start, n += s;
355
355
  continue;
356
356
  }
357
- if (c === ")") {
358
- r > 0 && r--, g = o.IdentifierOrLiteral, n += c;
357
+ if (s === ")") {
358
+ r > 0 && r--, g = a.IdentifierOrLiteral, n += s;
359
359
  continue;
360
360
  }
361
- if (c === "[") {
362
- i++, g = o.Start, n += c;
361
+ if (s === "[") {
362
+ i++, g = a.Start, n += s;
363
363
  continue;
364
364
  }
365
- if (c === "]") {
366
- i > 0 && i--, g = o.IdentifierOrLiteral, n += c;
365
+ if (s === "]") {
366
+ i > 0 && i--, g = a.IdentifierOrLiteral, n += s;
367
367
  continue;
368
368
  }
369
- if (c === "{") {
370
- if (!/\b(as|catch)\s*$/.test(n) && r === 0 && i === 0 && a === 0 && s.length === 0) return this.blockDepth++, this.blockElementDepthStack.push(this.elementDepth), this.createToken(t, n.trim(), e);
371
- a++, g = o.Start, n += c;
369
+ if (s === "{") {
370
+ if (!/\b(as|catch)\s*$/.test(n) && r === 0 && i === 0 && o === 0 && c.length === 0) return this.blockDepth++, this.blockElementDepthStack.push(this.elementDepth), this.createToken(t, n.trim(), e);
371
+ o++, g = a.Start, n += s;
372
372
  continue;
373
373
  }
374
- if (c === "}") {
375
- a--, s.length > 0 && a === s[s.length - 1] && (s.pop(), l = "`"), g = o.IdentifierOrLiteral, n += c;
374
+ if (s === "}") {
375
+ o--, c.length > 0 && o === c[c.length - 1] && (c.pop(), l = "`"), g = a.IdentifierOrLiteral, n += s;
376
376
  continue;
377
377
  }
378
- if (c === "+" || c === "-") {
379
- if (this.peek() === c) {
378
+ if (s === "+" || s === "-") {
379
+ if (this.peek() === s) {
380
380
  let e = this.advance();
381
- n += c + e, g = g === o.IdentifierOrLiteral ? o.PostfixOp : o.Start;
381
+ n += s + e, g = g === a.IdentifierOrLiteral ? a.PostfixOp : a.Start;
382
382
  continue;
383
383
  }
384
- g = o.Punctuator, n += c;
384
+ g = a.Punctuator, n += s;
385
385
  continue;
386
386
  }
387
- if ("=(,:;!&|?*%<>~^".includes(c)) {
388
- g = o.Punctuator, n += c;
387
+ if ("=(,:;!&|?*%<>~^".includes(s)) {
388
+ g = a.Punctuator, n += s;
389
389
  continue;
390
390
  }
391
- if (/[a-zA-Z0-9_$]/.test(c)) {
392
- let e = c;
391
+ if (/[a-zA-Z0-9_$]/.test(s)) {
392
+ let e = s;
393
393
  for (; !this.isAtEnd() && /[a-zA-Z0-9_$]/.test(this.peek());) e += this.advance();
394
- g = m.has(e) ? o.Keyword : o.IdentifierOrLiteral, n += e;
394
+ g = p.has(e) ? a.Keyword : a.IdentifierOrLiteral, n += e;
395
395
  continue;
396
396
  }
397
- n += c;
397
+ n += s;
398
398
  }
399
- throw new c("Unterminated directive header, expected '{'", e.line, e.column, e.offset);
399
+ throw new s("Unterminated directive header, expected '{'", e.line, e.column, e.offset);
400
400
  }
401
401
  readTagNameToken(e) {
402
402
  if (this.isAtEnd()) throw this.createUnexpectedEOFError(e ? "after closing tag opener" : "after opening tag opener");
403
403
  let t = this.getLocation(), n = this.peek();
404
- if (!this.isIdentifierStart(n)) throw new c(`Expected tag name but found '${n || "EOF"}'`, t.line, t.column, t.offset);
405
- let r = this.readIdentifierValue(), o = !e && f(r);
404
+ if (!this.isIdentifierStart(n)) throw new s(`Expected tag name but found '${n || "EOF"}'`, t.line, t.column, t.offset);
405
+ let a = this.readIdentifierValue(), o = !e && d(a);
406
406
  return this.transitionTo({
407
- kind: a.BeforeAttributeName,
408
- tagName: r,
407
+ kind: i.BeforeAttributeName,
408
+ tagName: a,
409
409
  isClosingTag: e,
410
410
  entersRawText: o
411
- }), this.createToken(i.Identifier, r, t);
411
+ }), this.createToken(r.Identifier, a, t);
412
412
  }
413
413
  readBeforeAttributeNameToken() {
414
414
  let t = this.state;
415
- if (t.kind !== a.BeforeAttributeName) throw Error(`Expected BeforeAttributeName state but found '${t.kind}'.`);
415
+ if (t.kind !== i.BeforeAttributeName) throw Error(`Expected BeforeAttributeName state but found '${t.kind}'.`);
416
416
  if (this.skipWhitespace(), this.isAtEnd()) throw this.createUnexpectedEOFError(`inside tag <${t.tagName}>`);
417
417
  let n = this.getLocation();
418
418
  if (t.isClosingTag) {
419
- if (this.peek() !== ">") throw new c(`Unexpected character '${this.peek()}' inside closing tag </${t.tagName}>`, n.line, n.column, n.offset);
420
- return this.advance(), this.elementDepth > 0 && this.elementDepth--, this.transitionTo({ kind: a.Data }), this.createToken(i.TagClose, ">", n);
419
+ if (this.peek() !== ">") throw new s(`Unexpected character '${this.peek()}' inside closing tag </${t.tagName}>`, n.line, n.column, n.offset);
420
+ return this.advance(), this.elementDepth > 0 && this.elementDepth--, this.transitionTo({ kind: i.Data }), this.createToken(r.TagClose, ">", n);
421
421
  }
422
422
  if (this.peek() === "/") {
423
423
  let e = 1;
424
424
  for (; this.peek(e) === " " || this.peek(e) === " " || this.peek(e) === "\n" || this.peek(e) === "\r";) e++;
425
425
  if (this.peek(e) === ">") {
426
426
  for (let t = 0; t <= e; t++) this.advance();
427
- return this.transitionTo({ kind: a.Data }), this.createToken(i.TagSelfClose, "/>", n);
427
+ return this.transitionTo({ kind: i.Data }), this.createToken(r.TagSelfClose, "/>", n);
428
428
  }
429
429
  }
430
- if (this.peek() === ">") return this.advance(), e.has(t.tagName.toLowerCase()) || this.elementDepth++, t.entersRawText && f(t.tagName) ? this.transitionTo({
431
- kind: a.RawText,
430
+ if (this.peek() === ">") return this.advance(), e.has(t.tagName.toLowerCase()) || this.elementDepth++, t.entersRawText && d(t.tagName) ? this.transitionTo({
431
+ kind: i.RawText,
432
432
  tagName: t.tagName
433
- }) : this.transitionTo({ kind: a.Data }), this.createToken(i.TagClose, ">", n);
434
- if (!this.isIdentifierStart(this.peek())) throw new c(`Unexpected character '${this.peek()}' inside tag <${t.tagName}>`, n.line, n.column, n.offset);
433
+ }) : this.transitionTo({ kind: i.Data }), this.createToken(r.TagClose, ">", n);
434
+ if (!this.isIdentifierStart(this.peek())) throw new s(`Unexpected character '${this.peek()}' inside tag <${t.tagName}>`, n.line, n.column, n.offset);
435
435
  return this.transitionTo({
436
- kind: a.AttributeName,
436
+ kind: i.AttributeName,
437
437
  tagName: t.tagName,
438
438
  attributeName: null
439
439
  }), this.readAttributeNameToken();
440
440
  }
441
441
  readAttributeNameToken() {
442
442
  let e = this.state;
443
- if (e.kind !== a.AttributeName) throw Error(`Expected AttributeName state but found '${e.kind}'.`);
443
+ if (e.kind !== i.AttributeName) throw Error(`Expected AttributeName state but found '${e.kind}'.`);
444
444
  let t = this.getLocation();
445
- if (!this.isIdentifierStart(this.peek())) throw new c(`Expected attribute name but found '${this.peek() || "EOF"}'`, t.line, t.column, t.offset);
446
- let n = this.readIdentifierValue(), r = e.tagName;
445
+ if (!this.isIdentifierStart(this.peek())) throw new s(`Expected attribute name but found '${this.peek() || "EOF"}'`, t.line, t.column, t.offset);
446
+ let n = this.readIdentifierValue(), a = e.tagName;
447
447
  return this.transitionTo({
448
- kind: a.AfterAttributeName,
449
- tagName: r,
448
+ kind: i.AfterAttributeName,
449
+ tagName: a,
450
450
  attributeName: n
451
- }), this.createToken(i.Identifier, n, t);
451
+ }), this.createToken(r.Identifier, n, t);
452
452
  }
453
453
  readAfterAttributeNameToken() {
454
454
  let e = this.state;
455
- if (e.kind !== a.AfterAttributeName) throw Error(`Expected AfterAttributeName state but found '${e.kind}'.`);
455
+ if (e.kind !== i.AfterAttributeName) throw Error(`Expected AfterAttributeName state but found '${e.kind}'.`);
456
456
  let t = e.tagName, n = e.attributeName;
457
457
  if (this.skipWhitespace(), this.isAtEnd()) throw this.createUnexpectedEOFError(`after attribute '${n}' in <${t}>`);
458
458
  if (this.peek() === "=") {
459
459
  let e = this.getLocation();
460
460
  return this.advance(), this.transitionTo({
461
- kind: a.BeforeAttributeValue,
461
+ kind: i.BeforeAttributeValue,
462
462
  tagName: t,
463
463
  attributeName: n
464
- }), this.createToken(i.Equals, "=", e);
464
+ }), this.createToken(r.Equals, "=", e);
465
465
  }
466
466
  return this.transitionTo({
467
- kind: a.BeforeAttributeName,
467
+ kind: i.BeforeAttributeName,
468
468
  tagName: t,
469
469
  isClosingTag: !1,
470
- entersRawText: f(t)
470
+ entersRawText: d(t)
471
471
  }), this.readBeforeAttributeNameToken();
472
472
  }
473
473
  readBeforeAttributeValueToken() {
474
474
  let e = this.state;
475
- if (e.kind !== a.BeforeAttributeValue) throw Error(`Expected BeforeAttributeValue state but found '${e.kind}'.`);
475
+ if (e.kind !== i.BeforeAttributeValue) throw Error(`Expected BeforeAttributeValue state but found '${e.kind}'.`);
476
476
  let t = e.tagName, n = e.attributeName;
477
477
  if (this.skipWhitespace(), this.isAtEnd()) throw this.createUnexpectedEOFError(`before value for attribute '${n}' in <${t}>`);
478
- let r = this.getLocation(), i = this.peek();
479
- if (i === "\"" || i === "'") return this.advance(), this.transitionTo({
480
- kind: a.AttributeValueQuoted,
478
+ let r = this.getLocation(), a = this.peek();
479
+ if (a === "\"" || a === "'") return this.advance(), this.transitionTo({
480
+ kind: i.AttributeValueQuoted,
481
481
  tagName: t,
482
482
  attributeName: n,
483
- quote: i
484
- }), this.readQuotedStringToken(r, i, t);
485
- if (i === "{") return this.advance(), this.transitionTo({
486
- kind: a.AttributeValueInterpolation,
483
+ quote: a
484
+ }), this.readQuotedStringToken(r, a, t);
485
+ if (a === "{") return this.advance(), this.transitionTo({
486
+ kind: i.AttributeValueInterpolation,
487
487
  tagName: t,
488
488
  attributeName: n
489
489
  }), this.readInterpolationToken(r, "attribute", t);
490
- throw new c(`Expected quoted string or interpolation for attribute '${n}' in <${t}>`, r.line, r.column, r.offset);
490
+ throw new s(`Expected quoted string or interpolation for attribute '${n}' in <${t}>`, r.line, r.column, r.offset);
491
491
  }
492
492
  readCommentToken(e) {
493
493
  let t = "";
494
494
  for (; !this.isAtEnd();) {
495
- if (this.startsWith("-->")) return this.consumePattern("-->"), this.transitionTo({ kind: a.Data }), this.createToken(i.Comment, t, e);
495
+ if (this.startsWith("-->")) return this.consumePattern("-->"), this.transitionTo({ kind: i.Data }), this.createToken(r.Comment, t, e);
496
496
  t += this.advance();
497
497
  }
498
- throw new c("Unterminated XML comment", e.line, e.column, e.offset);
498
+ throw new s("Unterminated XML comment", e.line, e.column, e.offset);
499
499
  }
500
500
  isRegexStart(e) {
501
- return e === o.Start || e === o.Punctuator || e === o.Keyword;
501
+ return e === a.Start || e === a.Punctuator || e === a.Keyword;
502
502
  }
503
503
  readInterpolationToken(e, t, n) {
504
- let r = 1, s = null, l = !1, u = !1, d = !1, p = !1, h = !1, g = o.Start, _ = [], v = "";
504
+ let o = 1, c = null, l = !1, u = !1, f = !1, m = !1, h = !1, g = a.Start, _ = [], v = "";
505
505
  for (; !this.isAtEnd();) {
506
- let c = this.advance();
506
+ let s = this.advance();
507
507
  if (u) {
508
- v += c, c === "\n" && (u = !1);
508
+ v += s, s === "\n" && (u = !1);
509
509
  continue;
510
510
  }
511
- if (d) {
512
- v += c, c === "/" && v.endsWith("*/") && (d = !1);
511
+ if (f) {
512
+ v += s, s === "/" && v.endsWith("*/") && (f = !1);
513
513
  continue;
514
514
  }
515
- if (p) {
516
- v += c, l ? l = !1 : c === "\\" ? l = !0 : c === "[" ? h = !0 : c === "]" && h ? h = !1 : c === "/" && !h && (p = !1, g = o.IdentifierOrLiteral);
515
+ if (m) {
516
+ v += s, l ? l = !1 : s === "\\" ? l = !0 : s === "[" ? h = !0 : s === "]" && h ? h = !1 : s === "/" && !h && (m = !1, g = a.IdentifierOrLiteral);
517
517
  continue;
518
518
  }
519
- if (s !== null) {
520
- if (v += c, l) l = !1;
521
- else if (c === "\\") l = !0;
522
- else if (c === s) s = null, g = o.IdentifierOrLiteral;
523
- else if (s === "`" && c === "{" && v.endsWith("${")) {
519
+ if (c !== null) {
520
+ if (v += s, l) l = !1;
521
+ else if (s === "\\") l = !0;
522
+ else if (s === c) c = null, g = a.IdentifierOrLiteral;
523
+ else if (c === "`" && s === "{" && v.endsWith("${")) {
524
524
  let e = 0;
525
525
  for (let t = v.length - 3; t >= 0 && v[t] === "\\"; t--) e++;
526
- e % 2 == 0 && (_.push(r), s = null, r++, g = o.Start);
526
+ e % 2 == 0 && (_.push(o), c = null, o++, g = a.Start);
527
527
  }
528
528
  continue;
529
529
  }
530
- if (c === "/" && !l) {
530
+ if (s === "/" && !l) {
531
531
  let e = this.peek();
532
532
  if (e === "/") {
533
- u = !0, v += c;
533
+ u = !0, v += s;
534
534
  continue;
535
535
  } else if (e === "*") {
536
- d = !0, v += c;
536
+ f = !0, v += s;
537
537
  continue;
538
538
  } else if (this.isRegexStart(g)) {
539
- p = !0, h = !1, v += c;
539
+ m = !0, h = !1, v += s;
540
540
  continue;
541
- } else g = o.Punctuator;
541
+ } else g = a.Punctuator;
542
542
  }
543
- if (c === "\"" || c === "'" || c === "`") {
544
- inQuote: s = c;
545
- v += c;
543
+ if (s === "\"" || s === "'" || s === "`") {
544
+ inQuote: c = s;
545
+ v += s;
546
546
  continue;
547
547
  }
548
- if (c === "(") {
549
- g = o.Start, v += c;
548
+ if (s === "(") {
549
+ g = a.Start, v += s;
550
550
  continue;
551
551
  }
552
- if (c === ")") {
553
- g = o.IdentifierOrLiteral, v += c;
552
+ if (s === ")") {
553
+ g = a.IdentifierOrLiteral, v += s;
554
554
  continue;
555
555
  }
556
- if (c === "[") {
557
- g = o.Start, v += c;
556
+ if (s === "[") {
557
+ g = a.Start, v += s;
558
558
  continue;
559
559
  }
560
- if (c === "]") {
561
- g = o.IdentifierOrLiteral, v += c;
560
+ if (s === "]") {
561
+ g = a.IdentifierOrLiteral, v += s;
562
562
  continue;
563
563
  }
564
- if (c === "{") {
565
- r++, g = o.Start, v += c;
564
+ if (s === "{") {
565
+ o++, g = a.Start, v += s;
566
566
  continue;
567
567
  }
568
- if (c === "}") {
569
- if (r--, _.length > 0 && r === _[_.length - 1] && (_.pop(), s = "`"), g = o.IdentifierOrLiteral, r === 0) return t === "attribute" && n !== null ? this.transitionTo({
570
- kind: a.BeforeAttributeName,
568
+ if (s === "}") {
569
+ if (o--, _.length > 0 && o === _[_.length - 1] && (_.pop(), c = "`"), g = a.IdentifierOrLiteral, o === 0) return t === "attribute" && n !== null ? this.transitionTo({
570
+ kind: i.BeforeAttributeName,
571
571
  tagName: n,
572
572
  isClosingTag: !1,
573
- entersRawText: f(n)
574
- }) : this.transitionTo({ kind: a.Data }), this.createToken(i.Interpolation, v, e);
575
- v += c;
573
+ entersRawText: d(n)
574
+ }) : this.transitionTo({ kind: i.Data }), this.createToken(r.Interpolation, v, e);
575
+ v += s;
576
576
  continue;
577
577
  }
578
- if (c === "+" || c === "-") {
579
- if (this.peek() === c) {
578
+ if (s === "+" || s === "-") {
579
+ if (this.peek() === s) {
580
580
  let e = this.advance();
581
- v += c + e, g = g === o.IdentifierOrLiteral ? o.PostfixOp : o.Start;
581
+ v += s + e, g = g === a.IdentifierOrLiteral ? a.PostfixOp : a.Start;
582
582
  continue;
583
583
  }
584
- g = o.Punctuator, v += c;
584
+ g = a.Punctuator, v += s;
585
585
  continue;
586
586
  }
587
- if ("=(,:;!&|?*%<>~^".includes(c)) {
588
- g = o.Punctuator, v += c;
587
+ if ("=(,:;!&|?*%<>~^".includes(s)) {
588
+ g = a.Punctuator, v += s;
589
589
  continue;
590
590
  }
591
- if (/[a-zA-Z0-9_$]/.test(c)) {
592
- let e = c;
591
+ if (/[a-zA-Z0-9_$]/.test(s)) {
592
+ let e = s;
593
593
  for (; !this.isAtEnd() && /[a-zA-Z0-9_$]/.test(this.peek());) e += this.advance();
594
- g = m.has(e) ? o.Keyword : o.IdentifierOrLiteral, v += e;
594
+ g = p.has(e) ? a.Keyword : a.IdentifierOrLiteral, v += e;
595
595
  continue;
596
596
  }
597
- v += c;
597
+ v += s;
598
598
  }
599
- throw new c("Unterminated interpolation expression, expected closing brace '}'", e.line, e.column, e.offset);
599
+ throw new s("Unterminated interpolation expression, expected closing brace '}'", e.line, e.column, e.offset);
600
600
  }
601
601
  readRawTextToken() {
602
602
  let e = this.state;
603
- if (e.kind !== a.RawText) throw Error(`Expected RawText state but found '${e.kind}'.`);
603
+ if (e.kind !== i.RawText) throw Error(`Expected RawText state but found '${e.kind}'.`);
604
604
  let t = this.getLocation(), n = `</${e.tagName}`;
605
- if (this.isAtEnd()) return this.transitionTo({ kind: a.EOF }), this.getOrCreateEOFToken(t);
606
- if (this.isRawTextClosingTagAhead(n)) return this.consumePattern("</"), this.transitionTo({ kind: a.EndTagOpen }), this.createToken(i.TagOpenSlash, "</", t);
607
- let r = "";
608
- for (; !this.isAtEnd() && !this.isRawTextClosingTagAhead(n);) r += this.advance();
609
- return r.length > 0 ? this.createToken(i.Text, r, t) : (this.transitionTo({ kind: a.EOF }), this.getOrCreateEOFToken(t));
605
+ if (this.isAtEnd()) return this.transitionTo({ kind: i.EOF }), this.getOrCreateEOFToken(t);
606
+ if (this.isRawTextClosingTagAhead(n)) return this.consumePattern("</"), this.transitionTo({ kind: i.EndTagOpen }), this.createToken(r.TagOpenSlash, "</", t);
607
+ let a = "";
608
+ for (; !this.isAtEnd() && !this.isRawTextClosingTagAhead(n);) a += this.advance();
609
+ return a.length > 0 ? this.createToken(r.Text, a, t) : (this.transitionTo({ kind: i.EOF }), this.getOrCreateEOFToken(t));
610
610
  }
611
611
  readTextToken() {
612
612
  let e = this.getLocation(), t = "", n = () => this.blockDepth > 0 && this.blockElementDepthStack.length > 0 && this.elementDepth === this.blockElementDepthStack[this.blockElementDepthStack.length - 1];
@@ -615,14 +615,14 @@ var p = /* @__PURE__ */ new Set([
615
615
  if (e === "<" || e === "{" || e === "@" || e === "}" && n()) break;
616
616
  t += this.advance();
617
617
  }
618
- return this.createToken(i.Text, t, e);
618
+ return this.createToken(r.Text, t, e);
619
619
  }
620
620
  readQuotedStringToken(e, t, n) {
621
- let r = "", o = !1;
621
+ let a = "", o = !1;
622
622
  for (; !this.isAtEnd();) {
623
623
  let s = this.peek();
624
624
  if (o) {
625
- o = !1, r += this.advance();
625
+ o = !1, a += this.advance();
626
626
  continue;
627
627
  }
628
628
  if (s === "\\") {
@@ -630,14 +630,14 @@ var p = /* @__PURE__ */ new Set([
630
630
  continue;
631
631
  }
632
632
  if (s === t) return this.advance(), this.transitionTo({
633
- kind: a.BeforeAttributeName,
633
+ kind: i.BeforeAttributeName,
634
634
  tagName: n,
635
635
  isClosingTag: !1,
636
- entersRawText: f(n)
637
- }), this.createToken(i.StringLiteral, r, e);
638
- r += this.advance();
636
+ entersRawText: d(n)
637
+ }), this.createToken(r.StringLiteral, a, e);
638
+ a += this.advance();
639
639
  }
640
- throw new c(`Unterminated string literal, expected closing quote ${t}`, e.line, e.column, e.offset);
640
+ throw new s(`Unterminated string literal, expected closing quote ${t}`, e.line, e.column, e.offset);
641
641
  }
642
642
  readIdentifierValue() {
643
643
  let e = "";
@@ -646,7 +646,7 @@ var p = /* @__PURE__ */ new Set([
646
646
  }
647
647
  getOrCreateEOFToken(e = this.getLocation()) {
648
648
  return this.eofToken === null && (this.eofToken = {
649
- type: i.EOF,
649
+ type: r.EOF,
650
650
  value: "",
651
651
  loc: {
652
652
  start: e,
@@ -666,10 +666,10 @@ var p = /* @__PURE__ */ new Set([
666
666
  }
667
667
  createUnexpectedEOFError(e) {
668
668
  let t = this.getLocation();
669
- return new c(`Unexpected end of input ${e}`, t.line, t.column, t.offset);
669
+ return new s(`Unexpected end of input ${e}`, t.line, t.column, t.offset);
670
670
  }
671
671
  transitionTo(e) {
672
- if (!d[this.state.kind].some((t) => t.to === e.kind)) throw Error(`Invalid lexer transition from '${this.state.kind}' to '${e.kind}'.`);
672
+ if (!u[this.state.kind].some((t) => t.to === e.kind)) throw Error(`Invalid lexer transition from '${this.state.kind}' to '${e.kind}'.`);
673
673
  this.state = e;
674
674
  }
675
675
  getLocation() {
@@ -719,7 +719,7 @@ var p = /* @__PURE__ */ new Set([
719
719
  let n = this.peek(t);
720
720
  return n === "" || n === ">" || n === " " || n === " " || n === "\r" || n === "\n";
721
721
  }
722
- }, g = class {
722
+ }, h = class {
723
723
  tokens;
724
724
  current = 0;
725
725
  constructor(e) {
@@ -730,7 +730,7 @@ var p = /* @__PURE__ */ new Set([
730
730
  let e = this.tokens[this.current];
731
731
  return this.current++, e;
732
732
  }
733
- }, _ = {
733
+ }, g = {
734
734
  amp: "&",
735
735
  lt: "<",
736
736
  gt: ">",
@@ -873,7 +873,7 @@ var p = /* @__PURE__ */ new Set([
873
873
  psi: "ψ",
874
874
  omega: "ω"
875
875
  };
876
- function v(e) {
876
+ function _(e) {
877
877
  return !e || !e.includes("&") ? e : e.replace(/&(?:#(\d+)|#x([0-9a-fA-F]+)|([a-zA-Z0-9]+));/g, (e, t, n, r) => {
878
878
  if (t) {
879
879
  let e = parseInt(t, 10);
@@ -891,14 +891,32 @@ function v(e) {
891
891
  return "�";
892
892
  }
893
893
  }
894
- return r && _[r] || e;
894
+ return r && g[r] || e;
895
895
  });
896
896
  }
897
+ function v(e) {
898
+ let t = e.trim();
899
+ if (!t.startsWith("(") || !t.endsWith(")")) return !1;
900
+ let n = 0, r = null, i = !1;
901
+ for (let e = 0; e < t.length - 1; e++) {
902
+ let a = t[e];
903
+ if (r !== null) {
904
+ i ? i = !1 : a === "\\" ? i = !0 : a === r && (r = null);
905
+ continue;
906
+ }
907
+ if (a === "\"" || a === "'" || a === "`") {
908
+ r = a;
909
+ continue;
910
+ }
911
+ if (a === "(" ? n++ : a === ")" && n--, n === 0) return !1;
912
+ }
913
+ return n === 1;
914
+ }
897
915
  var y = class {
898
916
  tokenSource;
899
917
  lookahead = [];
900
918
  constructor(e) {
901
- this.tokenSource = Array.isArray(e) ? new g(e) : e;
919
+ this.tokenSource = Array.isArray(e) ? new h(e) : e;
902
920
  }
903
921
  parse() {
904
922
  return this.lookahead.length = 0, this.parseProgram();
@@ -908,7 +926,7 @@ var y = class {
908
926
  for (; !this.isAtEnd();) t.push(this.parseChild());
909
927
  let n = this.peek().loc.end;
910
928
  return {
911
- type: s.Program,
929
+ type: o.Program,
912
930
  body: t,
913
931
  loc: {
914
932
  start: e,
@@ -918,37 +936,37 @@ var y = class {
918
936
  }
919
937
  parseChild() {
920
938
  let e = this.peek();
921
- if (e.type === i.Comment) return this.advance(), {
922
- type: s.Comment,
939
+ if (e.type === r.Comment) return this.advance(), {
940
+ type: o.Comment,
923
941
  content: e.value,
924
942
  loc: e.loc
925
943
  };
926
- if (e.type === i.Interpolation) return this.advance(), {
927
- type: s.Interpolation,
944
+ if (e.type === r.Interpolation) return this.advance(), {
945
+ type: o.Interpolation,
928
946
  expression: e.value,
929
947
  loc: e.loc
930
948
  };
931
- if (e.type === i.TagOpen) return this.parseElement();
932
- if (e.type === i.DirectiveIf) return this.parseIfDirective();
933
- if (e.type === i.DirectiveFor) return this.parseForDirective();
934
- if (e.type === i.DirectiveSwitch) return this.parseSwitchDirective();
935
- if (e.type === i.DirectiveAsync) return this.parseAsyncDirective();
936
- if (e.type === i.Text) return this.advance(), {
937
- type: s.Text,
938
- content: v(e.value),
949
+ if (e.type === r.TagOpen) return this.parseElement();
950
+ if (e.type === r.DirectiveIf) return this.parseIfDirective();
951
+ if (e.type === r.DirectiveFor) return this.parseForDirective();
952
+ if (e.type === r.DirectiveSwitch) return this.parseSwitchDirective();
953
+ if (e.type === r.DirectiveAsync) return this.parseAsyncDirective();
954
+ if (e.type === r.Text) return this.advance(), {
955
+ type: o.Text,
956
+ content: _(e.value),
939
957
  loc: e.loc
940
958
  };
941
- throw e.type === i.TagOpenSlash ? new l(`Unexpected closing tag '</${this.peek(1).value}>' without opening tag`, e.loc.start.line, e.loc.start.column, e.loc.start.offset) : new l(`Unexpected token '${e.value}' of type '${e.type}'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
959
+ throw e.type === r.TagOpenSlash ? new c(`Unexpected closing tag '</${this.peek(1).value}>' without opening tag`, e.loc.start.line, e.loc.start.column, e.loc.start.offset) : new c(`Unexpected token '${e.value}' of type '${e.type}'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
942
960
  }
943
961
  parseElement() {
944
- let t = this.consume(i.TagOpen, "Expected opening tag bracket").loc.start, n = this.consume(i.Identifier, "Expected tag name after opening bracket").value, r = [];
945
- for (; !this.check(i.TagClose) && !this.check(i.TagSelfClose) && !this.isAtEnd();) r.push(this.parseAttribute());
946
- if (this.check(i.TagSelfClose)) {
962
+ let t = this.consume(r.TagOpen, "Expected opening tag bracket").loc.start, n = this.consume(r.Identifier, "Expected tag name after opening bracket").value, i = [];
963
+ for (; !this.check(r.TagClose) && !this.check(r.TagSelfClose) && !this.isAtEnd();) i.push(this.parseAttribute());
964
+ if (this.check(r.TagSelfClose)) {
947
965
  let e = this.advance();
948
966
  return {
949
- type: s.Element,
967
+ type: o.Element,
950
968
  tagName: n,
951
- attributes: r,
969
+ attributes: i,
952
970
  children: [],
953
971
  isSelfClosing: !0,
954
972
  loc: {
@@ -957,11 +975,11 @@ var y = class {
957
975
  }
958
976
  };
959
977
  }
960
- let a = this.consume(i.TagClose, "Expected closing bracket after attributes");
978
+ let a = this.consume(r.TagClose, "Expected closing bracket after attributes");
961
979
  if (e.has(n.toLowerCase())) return {
962
- type: s.Element,
980
+ type: o.Element,
963
981
  tagName: n,
964
- attributes: r,
982
+ attributes: i,
965
983
  children: [],
966
984
  isSelfClosing: !0,
967
985
  loc: {
@@ -969,25 +987,25 @@ var y = class {
969
987
  end: a.loc.end
970
988
  }
971
989
  };
972
- let o = n.toLowerCase() === "script" || n.toLowerCase() === "style", c = [];
973
- for (; !this.check(i.TagOpenSlash) && !this.isAtEnd();) if (o && this.check(i.Text)) {
990
+ let s = n.toLowerCase() === "script" || n.toLowerCase() === "style", l = [];
991
+ for (; !this.check(r.TagOpenSlash) && !this.isAtEnd();) if (s && this.check(r.Text)) {
974
992
  let e = this.advance();
975
- c.push({
976
- type: s.Text,
993
+ l.push({
994
+ type: o.Text,
977
995
  content: e.value,
978
996
  loc: e.loc
979
997
  });
980
- } else c.push(this.parseChild());
981
- if (this.isAtEnd()) throw new l(`Unclosed element '<${n}>', expected closing tag '</${n}>'`, t.line, t.column, t.offset);
982
- this.consume(i.TagOpenSlash, `Expected closing tag '</${n}>'`);
983
- let u = this.consume(i.Identifier, "Expected closing tag name");
984
- if (u.value !== n && u.value.toLowerCase() !== n.toLowerCase()) throw new l(`Mismatched closing tag. Expected '</${n}>' but got '</${u.value}>'`, u.loc.start.line, u.loc.start.column, u.loc.start.offset);
985
- let d = this.consume(i.TagClose, "Expected '>' after closing tag name");
998
+ } else l.push(this.parseChild());
999
+ if (this.isAtEnd()) throw new c(`Unclosed element '<${n}>', expected closing tag '</${n}>'`, t.line, t.column, t.offset);
1000
+ this.consume(r.TagOpenSlash, `Expected closing tag '</${n}>'`);
1001
+ let u = this.consume(r.Identifier, "Expected closing tag name");
1002
+ if (u.value !== n && u.value.toLowerCase() !== n.toLowerCase()) throw new c(`Mismatched closing tag. Expected '</${n}>' but got '</${u.value}>'`, u.loc.start.line, u.loc.start.column, u.loc.start.offset);
1003
+ let d = this.consume(r.TagClose, "Expected '>' after closing tag name");
986
1004
  return {
987
- type: s.Element,
1005
+ type: o.Element,
988
1006
  tagName: n,
989
- attributes: r,
990
- children: c,
1007
+ attributes: i,
1008
+ children: l,
991
1009
  isSelfClosing: !1,
992
1010
  loc: {
993
1011
  start: t,
@@ -996,27 +1014,27 @@ var y = class {
996
1014
  };
997
1015
  }
998
1016
  parseAttribute() {
999
- let e = this.consume(i.Identifier, "Expected attribute name"), t = e.loc.start, n = e.value;
1000
- if (this.matchToken(i.Equals)) {
1017
+ let e = this.consume(r.Identifier, "Expected attribute name"), t = e.loc.start, n = e.value;
1018
+ if (this.matchToken(r.Equals)) {
1001
1019
  let e = this.peek();
1002
- if (e.type === i.StringLiteral) return this.advance(), {
1003
- type: s.Attribute,
1020
+ if (e.type === r.StringLiteral) return this.advance(), {
1021
+ type: o.Attribute,
1004
1022
  name: n,
1005
- value: v(e.value),
1023
+ value: _(e.value),
1006
1024
  loc: {
1007
1025
  start: t,
1008
1026
  end: e.loc.end
1009
1027
  }
1010
1028
  };
1011
- if (e.type === i.Interpolation) {
1029
+ if (e.type === r.Interpolation) {
1012
1030
  this.advance();
1013
1031
  let r = {
1014
- type: s.Interpolation,
1032
+ type: o.Interpolation,
1015
1033
  expression: e.value,
1016
1034
  loc: e.loc
1017
1035
  };
1018
1036
  return {
1019
- type: s.Attribute,
1037
+ type: o.Attribute,
1020
1038
  name: n,
1021
1039
  value: r,
1022
1040
  loc: {
@@ -1025,10 +1043,10 @@ var y = class {
1025
1043
  }
1026
1044
  };
1027
1045
  }
1028
- throw new l(`Expected string literal or interpolation after '=' for attribute '${n}'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1046
+ throw new c(`Expected string literal or interpolation after '=' for attribute '${n}'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1029
1047
  }
1030
1048
  return {
1031
- type: s.Attribute,
1049
+ type: o.Attribute,
1032
1050
  name: n,
1033
1051
  value: null,
1034
1052
  loc: {
@@ -1038,22 +1056,22 @@ var y = class {
1038
1056
  };
1039
1057
  }
1040
1058
  parseIfDirective() {
1041
- let e = this.consume(i.DirectiveIf, "Expected @if directive"), t = e.loc.start, n = e.value, r = [];
1042
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) r.push(this.parseChild());
1043
- let a = this.consume(i.BlockClose, "Expected closing brace } for @if block"), o = null, c = a.loc.end;
1044
- if (this.skipWhitespaceTokens(), this.check(i.DirectiveElseIf)) o = this.parseElseIfChain(), c = o.loc.end;
1045
- else if (this.check(i.DirectiveElse)) {
1059
+ let e = this.consume(r.DirectiveIf, "Expected @if directive"), t = e.loc.start, n = e.value, i = [];
1060
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) i.push(this.parseChild());
1061
+ let a = this.consume(r.BlockClose, "Expected closing brace } for @if block"), s = null, c = a.loc.end;
1062
+ if (this.skipWhitespaceTokens(), this.check(r.DirectiveElseIf)) s = this.parseElseIfChain(), c = s.loc.end;
1063
+ else if (this.check(r.DirectiveElse)) {
1046
1064
  this.advance();
1047
1065
  let e = [];
1048
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) e.push(this.parseChild());
1049
- let t = this.consume(i.BlockClose, "Expected closing brace } for @else block");
1050
- o = e, c = t.loc.end;
1066
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) e.push(this.parseChild());
1067
+ let t = this.consume(r.BlockClose, "Expected closing brace } for @else block");
1068
+ s = e, c = t.loc.end;
1051
1069
  }
1052
1070
  return {
1053
- type: s.If,
1071
+ type: o.If,
1054
1072
  test: n,
1055
- consequent: r,
1056
- alternate: o,
1073
+ consequent: i,
1074
+ alternate: s,
1057
1075
  loc: {
1058
1076
  start: t,
1059
1077
  end: c
@@ -1061,22 +1079,22 @@ var y = class {
1061
1079
  };
1062
1080
  }
1063
1081
  parseElseIfChain() {
1064
- let e = this.consume(i.DirectiveElseIf, "Expected @else if directive"), t = e.loc.start, n = e.value, r = [];
1065
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) r.push(this.parseChild());
1066
- let a = this.consume(i.BlockClose, "Expected closing brace } for @else if block"), o = null, c = a.loc.end;
1067
- if (this.skipWhitespaceTokens(), this.check(i.DirectiveElseIf)) o = this.parseElseIfChain(), c = o.loc.end;
1068
- else if (this.check(i.DirectiveElse)) {
1082
+ let e = this.consume(r.DirectiveElseIf, "Expected @else if directive"), t = e.loc.start, n = e.value, i = [];
1083
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) i.push(this.parseChild());
1084
+ let a = this.consume(r.BlockClose, "Expected closing brace } for @else if block"), s = null, c = a.loc.end;
1085
+ if (this.skipWhitespaceTokens(), this.check(r.DirectiveElseIf)) s = this.parseElseIfChain(), c = s.loc.end;
1086
+ else if (this.check(r.DirectiveElse)) {
1069
1087
  this.advance();
1070
1088
  let e = [];
1071
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) e.push(this.parseChild());
1072
- let t = this.consume(i.BlockClose, "Expected closing brace } for @else block");
1073
- o = e, c = t.loc.end;
1089
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) e.push(this.parseChild());
1090
+ let t = this.consume(r.BlockClose, "Expected closing brace } for @else block");
1091
+ s = e, c = t.loc.end;
1074
1092
  }
1075
1093
  return {
1076
- type: s.If,
1094
+ type: o.If,
1077
1095
  test: n,
1078
- consequent: r,
1079
- alternate: o,
1096
+ consequent: i,
1097
+ alternate: s,
1080
1098
  loc: {
1081
1099
  start: t,
1082
1100
  end: c
@@ -1084,94 +1102,126 @@ var y = class {
1084
1102
  };
1085
1103
  }
1086
1104
  parseForDirective() {
1087
- let e = this.consume(i.DirectiveFor, "Expected @for directive"), r = e.loc.start, a = e.value.trim();
1088
- for (; t(a);) a = a.slice(1, -1).trim();
1089
- let o = "", c = null, u = "", d = null, f = null;
1105
+ let e = this.consume(r.DirectiveFor, "Expected @for directive"), n = e.loc.start, i = e.value.trim();
1106
+ for (; v(i);) i = i.slice(1, -1).trim();
1107
+ let a = null, s = 0, l = 0, u = 0, d = null;
1090
1108
  try {
1091
- f = n.parseExpressionAt(a, 0, { ecmaVersion: "latest" });
1092
- } catch {
1093
- f = null;
1094
- }
1095
- if (f && f.type === "BinaryExpression" && f.operator === "in") {
1096
- if (f.left.type === "SequenceExpression") {
1097
- let t = f.left.expressions;
1098
- if (t.length < 1 || t.length > 2) throw new l("Invalid @for target bindings. Expected at most 2 variables (item, index).", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1099
- o = a.slice(t[0].start, t[0].end).trim(), c = t.length === 2 ? a.slice(t[1].start, t[1].end).trim() : null;
1100
- } else o = a.slice(f.left.start, f.left.end).trim();
1101
- u = a.slice(f.right.start, f.right.end).trim();
1102
- let t = a.slice(f.end).trim();
1103
- if (t.length > 0) if (t.startsWith("key ") || t.startsWith("key ") || t.startsWith("key\n")) {
1104
- let r = t.slice(3).trim();
1105
- try {
1106
- let e = n.parseExpressionAt(r, 0, { ecmaVersion: "latest" });
1107
- d = r.slice(0, e.end).trim();
1108
- } catch {
1109
- throw new l(`Invalid key expression in @for directive: '${r}'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1110
- }
1111
- } else throw new l(`Unexpected token '${t}' in @for header. Expected 'key <expression>' or block opening '{'.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1112
- } else {
1113
- let r = -1, i = null;
1114
- for (let e = 0; e < a.length - 1; e++) if (a[e] === "i" && a[e + 1] === "n") {
1115
- let t = e === 0 || !/[a-zA-Z0-9_$]/.test(a[e - 1]), o = e + 2 >= a.length || !/[a-zA-Z0-9_$]/.test(a[e + 2]);
1116
- if (t && o) {
1117
- let t = a.slice(0, e).trim(), o = t.startsWith("(") && t.endsWith(")") ? t : `(${t})`;
1118
- try {
1119
- let t = n.parseExpressionAt(`${o} => {}`, 0, { ecmaVersion: "latest" });
1120
- if (t && t.type === "ArrowFunctionExpression") {
1121
- r = e, i = t.params;
1122
- break;
1123
- }
1124
- } catch {}
1125
- }
1109
+ let e = t.tokenizer(i, { ecmaVersion: "latest" });
1110
+ for (let n of e) if (n.type === t.tokTypes.parenL) s++;
1111
+ else if (n.type === t.tokTypes.parenR) s = Math.max(0, s - 1);
1112
+ else if (n.type === t.tokTypes.bracketL) l++;
1113
+ else if (n.type === t.tokTypes.bracketR) l = Math.max(0, l - 1);
1114
+ else if (n.type === t.tokTypes.braceL || n.type === t.tokTypes.dollarBraceL) u++;
1115
+ else if (n.type === t.tokTypes.braceR) u = Math.max(0, u - 1);
1116
+ else if (n.type === t.tokTypes._in && s === 0 && l === 0 && u === 0) {
1117
+ a = n;
1118
+ break;
1126
1119
  }
1127
- if (r === -1 || !i) throw new l(`Invalid @for header syntax '${e.value.trim()}'. Expected format: 'item in list' or '(item, index) in list'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1128
- let s = a.slice(0, r).trim(), f = a.slice(r + 2).trim();
1129
- if (i.length === 1) {
1130
- let e = s;
1131
- for (; t(e);) e = e.slice(1, -1).trim();
1132
- o = e;
1133
- } else if (i.length === 2) {
1134
- let e = s;
1135
- for (; t(e);) e = e.slice(1, -1).trim();
1136
- let n = e.lastIndexOf(",");
1137
- o = e.slice(0, n).trim(), c = e.slice(n + 1).trim();
1138
- } else throw new l("Invalid @for target bindings. Expected at most 2 variables (item, index).", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1120
+ } catch (e) {
1121
+ d = e;
1122
+ }
1123
+ if (!a) throw d ? new c(`Syntax error in @for header: ${d.message}`, e.loc.start.line, e.loc.start.column, e.loc.start.offset) : new c(`Invalid @for header syntax '${e.value.trim()}'. Expected format: 'item in list' or '(item, index) in list'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1124
+ let f = i.slice(0, a.start).trim();
1125
+ if (f.length === 0) throw new c(`Invalid @for header syntax '${e.value.trim()}'. Expected format: 'item in list' or '(item, index) in list'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1126
+ let p = "", m = null;
1127
+ if (v(f)) {
1128
+ let n = f.slice(1, -1).trim(), r = [], i = 0, a = 0, o = 0;
1139
1129
  try {
1140
- let t = n.parseExpressionAt(f, 0, { ecmaVersion: "latest" });
1141
- u = f.slice(0, t.end).trim();
1142
- let r = f.slice(t.end).trim();
1143
- if (r.length > 0) if (r.startsWith("key ") || r.startsWith("key ") || r.startsWith("key\n")) {
1144
- let e = r.slice(3).trim(), t = n.parseExpressionAt(e, 0, { ecmaVersion: "latest" });
1145
- d = e.slice(0, t.end).trim();
1146
- } else throw new l(`Unexpected token '${r}' in @for header. Expected 'key <expression>' or block opening '{'.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1130
+ let e = t.tokenizer(n, { ecmaVersion: "latest" });
1131
+ for (let n of e) n.type === t.tokTypes.parenL ? i++ : n.type === t.tokTypes.parenR ? i = Math.max(0, i - 1) : n.type === t.tokTypes.bracketL ? a++ : n.type === t.tokTypes.bracketR ? a = Math.max(0, a - 1) : n.type === t.tokTypes.braceL || n.type === t.tokTypes.dollarBraceL ? o++ : n.type === t.tokTypes.braceR ? o = Math.max(0, o - 1) : n.type === t.tokTypes.comma && i === 0 && a === 0 && o === 0 && r.push(n.start);
1147
1132
  } catch (t) {
1148
- throw t instanceof l ? t : new l(`Invalid @for iterable expression in '${e.value.trim()}'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1133
+ throw new c(`Invalid @for target bindings '${f}': ${t.message}`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1134
+ }
1135
+ if (r.length === 0) p = n;
1136
+ else if (r.length === 1) {
1137
+ let e = r[0];
1138
+ p = n.slice(0, e).trim(), m = n.slice(e + 1).trim();
1139
+ } else throw new c("Invalid @for target bindings. Expected at most 2 variables (item, index).", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1140
+ } else {
1141
+ let n = 0, r = 0, i = 0, a = !1;
1142
+ try {
1143
+ let e = t.tokenizer(f, { ecmaVersion: "latest" });
1144
+ for (let o of e) if (o.type === t.tokTypes.parenL) n++;
1145
+ else if (o.type === t.tokTypes.parenR) n = Math.max(0, n - 1);
1146
+ else if (o.type === t.tokTypes.bracketL) r++;
1147
+ else if (o.type === t.tokTypes.bracketR) r = Math.max(0, r - 1);
1148
+ else if (o.type === t.tokTypes.braceL || o.type === t.tokTypes.dollarBraceL) i++;
1149
+ else if (o.type === t.tokTypes.braceR) i = Math.max(0, i - 1);
1150
+ else if (o.type === t.tokTypes.comma && n === 0 && r === 0 && i === 0) {
1151
+ a = !0;
1152
+ break;
1153
+ }
1154
+ } catch {}
1155
+ if (a) throw new c(`Invalid @for target bindings '${f}'. Multiple loop variables must be enclosed in parentheses: '(${f})'.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1156
+ p = f;
1157
+ }
1158
+ if (p.length === 0) throw new c("Expected item identifier in @for target bindings.", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1159
+ let h = null;
1160
+ try {
1161
+ let e = t.parse(`let ${p} = 0;`, { ecmaVersion: "latest" });
1162
+ if (!e || !Array.isArray(e.body) || e.body.length !== 1 || e.body[0].type !== "VariableDeclaration" || !Array.isArray(e.body[0].declarations) || e.body[0].declarations.length !== 1) throw Error();
1163
+ h = e.body[0].declarations[0].id;
1164
+ } catch {
1165
+ throw new c(`Invalid @for item binding '${p}'. Expected a valid variable identifier or destructuring pattern.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1166
+ }
1167
+ if (m !== null) {
1168
+ if (m.length === 0) throw new c("Unexpected trailing comma in @for target bindings. Expected index identifier.", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1169
+ try {
1170
+ let e = t.parseExpressionAt(m, 0, { ecmaVersion: "latest" });
1171
+ if (e.type !== "Identifier" || m.slice(e.end).trim().length > 0) throw Error();
1172
+ } catch {
1173
+ throw new c(`Invalid @for index binding '${m}'. Array index must be a valid identifier.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1149
1174
  }
1150
1175
  }
1151
- let p = [];
1152
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) p.push(this.parseChild());
1153
- let m = this.consume(i.BlockClose, "Expected closing brace } for @for block");
1176
+ let g = a.end, _ = i.slice(g), y = g + (_.length - _.trimStart().length), b = "", x = null;
1177
+ try {
1178
+ x = t.parseExpressionAt(i, y, { ecmaVersion: "latest" }), b = i.slice(y, x.end).trim();
1179
+ } catch {
1180
+ throw new c(`Invalid @for iterable expression in '${e.value.trim()}'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1181
+ }
1182
+ let S = null, C = i.slice(x.end).trim();
1183
+ if (C.length > 0) {
1184
+ let n = null;
1185
+ try {
1186
+ n = t.tokenizer(C, { ecmaVersion: "latest" }).getToken();
1187
+ } catch {}
1188
+ if (n && n.type === t.tokTypes.name && n.value === "key") {
1189
+ let r = n.end, i = C.slice(r).trim();
1190
+ try {
1191
+ let n = t.parseExpressionAt(i, 0, { ecmaVersion: "latest" });
1192
+ S = i.slice(0, n.end).trim();
1193
+ let r = i.slice(n.end).trim();
1194
+ if (r.length > 0) throw new c(`Unexpected token '${r}' after key expression in @for directive.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1195
+ } catch (t) {
1196
+ throw t instanceof c ? t : new c(`Invalid key expression in @for directive: '${i}'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1197
+ }
1198
+ } else throw new c(`Unexpected token '${C}' in @for header. Expected 'key <expression>' or block opening '{'.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1199
+ }
1200
+ let w = [];
1201
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) w.push(this.parseChild());
1202
+ let T = this.consume(r.BlockClose, "Expected closing brace } for @for block");
1154
1203
  return {
1155
- type: s.For,
1156
- item: o,
1157
- index: c,
1158
- iterable: u,
1159
- key: d,
1160
- body: p,
1204
+ type: o.For,
1205
+ item: p,
1206
+ pattern: h,
1207
+ index: m,
1208
+ iterable: b,
1209
+ key: S,
1210
+ body: w,
1161
1211
  loc: {
1162
- start: r,
1163
- end: m.loc.end
1212
+ start: n,
1213
+ end: T.loc.end
1164
1214
  }
1165
1215
  };
1166
1216
  }
1167
1217
  parseSwitchDirective() {
1168
- let e = this.consume(i.DirectiveSwitch, "Expected @switch directive"), t = e.loc.start, n = e.value, r = [];
1169
- for (this.skipWhitespaceTokens(); !this.check(i.BlockClose) && !this.isAtEnd();) {
1170
- if (this.check(i.DirectiveCase)) {
1218
+ let e = this.consume(r.DirectiveSwitch, "Expected @switch directive"), t = e.loc.start, n = e.value, i = [];
1219
+ for (this.skipWhitespaceTokens(); !this.check(r.BlockClose) && !this.isAtEnd();) {
1220
+ if (this.check(r.DirectiveCase)) {
1171
1221
  let e = this.advance(), t = [];
1172
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) t.push(this.parseChild());
1173
- let n = this.consume(i.BlockClose, "Expected closing brace } for @case block");
1174
- r.push({
1222
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) t.push(this.parseChild());
1223
+ let n = this.consume(r.BlockClose, "Expected closing brace } for @case block");
1224
+ i.push({
1175
1225
  expression: e.value,
1176
1226
  body: t,
1177
1227
  loc: {
@@ -1179,11 +1229,11 @@ var y = class {
1179
1229
  end: n.loc.end
1180
1230
  }
1181
1231
  });
1182
- } else if (this.check(i.DirectiveDefault)) {
1232
+ } else if (this.check(r.DirectiveDefault)) {
1183
1233
  let e = this.advance(), t = [];
1184
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) t.push(this.parseChild());
1185
- let n = this.consume(i.BlockClose, "Expected closing brace } for @default block");
1186
- r.push({
1234
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) t.push(this.parseChild());
1235
+ let n = this.consume(r.BlockClose, "Expected closing brace } for @default block");
1236
+ i.push({
1187
1237
  expression: null,
1188
1238
  body: t,
1189
1239
  loc: {
@@ -1191,14 +1241,14 @@ var y = class {
1191
1241
  end: n.loc.end
1192
1242
  }
1193
1243
  });
1194
- } else throw new l(`Unexpected token '${this.peek().value}' inside @switch block. Expected @case or @default.`, this.peek().loc.start.line, this.peek().loc.start.column, this.peek().loc.start.offset);
1244
+ } else throw new c(`Unexpected token '${this.peek().value}' inside @switch block. Expected @case or @default.`, this.peek().loc.start.line, this.peek().loc.start.column, this.peek().loc.start.offset);
1195
1245
  this.skipWhitespaceTokens();
1196
1246
  }
1197
- let a = this.consume(i.BlockClose, "Expected closing brace } for @switch block");
1247
+ let a = this.consume(r.BlockClose, "Expected closing brace } for @switch block");
1198
1248
  return {
1199
- type: s.Switch,
1249
+ type: o.Switch,
1200
1250
  discriminant: n,
1201
- cases: r,
1251
+ cases: i,
1202
1252
  loc: {
1203
1253
  start: t,
1204
1254
  end: a.loc.end
@@ -1206,42 +1256,55 @@ var y = class {
1206
1256
  };
1207
1257
  }
1208
1258
  parseAsyncDirective() {
1209
- let e = this.consume(i.DirectiveAsync, "Expected @async directive"), r = e.loc.start, a = e.value.trim();
1210
- for (; t(a);) a = a.slice(1, -1).trim();
1211
- let o = null;
1259
+ let e = this.consume(r.DirectiveAsync, "Expected @async directive"), n = e.loc.start, i = e.value.trim();
1260
+ for (; v(i);) i = i.slice(1, -1).trim();
1261
+ let a = null;
1212
1262
  try {
1213
- o = n.parseExpressionAt(a, 0, { ecmaVersion: "latest" });
1263
+ a = t.parseExpressionAt(i, 0, { ecmaVersion: "latest" });
1214
1264
  } catch {
1215
- throw new l(`Invalid @async header syntax '${e.value.trim()}'. Expected format: '@async <promise> as <alias>'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1265
+ throw new c(`Invalid @async header syntax '${e.value.trim()}'. Expected format: '@async <promise> as <alias>'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1216
1266
  }
1217
- let c = a.slice(0, o.end).trim(), u = a.slice(o.end).trim(), d = "data";
1218
- if (u.length > 0) if (u.startsWith("as ") || u.startsWith("as ") || u.startsWith("as\n")) for (d = u.slice(2).trim(); t(d);) d = d.slice(1, -1).trim();
1219
- else throw new l(`Unexpected token '${u}' in @async header. Expected 'as <alias>'.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1220
- if (!c || !d) throw new l(`Invalid @async header syntax '${e.value.trim()}'. Expected format: '@async <promise> as <alias>'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1267
+ let s = i.slice(0, a.end).trim(), l = i.slice(a.end).trim(), u = "data", d = null;
1268
+ if (l.length > 0) {
1269
+ let n = null;
1270
+ try {
1271
+ n = t.tokenizer(l, { ecmaVersion: "latest" }).getToken();
1272
+ } catch {}
1273
+ if (n && n.type === t.tokTypes.name && n.value === "as") {
1274
+ let e = l.slice(n.end).trim();
1275
+ for (; v(e);) e = e.slice(1, -1).trim();
1276
+ u = e;
1277
+ try {
1278
+ let n = t.parse(`let ${e} = 0;`, { ecmaVersion: "latest" });
1279
+ n && Array.isArray(n.body) && n.body.length === 1 && n.body[0].type === "VariableDeclaration" && Array.isArray(n.body[0].declarations) && n.body[0].declarations.length === 1 && (d = n.body[0].declarations[0].id);
1280
+ } catch {}
1281
+ } else throw new c(`Unexpected token '${l}' in @async header. Expected 'as <alias>'.`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1282
+ }
1283
+ if (!s || !u) throw new c(`Invalid @async header syntax '${e.value.trim()}'. Expected format: '@async <promise> as <alias>'`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1221
1284
  let f = [];
1222
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) f.push(this.parseChild());
1223
- let p = this.consume(i.BlockClose, "Expected closing brace } for @async block"), m = null, h = null;
1224
- for (; !this.isAtEnd();) if (this.skipWhitespaceTokens(), this.check(i.DirectiveFallback)) {
1285
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) f.push(this.parseChild());
1286
+ let p = this.consume(r.BlockClose, "Expected closing brace } for @async block"), m = null, h = null;
1287
+ for (; !this.isAtEnd();) if (this.skipWhitespaceTokens(), this.check(r.DirectiveFallback)) {
1225
1288
  if (m !== null) {
1226
1289
  let e = this.peek();
1227
- throw new l("Duplicate @fallback directive for @async block", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1290
+ throw new c("Duplicate @fallback directive for @async block", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1228
1291
  }
1229
- this.consume(i.DirectiveFallback, "Expected @fallback directive");
1292
+ this.consume(r.DirectiveFallback, "Expected @fallback directive");
1230
1293
  let e = [];
1231
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) e.push(this.parseChild());
1232
- p = this.consume(i.BlockClose, "Expected closing brace } for @fallback block"), m = e;
1233
- } else if (this.check(i.DirectiveCatch)) {
1294
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) e.push(this.parseChild());
1295
+ p = this.consume(r.BlockClose, "Expected closing brace } for @fallback block"), m = e;
1296
+ } else if (this.check(r.DirectiveCatch)) {
1234
1297
  if (h !== null) {
1235
1298
  let e = this.peek();
1236
- throw new l("Duplicate @catch directive for @async block", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1299
+ throw new c("Duplicate @catch directive for @async block", e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1237
1300
  }
1238
- let e = this.consume(i.DirectiveCatch, "Expected @catch directive"), n = e.value.trim() || "error";
1239
- for (; t(n);) n = n.slice(1, -1).trim();
1240
- let r = [];
1241
- for (; !this.check(i.BlockClose) && !this.isAtEnd();) r.push(this.parseChild());
1242
- p = this.consume(i.BlockClose, "Expected closing brace } for @catch block"), h = {
1243
- errorVar: n,
1244
- body: r,
1301
+ let e = this.consume(r.DirectiveCatch, "Expected @catch directive"), t = e.value.trim() || "error";
1302
+ for (; v(t);) t = t.slice(1, -1).trim();
1303
+ let n = [];
1304
+ for (; !this.check(r.BlockClose) && !this.isAtEnd();) n.push(this.parseChild());
1305
+ p = this.consume(r.BlockClose, "Expected closing brace } for @catch block"), h = {
1306
+ errorVar: t,
1307
+ body: n,
1245
1308
  loc: {
1246
1309
  start: e.loc.start,
1247
1310
  end: p.loc.end
@@ -1249,30 +1312,31 @@ var y = class {
1249
1312
  };
1250
1313
  } else break;
1251
1314
  return {
1252
- type: s.Async,
1253
- promise: c,
1254
- alias: d,
1315
+ type: o.Async,
1316
+ promise: s,
1317
+ alias: u,
1318
+ aliasAst: d,
1255
1319
  body: f,
1256
1320
  fallback: m,
1257
1321
  catchBranch: h,
1258
1322
  loc: {
1259
- start: r,
1323
+ start: n,
1260
1324
  end: p.loc.end
1261
1325
  }
1262
1326
  };
1263
1327
  }
1264
1328
  skipWhitespaceTokens() {
1265
- for (; this.check(i.Text) && this.peek().value.trim().length === 0;) this.advance();
1329
+ for (; this.check(r.Text) && this.peek().value.trim().length === 0;) this.advance();
1266
1330
  }
1267
1331
  isAtEnd() {
1268
- return this.peek().type === i.EOF;
1332
+ return this.peek().type === r.EOF;
1269
1333
  }
1270
1334
  peek(e = 0) {
1271
1335
  return this.ensureLookahead(e), this.lookahead[Math.min(e, this.lookahead.length - 1)];
1272
1336
  }
1273
1337
  advance() {
1274
1338
  let e = this.peek();
1275
- return e.type !== i.EOF && this.lookahead.shift(), e;
1339
+ return e.type !== r.EOF && this.lookahead.shift(), e;
1276
1340
  }
1277
1341
  check(e) {
1278
1342
  return this.peek().type === e;
@@ -1283,12 +1347,12 @@ var y = class {
1283
1347
  consume(e, t) {
1284
1348
  if (this.check(e)) return this.advance();
1285
1349
  let n = this.peek();
1286
- throw new l(t, n.loc.start.line, n.loc.start.column, n.loc.start.offset);
1350
+ throw new c(t, n.loc.start.line, n.loc.start.column, n.loc.start.offset);
1287
1351
  }
1288
1352
  ensureLookahead(e) {
1289
1353
  for (; this.lookahead.length <= e;) {
1290
1354
  let e = this.tokenSource.nextToken();
1291
- if (this.lookahead.push(e), e.type === i.EOF) break;
1355
+ if (this.lookahead.push(e), e.type === r.EOF) break;
1292
1356
  }
1293
1357
  }
1294
1358
  };
@@ -1313,16 +1377,16 @@ function b(e, t) {
1313
1377
  a = e;
1314
1378
  }
1315
1379
  }
1316
- let o = t[a.type];
1317
- if (o) {
1318
- let e = o(a, i);
1380
+ let s = t[a.type];
1381
+ if (s) {
1382
+ let e = s(a, i);
1319
1383
  if (e !== void 0) {
1320
1384
  if (e === null || Array.isArray(e)) return e;
1321
1385
  a = e;
1322
1386
  }
1323
1387
  }
1324
1388
  switch (a.type) {
1325
- case s.Program: {
1389
+ case o.Program: {
1326
1390
  let e = n(a.body, a);
1327
1391
  a = {
1328
1392
  ...a,
@@ -1330,7 +1394,7 @@ function b(e, t) {
1330
1394
  };
1331
1395
  break;
1332
1396
  }
1333
- case s.Element: {
1397
+ case o.Element: {
1334
1398
  let e = a.attributes;
1335
1399
  if (t.Attribute && Array.isArray(a.attributes)) {
1336
1400
  let n = [];
@@ -1348,7 +1412,7 @@ function b(e, t) {
1348
1412
  };
1349
1413
  break;
1350
1414
  }
1351
- case s.If: {
1415
+ case o.If: {
1352
1416
  let e = n(a.consequent, a), t = a.alternate;
1353
1417
  Array.isArray(a.alternate) ? t = n(a.alternate, a) : a.alternate !== null && typeof a.alternate == "object" && (t = r(a.alternate, a)), a = {
1354
1418
  ...a,
@@ -1357,7 +1421,7 @@ function b(e, t) {
1357
1421
  };
1358
1422
  break;
1359
1423
  }
1360
- case s.For: {
1424
+ case o.For: {
1361
1425
  let e = n(a.body, a);
1362
1426
  a = {
1363
1427
  ...a,
@@ -1365,7 +1429,7 @@ function b(e, t) {
1365
1429
  };
1366
1430
  break;
1367
1431
  }
1368
- case s.Switch:
1432
+ case o.Switch:
1369
1433
  if (Array.isArray(a.cases)) {
1370
1434
  let e = a.cases.map((e) => ({
1371
1435
  ...e,
@@ -1377,7 +1441,7 @@ function b(e, t) {
1377
1441
  };
1378
1442
  }
1379
1443
  break;
1380
- case s.Async: {
1444
+ case o.Async: {
1381
1445
  let e = n(a.body, a), t = a.fallback ? n(a.fallback, a) : null, r = a.catchBranch;
1382
1446
  a.catchBranch && (r = {
1383
1447
  ...a.catchBranch,
@@ -1401,20 +1465,19 @@ function b(e, t) {
1401
1465
  }
1402
1466
  var x = class {
1403
1467
  rawAst;
1404
- switchCounter = 0;
1405
1468
  constructor(e) {
1406
1469
  this.rawAst = e;
1407
1470
  }
1408
1471
  transform() {
1409
- return b(b(b(this.rawAst, { Text: (e) => {
1472
+ return b(b(this.rawAst, { Text: (e) => {
1410
1473
  if (typeof e.content == "string" && this.isWhitespaceOnly(e.content)) return null;
1411
- } }), { Switch: (e) => this.transformSwitchToIfChain(e) }), {
1474
+ } }), {
1412
1475
  Interpolation: (e) => this.transformInterpolation(e),
1413
1476
  Element: (e) => {
1414
1477
  if (e.tagName === "script") return this.transformScriptElement(e);
1415
1478
  if (e.attributes.some((e) => e.value !== null && typeof e.value != "string")) return {
1416
1479
  ...e,
1417
- attributes: e.attributes.map((e) => e.type === s.Attribute && e.value !== null && typeof e.value != "string" && e.value.type === s.Interpolation ? {
1480
+ attributes: e.attributes.map((e) => e.type === o.Attribute && e.value !== null && typeof e.value != "string" && e.value.type === o.Interpolation ? {
1418
1481
  ...e,
1419
1482
  value: this.transformInterpolation(e.value)
1420
1483
  } : e)
@@ -1423,139 +1486,75 @@ var x = class {
1423
1486
  If: (e) => {
1424
1487
  if (typeof e.test == "string" && e.test.trim().length > 0) return {
1425
1488
  ...e,
1426
- test: n.parseExpressionAt(e.test, 0, { ecmaVersion: "latest" })
1489
+ test: t.parseExpressionAt(e.test, 0, { ecmaVersion: "latest" })
1427
1490
  };
1428
1491
  },
1429
1492
  For: (e) => ({
1430
1493
  ...e,
1431
- iterable: typeof e.iterable == "string" ? n.parseExpressionAt(e.iterable, 0, { ecmaVersion: "latest" }) : e.iterable,
1432
- key: typeof e.key == "string" && e.key.trim().length > 0 ? n.parseExpressionAt(e.key, 0, { ecmaVersion: "latest" }) : e.key ?? null
1494
+ iterable: typeof e.iterable == "string" ? t.parseExpressionAt(e.iterable, 0, { ecmaVersion: "latest" }) : e.iterable,
1495
+ key: typeof e.key == "string" && e.key.trim().length > 0 ? t.parseExpressionAt(e.key, 0, { ecmaVersion: "latest" }) : e.key ?? null
1433
1496
  }),
1497
+ Switch: (e) => {
1498
+ let n = typeof e.discriminant == "string" && e.discriminant.trim().length > 0 ? t.parseExpressionAt(e.discriminant, 0, { ecmaVersion: "latest" }) : e.discriminant, r = e.cases.map((e) => {
1499
+ let n = e.expression !== null && typeof e.expression == "string" && e.expression.trim().length > 0 ? t.parseExpressionAt(e.expression, 0, { ecmaVersion: "latest" }) : e.expression;
1500
+ return {
1501
+ ...e,
1502
+ expression: n
1503
+ };
1504
+ });
1505
+ return {
1506
+ ...e,
1507
+ discriminant: n,
1508
+ cases: r
1509
+ };
1510
+ },
1434
1511
  Async: (e) => ({
1435
1512
  ...e,
1436
- promise: typeof e.promise == "string" && e.promise.trim().length > 0 ? n.parseExpressionAt(e.promise, 0, { ecmaVersion: "latest" }) : e.promise
1513
+ promise: typeof e.promise == "string" && e.promise.trim().length > 0 ? t.parseExpressionAt(e.promise, 0, { ecmaVersion: "latest" }) : e.promise
1437
1514
  })
1438
1515
  });
1439
1516
  }
1440
- transformSwitchToIfChain(e) {
1441
- let t = typeof e.discriminant == "string" ? n.parseExpressionAt(e.discriminant, 0, { ecmaVersion: "latest" }) : e.discriminant, r = t.type === "Identifier" || t.type === "Literal" || t.type === "MemberExpression", i = `__drift_sw_${this.switchCounter++}`, a = !0, o = (c) => {
1442
- let l = e.cases[c];
1443
- if (!l) return null;
1444
- if (l.expression === null) {
1445
- let e = [...l.body], t = o(c + 1), n = null;
1446
- return (Array.isArray(t) || t !== null && t.type === s.If) && (n = t), c > 0 && n === null ? e : {
1447
- type: s.If,
1448
- test: {
1449
- type: "Literal",
1450
- value: !0,
1451
- raw: "true",
1452
- start: 0,
1453
- end: 0
1454
- },
1455
- consequent: e,
1456
- alternate: n,
1457
- loc: l.loc
1458
- };
1459
- }
1460
- let u = typeof l.expression == "string" && l.expression.trim().length > 0 ? n.parseExpressionAt(l.expression, 0, { ecmaVersion: "latest" }) : l.expression, d;
1461
- r ? d = structuredClone(t) : a ? (a = !1, d = {
1462
- type: "AssignmentExpression",
1463
- operator: "=",
1464
- left: {
1465
- type: "Identifier",
1466
- name: i,
1467
- start: 0,
1468
- end: 0
1469
- },
1470
- right: structuredClone(t),
1471
- start: 0,
1472
- end: 0
1473
- }) : d = {
1474
- type: "Identifier",
1475
- name: i,
1476
- start: 0,
1477
- end: 0
1478
- };
1479
- let f = {
1480
- type: "BinaryExpression",
1481
- operator: "===",
1482
- left: d,
1483
- right: u,
1484
- start: 0,
1485
- end: 0
1486
- }, p = [...l.body], m = o(c + 1), h = null;
1487
- return (Array.isArray(m) || m !== null && m.type === s.If) && (h = m), {
1488
- type: s.If,
1489
- test: f,
1490
- consequent: p,
1491
- alternate: h,
1492
- extraDeps: structuredClone(t),
1493
- loc: l.loc
1494
- };
1495
- }, c = o(0);
1496
- return c ? Array.isArray(c) ? c.length === 0 ? {
1497
- type: s.Comment,
1498
- content: "empty switch",
1499
- loc: e.loc
1500
- } : {
1501
- type: s.If,
1502
- test: {
1503
- type: "Literal",
1504
- value: !0,
1505
- raw: "true",
1506
- start: 0,
1507
- end: 0
1508
- },
1509
- consequent: c,
1510
- alternate: null,
1511
- loc: e.loc
1512
- } : c : {
1513
- type: s.Comment,
1514
- content: "empty switch",
1515
- loc: e.loc
1516
- };
1517
- }
1518
1517
  transformInterpolation(e) {
1519
1518
  if (typeof e.expression != "string") return e;
1520
- let t;
1519
+ let n;
1521
1520
  try {
1522
- t = n.parseExpressionAt(e.expression, 0, {
1521
+ n = t.parseExpressionAt(e.expression, 0, {
1523
1522
  ecmaVersion: "latest",
1524
1523
  allowAwaitOutsideFunction: !0
1525
1524
  });
1526
1525
  } catch (t) {
1527
- throw new l(`Failed to parse JS expression in interpolation: ${t instanceof Error ? t.message : String(t)}`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1526
+ throw new c(`Failed to parse JS expression in interpolation: ${t instanceof Error ? t.message : String(t)}`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1528
1527
  }
1529
1528
  return {
1530
1529
  ...e,
1531
- expression: t
1530
+ expression: n
1532
1531
  };
1533
1532
  }
1534
1533
  transformScriptElement(e) {
1535
- let t = e.children.map((e) => {
1536
- if (e.type === s.Text && typeof e.content == "string") {
1537
- let t;
1534
+ let n = e.children.map((e) => {
1535
+ if (e.type === o.Text && typeof e.content == "string") {
1536
+ let n;
1538
1537
  try {
1539
- let r = n.parse(e.content, {
1538
+ let r = t.parse(e.content, {
1540
1539
  ecmaVersion: "latest",
1541
1540
  sourceType: "module",
1542
1541
  allowAwaitOutsideFunction: !0,
1543
1542
  allowReturnOutsideFunction: !0
1544
1543
  });
1545
- t = r.body.length === 1 && r.body[0] !== void 0 ? r.body[0] : r.body;
1544
+ n = r.body.length === 1 && r.body[0] !== void 0 ? r.body[0] : r.body;
1546
1545
  } catch (t) {
1547
- throw new l(`Failed to parse script tag JS content: ${t instanceof Error ? t.message : String(t)}`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1546
+ throw new c(`Failed to parse script tag JS content: ${t instanceof Error ? t.message : String(t)}`, e.loc.start.line, e.loc.start.column, e.loc.start.offset);
1548
1547
  }
1549
1548
  return {
1550
1549
  ...e,
1551
- content: t
1550
+ content: n
1552
1551
  };
1553
1552
  }
1554
1553
  return e;
1555
1554
  });
1556
1555
  return {
1557
1556
  ...e,
1558
- children: t
1557
+ children: n
1559
1558
  };
1560
1559
  }
1561
1560
  isWhitespaceOnly(e) {
@@ -1579,7 +1578,7 @@ var x = class {
1579
1578
  generate() {
1580
1579
  if (this.bytecode = [], this.constants = [], this.nextRegisterId = 0, this.declaredVars = /* @__PURE__ */ new Set(), this.imports = [], this.bindingPositions = /* @__PURE__ */ new Map(), this.derivedBindings = [], this.pendingDerived = [], this.effectBindings = [], this.pendingEffects = [], this.collectDeclaredVars(this.ast.body), this.processDerivedBindings(), this.processEffectBindings(), this.ast.body.length === 0) {
1581
1580
  let e = this.allocRegister();
1582
- return this.emit(u.CREATE_FRAGMENT, e), {
1581
+ return this.emit(l.CREATE_FRAGMENT, e), {
1583
1582
  bytecode: this.bytecode,
1584
1583
  constants: this.constants,
1585
1584
  reactiveBindings: this.buildReactiveBindings(),
@@ -1589,12 +1588,12 @@ var x = class {
1589
1588
  imports: this.imports
1590
1589
  };
1591
1590
  }
1592
- if (this.ast.body.length === 1 && this.ast.body[0]?.type === s.Element) {
1591
+ if (this.ast.body.length === 1 && this.ast.body[0]?.type === o.Element) {
1593
1592
  let e = this.allocRegister();
1594
1593
  this.compileElement(this.ast.body[0], e);
1595
1594
  } else {
1596
1595
  let e = this.allocRegister();
1597
- this.emit(u.CREATE_FRAGMENT, e);
1596
+ this.emit(l.CREATE_FRAGMENT, e);
1598
1597
  for (let t of this.ast.body) this.compileNode(t, e);
1599
1598
  }
1600
1599
  return {
@@ -1609,25 +1608,28 @@ var x = class {
1609
1608
  }
1610
1609
  compileNode(e, t) {
1611
1610
  switch (e.type) {
1612
- case s.Element:
1611
+ case o.Element:
1613
1612
  e.tagName === "script" ? this.compileScriptElement(e) : this.compileElementNode(e, t);
1614
1613
  break;
1615
- case s.Text:
1614
+ case o.Text:
1616
1615
  this.compileTextNode(e, t);
1617
1616
  break;
1618
- case s.Interpolation:
1617
+ case o.Interpolation:
1619
1618
  this.compileInterpolationNode(e, t);
1620
1619
  break;
1621
- case s.Comment:
1620
+ case o.Comment:
1622
1621
  this.compileCommentNode(e, t);
1623
1622
  break;
1624
- case s.If:
1623
+ case o.If:
1625
1624
  this.compileIfNode(e, t);
1626
1625
  break;
1627
- case s.For:
1626
+ case o.Switch:
1627
+ this.compileSwitchNode(e, t);
1628
+ break;
1629
+ case o.For:
1628
1630
  this.compileForNode(e, t);
1629
1631
  break;
1630
- case s.Async:
1632
+ case o.Async:
1631
1633
  this.compileAsyncNode(e, t);
1632
1634
  break;
1633
1635
  }
@@ -1652,11 +1654,11 @@ var x = class {
1652
1654
  return e;
1653
1655
  }
1654
1656
  compileScriptElement(e) {
1655
- for (let t of e.children) if (t.type === s.Text && typeof t.content == "object" && t.content !== null) {
1657
+ for (let t of e.children) if (t.type === o.Text && typeof t.content == "object" && t.content !== null) {
1656
1658
  let e = this.filterRuntimeScriptAst(t.content);
1657
1659
  if (e !== null && (!Array.isArray(e) || e.length > 0)) {
1658
1660
  let t = this.addScriptConstant(e);
1659
- this.emit(u.EXEC_SCRIPT, t);
1661
+ this.emit(l.EXEC_SCRIPT, t);
1660
1662
  }
1661
1663
  }
1662
1664
  }
@@ -1669,66 +1671,66 @@ var x = class {
1669
1671
  let n = this.isComponentTag(e.tagName), r = this.addConstant(e.tagName);
1670
1672
  if (n) {
1671
1673
  let n = { __drift_props__: !0 };
1672
- for (let t of e.attributes) if (t.type === s.Attribute) {
1674
+ for (let t of e.attributes) if (t.type === o.Attribute) {
1673
1675
  if (t.value === null) n[t.name] = !0;
1674
1676
  else if (typeof t.value == "string") n[t.name] = t.value;
1675
- else if (t.value.type === s.Interpolation) {
1677
+ else if (t.value.type === o.Interpolation) {
1676
1678
  let e = t.value.expression;
1677
1679
  if (e && typeof e == "object" && e.type) {
1678
- let r = O(e);
1680
+ let r = k(e);
1679
1681
  n[t.name] = { __drift_fn__: `(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => (${r})` };
1680
1682
  } else n[t.name] = e;
1681
1683
  }
1682
1684
  }
1683
1685
  let i = null;
1684
1686
  if (e.children && e.children.length > 0) {
1685
- let t = e.children.filter((e) => !(e.type === s.Text && typeof e.content == "string" && e.content.trim() === ""));
1687
+ let t = e.children.filter((e) => !(e.type === o.Text && typeof e.content == "string" && e.content.trim() === ""));
1686
1688
  t.length > 0 && (i = this.compileNodesToSubModule(t), n.__drift_children__ = this.addConstant(i));
1687
1689
  }
1688
- let a = Object.keys(n).length > 1 ? this.addConstant(n) : 255, o = this.bytecode.length;
1689
- this.emit(u.MOUNT_COMPONENT, t, r, a), this.emit(u.RETURN);
1690
- for (let t of e.attributes) t.type === s.Attribute && t.value !== null && typeof t.value != "string" && t.value.type === s.Interpolation && this.recordBindingPositions(t.value.expression, o);
1691
- if (i) for (let e of i.reactiveBindings) this.declaredVars.has(e.variable) && (this.bindingPositions.has(e.variable) || this.bindingPositions.set(e.variable, []), this.bindingPositions.get(e.variable).push(o));
1690
+ let a = Object.keys(n).length > 1 ? this.addConstant(n) : 255, s = this.bytecode.length;
1691
+ this.emit(l.MOUNT_COMPONENT, t, r, a), this.emit(l.RETURN);
1692
+ for (let t of e.attributes) t.type === o.Attribute && t.value !== null && typeof t.value != "string" && t.value.type === o.Interpolation && this.recordBindingPositions(t.value.expression, s);
1693
+ if (i) for (let e of i.reactiveBindings) this.declaredVars.has(e.variable) && (this.bindingPositions.has(e.variable) || this.bindingPositions.set(e.variable, []), this.bindingPositions.get(e.variable).push(s));
1692
1694
  } else {
1693
- this.emit(u.CREATE_ELEMENT, t, r);
1695
+ this.emit(l.CREATE_ELEMENT, t, r);
1694
1696
  for (let n of e.attributes) this.compileAttributeNode(n, t);
1695
1697
  for (let n of e.children) this.compileNode(n, t);
1696
1698
  }
1697
1699
  }
1698
1700
  compileElementNode(e, t) {
1699
1701
  let n = this.allocRegister();
1700
- this.compileElement(e, n), this.emit(u.APPEND_CHILD, t, n);
1702
+ this.compileElement(e, n), this.emit(l.APPEND_CHILD, t, n);
1701
1703
  }
1702
1704
  compileAttributeNode(e, t) {
1703
1705
  let n = this.addConstant(e.name);
1704
1706
  if (e.value === null) {
1705
1707
  let e = this.addConstant(!0);
1706
- this.emit(u.SET_ATTR, t, n, e, 0);
1708
+ this.emit(l.SET_ATTR, t, n, e, 0);
1707
1709
  } else if (typeof e.value == "string") {
1708
1710
  let r = this.addConstant(e.value);
1709
- this.emit(u.SET_ATTR, t, n, r, 0);
1710
- } else if (e.value.type === s.Interpolation) {
1711
+ this.emit(l.SET_ATTR, t, n, r, 0);
1712
+ } else if (e.value.type === o.Interpolation) {
1711
1713
  let r = this.addExpressionConstant(e.value.expression), i = this.bytecode.length;
1712
- this.emit(u.SET_ATTR, t, n, r, 1), this.emit(u.RETURN), this.recordBindingPositions(e.value.expression, i);
1714
+ this.emit(l.SET_ATTR, t, n, r, 1), this.emit(l.RETURN), this.recordBindingPositions(e.value.expression, i);
1713
1715
  }
1714
1716
  }
1715
1717
  compileTextNode(e, t) {
1716
1718
  let n = this.allocRegister(), r = this.addConstant(e.content);
1717
- this.emit(u.CREATE_TEXT, n, r), this.emit(u.APPEND_CHILD, t, n);
1719
+ this.emit(l.CREATE_TEXT, n, r), this.emit(l.APPEND_CHILD, t, n);
1718
1720
  }
1719
1721
  compileInterpolationNode(e, t) {
1720
1722
  let n = this.allocRegister(), r = this.addExpressionConstant(e.expression), i = this.bytecode.length;
1721
- this.emit(u.INTERPOLATE_TEXT, n, r), this.emit(u.RETURN), this.emit(u.APPEND_CHILD, t, n), this.recordBindingPositions(e.expression, i);
1723
+ this.emit(l.INTERPOLATE_TEXT, n, r), this.emit(l.RETURN), this.emit(l.APPEND_CHILD, t, n), this.recordBindingPositions(e.expression, i);
1722
1724
  }
1723
1725
  compileCommentNode(e, t) {
1724
1726
  let n = this.allocRegister(), r = this.addConstant(e.content);
1725
- this.emit(u.CREATE_COMMENT, n, r), this.emit(u.APPEND_CHILD, t, n);
1727
+ this.emit(l.CREATE_COMMENT, n, r), this.emit(l.APPEND_CHILD, t, n);
1726
1728
  }
1727
1729
  compileNodesToSubModule(e) {
1728
1730
  let t = this.bytecode, n = this.constants, r = this.nextRegisterId, i = this.bindingPositions;
1729
1731
  this.bytecode = [], this.constants = [], this.nextRegisterId = 0, this.bindingPositions = /* @__PURE__ */ new Map();
1730
1732
  let a = this.allocRegister();
1731
- this.emit(u.CREATE_FRAGMENT, a);
1733
+ this.emit(l.CREATE_FRAGMENT, a);
1732
1734
  for (let t of e) this.compileNode(t, a);
1733
1735
  let o = {
1734
1736
  bytecode: this.bytecode,
@@ -1757,16 +1759,47 @@ var x = class {
1757
1759
  }
1758
1760
  if (a) for (let e of this.collectDepsFromSubModule(a)) o.add(e);
1759
1761
  let s = this.addConstant(Array.from(o)), c = this.addExpressionConstant(e.test);
1760
- this.emit(u.REACTIVE_IF, t, c, r, i, s);
1762
+ this.emit(l.REACTIVE_IF, t, c, r, i, s);
1763
+ }
1764
+ compileSwitchNode(e, t) {
1765
+ let n = this.addExpressionConstant(e.discriminant), r = [], i = 255, a = [];
1766
+ for (let t of e.cases) if (t.expression === null) {
1767
+ let e = this.compileNodesToSubModule(t.body);
1768
+ a.push(e), i = this.addConstant(e);
1769
+ } else {
1770
+ let e = this.addExpressionConstant(t.expression), n = this.compileNodesToSubModule(t.body);
1771
+ a.push(n);
1772
+ let i = this.addConstant(n);
1773
+ r.push({
1774
+ testIdx: e,
1775
+ modIdx: i
1776
+ });
1777
+ }
1778
+ let o = this.addConstant(r), s = /* @__PURE__ */ new Set();
1779
+ for (let t of this.extractIdentifiers(e.discriminant)) this.declaredVars.has(t) && s.add(t);
1780
+ for (let t of e.cases) if (t.expression !== null) for (let e of this.extractIdentifiers(t.expression)) this.declaredVars.has(e) && s.add(e);
1781
+ for (let e of a) for (let t of this.collectDepsFromSubModule(e)) s.add(t);
1782
+ let c = this.addConstant(Array.from(s));
1783
+ this.emit(l.REACTIVE_SWITCH, t, n, o, i, c);
1761
1784
  }
1762
1785
  compileForNode(e, t) {
1763
- let n = this.compileNodesToSubModule(e.body), r = this.addConstant(n), i = this.addExpressionConstant(e.iterable), a = this.addConstant(e.item), o = e.index === null ? 255 : this.addConstant(e.index), s = e.key ? this.addExpressionConstant(e.key) : 255, c = /* @__PURE__ */ new Set();
1764
- for (let t of this.extractIdentifiers(e.iterable)) this.declaredVars.has(t) && c.add(t);
1765
- if (e.key) for (let t of this.extractIdentifiers(e.key)) this.declaredVars.has(t) && c.add(t);
1766
- let l = this.addConstant([...c]), d = /* @__PURE__ */ new Set();
1767
- for (let e of n.reactiveBindings) c.has(e.variable) || d.add(e.variable);
1768
- let f = this.addConstant([...d]), p = [...c, ...d], m = this.addConstant(p);
1769
- this.emit(u.REACTIVE_FOR, t, i, a, o, s, r, m, l, f);
1786
+ let n = /* @__PURE__ */ new Set();
1787
+ if (e.pattern) for (let t of w(e.pattern)) n.add(t);
1788
+ else e.item && n.add(e.item);
1789
+ e.index !== null && n.add(e.index);
1790
+ let r = [];
1791
+ for (let e of n) this.declaredVars.has(e) || (this.declaredVars.add(e), r.push(e));
1792
+ let i = this.compileNodesToSubModule(e.body);
1793
+ for (let e of r) this.declaredVars.delete(e);
1794
+ let a = this.addConstant(i), o = this.addExpressionConstant(e.iterable), s = this.addConstant(e.item), c = e.index === null ? 255 : this.addConstant(e.index), u = e.key ? this.addExpressionConstant(e.key) : 255, d = 255;
1795
+ e.pattern && (d = this.addConstant(O(e.pattern, e.index)));
1796
+ let f = /* @__PURE__ */ new Set();
1797
+ for (let t of this.extractIdentifiers(e.iterable)) this.declaredVars.has(t) && f.add(t);
1798
+ if (e.key) for (let t of this.extractIdentifiers(e.key)) this.declaredVars.has(t) && f.add(t);
1799
+ let p = this.addConstant([...f]), m = /* @__PURE__ */ new Set();
1800
+ for (let e of i.reactiveBindings) !f.has(e.variable) && !n.has(e.variable) && m.add(e.variable);
1801
+ let h = this.addConstant([...m]), g = [...f, ...m], _ = this.addConstant(g);
1802
+ this.emit(l.REACTIVE_FOR, t, o, s, c, u, a, _, p, h, d);
1770
1803
  }
1771
1804
  compileAsyncNode(e, t) {
1772
1805
  let n = this.compileNodesToSubModule(e.body), r = this.addConstant(n), i = e.fallback ? this.compileNodesToSubModule(e.fallback) : null, a = i ? this.addConstant(i) : 255, o = 255;
@@ -1777,15 +1810,17 @@ var x = class {
1777
1810
  module: t
1778
1811
  });
1779
1812
  }
1780
- let s = this.addExpressionConstant(e.promise), c = this.addConstant(e.alias), l = /* @__PURE__ */ new Set();
1781
- for (let t of this.collectDepsFromSubModule(n, e.promise)) l.add(t);
1782
- if (i) for (let e of this.collectDepsFromSubModule(i)) l.add(e);
1783
- let d = this.addConstant(Array.from(l));
1784
- this.emit(u.REACTIVE_ASYNC, t, s, c, r, a, o, d);
1813
+ let s = this.addExpressionConstant(e.promise), c = this.addConstant(e.alias), u = 255;
1814
+ e.aliasAst && (u = this.addConstant(O(e.aliasAst, null)));
1815
+ let d = /* @__PURE__ */ new Set();
1816
+ for (let t of this.collectDepsFromSubModule(n, e.promise)) d.add(t);
1817
+ if (i) for (let e of this.collectDepsFromSubModule(i)) d.add(e);
1818
+ let f = this.addConstant(Array.from(d));
1819
+ this.emit(l.REACTIVE_ASYNC, t, s, c, r, a, o, f, u);
1785
1820
  }
1786
1821
  collectDeclaredVars(e) {
1787
- for (let t of e) if (t.type === s.Element && t.tagName === "script") {
1788
- for (let e of t.children) if (e.type === s.Text && typeof e.content == "object" && e.content !== null) {
1822
+ for (let t of e) if (t.type === o.Element && t.tagName === "script") {
1823
+ for (let e of t.children) if (e.type === o.Text && typeof e.content == "object" && e.content !== null) {
1789
1824
  let t = e.content;
1790
1825
  if (Array.isArray(t)) for (let e of t) this.extractVarNames(e);
1791
1826
  else this.extractVarNames(t);
@@ -1830,7 +1865,7 @@ var x = class {
1830
1865
  for (let e of this.pendingDerived) {
1831
1866
  let { name: t, arg: n } = e, r = n, i = !1;
1832
1867
  (n.type === "ArrowFunctionExpression" || n.type === "FunctionExpression") && (n.body?.type === "BlockStatement" && (i = !0), r = n.body);
1833
- let a = [...this.extractIdentifiers(r)].filter((e) => e !== t && this.declaredVars.has(e)), o = O(r), s;
1868
+ let a = [...this.extractIdentifiers(r)].filter((e) => e !== t && this.declaredVars.has(e)), o = k(r), s;
1834
1869
  s = i ? { __drift_fn__: `(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => ${o}` } : { __drift_fn__: `(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => (${o})` };
1835
1870
  let c = this.addConstant(s);
1836
1871
  this.derivedBindings.push({
@@ -1844,7 +1879,7 @@ var x = class {
1844
1879
  for (let e of this.pendingEffects) {
1845
1880
  let { arg: t } = e, n = t, r = !1, i = !!t?.async;
1846
1881
  (t.type === "ArrowFunctionExpression" || t.type === "FunctionExpression") && (t.body?.type === "BlockStatement" && (r = !0), n = t.body);
1847
- let a = [...this.extractIdentifiers(n)].filter((e) => this.declaredVars.has(e)), o = O(n), s = i ? "async " : "", c;
1882
+ let a = [...this.extractIdentifiers(n)].filter((e) => this.declaredVars.has(e)), o = k(n), s = i ? "async " : "", c;
1848
1883
  c = r ? { __drift_fn__: `${s}(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => ${o}` } : { __drift_fn__: `${s}(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => (${o})` };
1849
1884
  let l = this.addConstant(c);
1850
1885
  this.effectBindings.push({
@@ -1857,7 +1892,7 @@ var x = class {
1857
1892
  let t = /* @__PURE__ */ new Set();
1858
1893
  if (!e || typeof e != "object") return t;
1859
1894
  try {
1860
- r.ancestor(e, { Identifier(e, n) {
1895
+ n.ancestor(e, { Identifier(e, n) {
1861
1896
  let r = n[n.length - 2];
1862
1897
  r && (r.type === "MemberExpression" && r.property === e && !r.computed || (r.type === "Property" || r.type === "MethodDefinition" || r.type === "PropertyDefinition") && r.key === e && !r.computed) || t.add(e.name);
1863
1898
  } });
@@ -1881,7 +1916,7 @@ var x = class {
1881
1916
  return this.nextRegisterId++;
1882
1917
  }
1883
1918
  addExpressionConstant(e) {
1884
- let t = O(e), n = [];
1919
+ let t = k(e), n = [];
1885
1920
  for (let t of this.extractIdentifiers(e)) this.declaredVars.has(t) && n.push(t);
1886
1921
  let r = {
1887
1922
  __drift_fn__: `(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => (${t})`,
@@ -1890,7 +1925,7 @@ var x = class {
1890
1925
  return this.addConstant(r);
1891
1926
  }
1892
1927
  addScriptConstant(e) {
1893
- let t = { __drift_fn__: `(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => { ${O(e)}; }` };
1928
+ let t = { __drift_fn__: `(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => { ${k(e)}; }` };
1894
1929
  return this.addConstant(t);
1895
1930
  }
1896
1931
  addConstant(e) {
@@ -1921,21 +1956,21 @@ function T(e, t) {
1921
1956
  if (!e) return "";
1922
1957
  switch (e.type) {
1923
1958
  case "Identifier": return e.name;
1924
- case "AssignmentPattern": return `${T(e.left, t)} = ${O(e.right, t)}`;
1959
+ case "AssignmentPattern": return `${T(e.left, t)} = ${k(e.right, t)}`;
1925
1960
  case "RestElement": return `...${T(e.argument, t)}`;
1926
1961
  case "ArrayPattern": return `[${(e.elements || []).map((e) => e ? T(e, t) : "").join(", ")}]`;
1927
1962
  case "ObjectPattern": return `{ ${(e.properties || []).map((e) => {
1928
1963
  if (e.type === "Property") {
1929
- let n = e.key?.name || (typeof e.key?.value == "string" ? JSON.stringify(e.key.value) : e.key?.value ? String(e.key.value) : O(e.key, t));
1964
+ let n = e.key?.name || (typeof e.key?.value == "string" ? JSON.stringify(e.key.value) : e.key?.value ? String(e.key.value) : k(e.key, t));
1930
1965
  if (e.value?.type === "AssignmentPattern") {
1931
- let r = e.value.left?.name || T(e.value.left, t), i = O(e.value.right, t);
1966
+ let r = e.value.left?.name || T(e.value.left, t), i = k(e.value.right, t);
1932
1967
  return n === r || e.shorthand ? `${n} = ${i}` : `${n}: ${r} = ${i}`;
1933
1968
  } else if (e.value?.type === "Identifier" && e.value.name === n) return n;
1934
1969
  else return `${n}: ${T(e.value, t)}`;
1935
1970
  } else if (e.type === "RestElement") return `...${T(e.argument, t)}`;
1936
1971
  return "";
1937
1972
  }).filter(Boolean).join(", ")} }`;
1938
- default: return e.name || O(e, t);
1973
+ default: return e.name || k(e, t);
1939
1974
  }
1940
1975
  }
1941
1976
  function E(e, t, n) {
@@ -1946,7 +1981,7 @@ function D(e, t, n, r = { count: 0 }) {
1946
1981
  if (!e) return i;
1947
1982
  if (e.type === "Identifier") return i.push(E(e.name, t, n)), i;
1948
1983
  if (e.type === "AssignmentPattern") {
1949
- let a = `((${t} !== undefined) ? ${t} : ${O(e.right, n)})`;
1984
+ let a = `((${t} !== undefined) ? ${t} : ${k(e.right, n)})`;
1950
1985
  if (e.left?.type === "Identifier") i.push(E(e.left.name, a, n));
1951
1986
  else {
1952
1987
  let t = `_t${r.count++}`;
@@ -1956,12 +1991,12 @@ function D(e, t, n, r = { count: 0 }) {
1956
1991
  }
1957
1992
  if (e.type === "ObjectPattern") {
1958
1993
  for (let a of e.properties || []) if (a.type === "Property") {
1959
- let e = a.computed ? O(a.key, n) : a.key?.name === void 0 ? typeof a.key?.value == "string" || typeof a.key?.value == "number" ? JSON.stringify(a.key.value) : O(a.key, n) : JSON.stringify(a.key.name);
1994
+ let e = a.computed ? k(a.key, n) : a.key?.name === void 0 ? typeof a.key?.value == "string" || typeof a.key?.value == "number" ? JSON.stringify(a.key.value) : k(a.key, n) : JSON.stringify(a.key.name);
1960
1995
  if (a.value?.type === "Identifier") {
1961
1996
  let r = `(${t} ? ${t}[${e}] : undefined)`;
1962
1997
  i.push(E(a.value.name, r, n));
1963
1998
  } else if (a.value?.type === "AssignmentPattern") {
1964
- let o = `((${t} && ${t}[${e}] !== undefined) ? ${t}[${e}] : ${O(a.value.right, n)})`;
1999
+ let o = `((${t} && ${t}[${e}] !== undefined) ? ${t}[${e}] : ${k(a.value.right, n)})`;
1965
2000
  if (a.value.left?.type === "Identifier") i.push(E(a.value.left.name, o, n));
1966
2001
  else {
1967
2002
  let e = `_t${r.count++}`;
@@ -1971,16 +2006,23 @@ function D(e, t, n, r = { count: 0 }) {
1971
2006
  let o = `_t${r.count++}`, s = `(${t} ? ${t}[${e}] : undefined)`;
1972
2007
  i.push(`const ${o} = ${s}`), i.push(...D(a.value, o, n, r));
1973
2008
  } else {
1974
- let r = a.value?.name || O(a.value, n);
2009
+ let r = a.value?.name || k(a.value, n);
1975
2010
  if (r) {
1976
2011
  let a = `(${t} ? ${t}[${e}] : undefined)`;
1977
2012
  i.push(E(r, a, n));
1978
2013
  }
1979
2014
  }
1980
2015
  } else if (a.type === "RestElement") {
1981
- let r = a.argument?.name || O(a.argument, n);
2016
+ let r = a.argument?.name || k(a.argument, n);
1982
2017
  if (r) {
1983
- let a = (e.properties || []).filter((e) => e.type === "Property").map((e) => e.key?.name || (typeof e.key?.value == "string" ? e.key.value : "")).filter(Boolean), o = `(() => { const _r = Object.assign({}, ${t}); ${JSON.stringify(a)}.forEach(k => delete _r[k]); return _r; })()`;
2018
+ (e.properties || []).filter((e) => e.type === "Property").map((e) => {
2019
+ let t = e.key?.name === void 0 ? typeof e.key?.value == "string" ? e.key.value : null : e.key.name;
2020
+ return t == null ? null : JSON.stringify(t);
2021
+ }).filter(Boolean);
2022
+ let a = (e.properties || []).filter((e) => e.type === "Property").map((e) => {
2023
+ let t = e.key?.name === void 0 ? typeof e.key?.value == "string" ? e.key.value : null : e.key.name;
2024
+ return t == null ? null : String(t);
2025
+ }).filter(Boolean).join(", "), o = `(((${a.length > 0 ? `{ ${a}, ...${r} }` : `{ ...${r} }`}) => ${r})(${t} ?? {}))`;
1984
2026
  i.push(E(r, o, n));
1985
2027
  }
1986
2028
  }
@@ -1997,14 +2039,14 @@ function D(e, t, n, r = { count: 0 }) {
1997
2039
  let r = `(${a} ? ${a}[${e}] : undefined)`;
1998
2040
  i.push(E(t.name, r, n));
1999
2041
  } else if (t.type === "AssignmentPattern") {
2000
- let o = O(t.right, n), s = `((${a} && ${a}[${e}] !== undefined) ? ${a}[${e}] : ${o})`;
2042
+ let o = k(t.right, n), s = `((${a} && ${a}[${e}] !== undefined) ? ${a}[${e}] : ${o})`;
2001
2043
  if (t.left?.type === "Identifier") i.push(E(t.left.name, s, n));
2002
2044
  else {
2003
2045
  let e = `_t${r.count++}`;
2004
2046
  i.push(`const ${e} = ${s}`), i.push(...D(t.left, e, n, r));
2005
2047
  }
2006
2048
  } else if (t.type === "RestElement") {
2007
- let r = t.argument?.name || O(t.argument, n);
2049
+ let r = t.argument?.name || k(t.argument, n);
2008
2050
  if (r) {
2009
2051
  let t = `((${a} && typeof ${a}.slice === 'function') ? ${a}.slice(${e}) : [])`;
2010
2052
  i.push(E(r, t, n));
@@ -2020,40 +2062,32 @@ function D(e, t, n, r = { count: 0 }) {
2020
2062
  return i;
2021
2063
  }
2022
2064
  function O(e, t) {
2065
+ let n = [], r = D(e, "_item", void 0, { count: 0 });
2066
+ return n.push(...r), t && n.push(E(t, "_index", void 0)), { __drift_fn__: `(scope, declaredVars, setScopeValue, inScopeChain, resolveIterable, getScopeValue) => (_item, _index) => { ${n.join("; ")}; }` };
2067
+ }
2068
+ function k(e, t) {
2023
2069
  if (e == null) return "undefined";
2024
2070
  if (typeof e != "object") return typeof e == "string" ? JSON.stringify(e) : String(e);
2025
- if (Array.isArray(e)) return e.map((e) => O(e, t)).join("; ");
2071
+ if (Array.isArray(e)) return e.map((e) => k(e, t)).join("; ");
2026
2072
  switch (e.type) {
2027
- case "Identifier": return t && t.has(e.name) ? e.name : `(typeof getScopeValue === 'function' ? getScopeValue(scope, ${JSON.stringify(e.name)}) : (typeof inScopeChain === 'function' && inScopeChain(scope, ${JSON.stringify(e.name)}) ? scope[${JSON.stringify(e.name)}] : (typeof globalThis !== 'undefined' && globalThis && (${JSON.stringify(e.name)} in globalThis) ? globalThis[${JSON.stringify(e.name)}] : (scope || {})[${JSON.stringify(e.name)}])))`;
2073
+ case "Identifier": return t && t.has(e.name) ? e.name : e.name === "undefined" ? "undefined" : `getScopeValue(scope, ${JSON.stringify(e.name)})`;
2028
2074
  case "Literal": return typeof e.raw == "string" ? e.raw : typeof e.value == "string" ? JSON.stringify(e.value) : String(e.value);
2029
2075
  case "BinaryExpression":
2030
- case "LogicalExpression": return `(${O(e.left, t)} ${e.operator} ${O(e.right, t)})`;
2031
- case "UnaryExpression": return `(${e.operator} ${O(e.argument, t)})`;
2032
- case "AwaitExpression": return `(await ${O(e.argument, t)})`;
2033
- case "YieldExpression": return e.delegate ? `(yield* ${e.argument ? O(e.argument, t) : ""})` : `(yield ${e.argument ? O(e.argument, t) : ""})`;
2034
- case "ConditionalExpression": return `(${O(e.test, t)} ? ${O(e.consequent, t)} : ${O(e.alternate, t)})`;
2076
+ case "LogicalExpression": return `(${k(e.left, t)} ${e.operator} ${k(e.right, t)})`;
2077
+ case "UnaryExpression": return `(${e.operator} ${k(e.argument, t)})`;
2078
+ case "AwaitExpression": return `(await ${k(e.argument, t)})`;
2079
+ case "YieldExpression": return e.delegate ? `(yield* ${e.argument ? k(e.argument, t) : ""})` : `(yield ${e.argument ? k(e.argument, t) : ""})`;
2080
+ case "ConditionalExpression": return `(${k(e.test, t)} ? ${k(e.consequent, t)} : ${k(e.alternate, t)})`;
2035
2081
  case "MemberExpression": {
2036
2082
  let n = e.optional ? "?." : ".";
2037
- return e.computed ? e.optional ? `(${O(e.object, t)}?.[${O(e.property, t)}])` : `(${O(e.object, t)}[${O(e.property, t)}])` : `(${O(e.object, t)}${n}${e.property.name})`;
2083
+ return e.computed ? e.optional ? `(${k(e.object, t)}?.[${k(e.property, t)}])` : `(${k(e.object, t)}[${k(e.property, t)}])` : `(${k(e.object, t)}${n}${e.property.name})`;
2038
2084
  }
2039
2085
  case "CallExpression": {
2040
- let n = O(e.callee, t), r = e.arguments ? e.arguments.map((e) => O(e, t)).join(", ") : "", i = `(${n}${e.optional ? "?.(" : "("}${r}))`;
2041
- if (e.callee?.type === "MemberExpression" && e.callee.property?.type === "Identifier") {
2042
- let n = C(e.callee.object), r = e.callee.property.name;
2043
- if (n && [
2044
- "push",
2045
- "pop",
2046
- "shift",
2047
- "unshift",
2048
- "splice",
2049
- "sort",
2050
- "reverse"
2051
- ].includes(r) && (!t || !t.has(n))) return `(() => { const _res = ${i}; if (typeof setScopeValue === 'function' && scope && typeof inScopeChain === 'function' && inScopeChain(scope, ${JSON.stringify(n)})) setScopeValue(scope, ${JSON.stringify(n)}, scope[${JSON.stringify(n)}]); return _res; })()`;
2052
- }
2053
- return i;
2086
+ let n = k(e.callee, t), r = e.arguments ? e.arguments.map((e) => k(e, t)).join(", ") : "";
2087
+ return `(${n}${e.optional ? "?.(" : "("}${r}))`;
2054
2088
  }
2055
2089
  case "AssignmentExpression": {
2056
- let n = O(e.right, t);
2090
+ let n = k(e.right, t);
2057
2091
  if (e.left?.type === "Identifier") {
2058
2092
  let r = e.left.name;
2059
2093
  if (t && t.has(r)) return `(${r} ${e.operator} ${n})`;
@@ -2064,10 +2098,10 @@ function O(e, t) {
2064
2098
  }
2065
2099
  }
2066
2100
  if (e.left?.type === "MemberExpression") {
2067
- let r = C(e.left), i = `(${O(e.left, t)} ${e.operator} ${n})`;
2101
+ let r = C(e.left), i = `(${k(e.left, t)} ${e.operator} ${n})`;
2068
2102
  if (r && (!t || !t.has(r))) return `(() => { const _res = ${i}; if (typeof setScopeValue === 'function' && scope && typeof inScopeChain === 'function' && inScopeChain(scope, ${JSON.stringify(r)})) setScopeValue(scope, ${JSON.stringify(r)}, scope[${JSON.stringify(r)}]); return _res; })()`;
2069
2103
  }
2070
- return e.left?.type === "ObjectPattern" || e.left?.type === "ArrayPattern" ? `((_val) => { ${D(e.left, "_val", t).join("; ")}; return _val; })(${n})` : `(${O(e.left, t)} ${e.operator} ${n})`;
2104
+ return e.left?.type === "ObjectPattern" || e.left?.type === "ArrayPattern" ? `((_val) => { ${D(e.left, "_val", t).join("; ")}; return _val; })(${n})` : `(${k(e.left, t)} ${e.operator} ${n})`;
2071
2105
  }
2072
2106
  case "UpdateExpression":
2073
2107
  if (e.argument?.type === "Identifier") {
@@ -2077,22 +2111,22 @@ function O(e, t) {
2077
2111
  return e.prefix ? `(typeof setScopeValue === 'function' ? (setScopeValue(scope, ${JSON.stringify(n)}, (Number(scope[${JSON.stringify(n)}]) || 0) ${r} 1), scope[${JSON.stringify(n)}]) : ((scope || {})[${JSON.stringify(n)}] = (Number((scope || {})[${JSON.stringify(n)}]) || 0) ${r} 1))` : `(() => { const _v = Number(scope[${JSON.stringify(n)}]) || 0; if (typeof setScopeValue === 'function') setScopeValue(scope, ${JSON.stringify(n)}, _v ${r} 1); else (scope || {})[${JSON.stringify(n)}] = _v ${r} 1; return _v; })()`;
2078
2112
  }
2079
2113
  if (e.argument?.type === "MemberExpression") {
2080
- let n = C(e.argument), r = e.prefix ? `(${e.operator}${O(e.argument, t)})` : `(${O(e.argument, t)}${e.operator})`;
2114
+ let n = C(e.argument), r = e.prefix ? `(${e.operator}${k(e.argument, t)})` : `(${k(e.argument, t)}${e.operator})`;
2081
2115
  if (n && (!t || !t.has(n))) return `(() => { const _res = ${r}; if (typeof setScopeValue === 'function' && scope && typeof inScopeChain === 'function' && inScopeChain(scope, ${JSON.stringify(n)})) setScopeValue(scope, ${JSON.stringify(n)}, scope[${JSON.stringify(n)}]); return _res; })()`;
2082
2116
  }
2083
- return e.prefix ? `(${e.operator}${O(e.argument, t)})` : `(${O(e.argument, t)}${e.operator})`;
2084
- case "SequenceExpression": return `(${e.expressions ? e.expressions.map((e) => O(e, t)).join(", ") : ""})`;
2085
- case "ArrayExpression": return `[${e.elements ? e.elements.map((e) => e?.type === "SpreadElement" ? "..." + O(e.argument, t) : O(e, t)).join(", ") : ""}]`;
2117
+ return e.prefix ? `(${e.operator}${k(e.argument, t)})` : `(${k(e.argument, t)}${e.operator})`;
2118
+ case "SequenceExpression": return `(${e.expressions ? e.expressions.map((e) => k(e, t)).join(", ") : ""})`;
2119
+ case "ArrayExpression": return `[${e.elements ? e.elements.map((e) => e?.type === "SpreadElement" ? "..." + k(e.argument, t) : k(e, t)).join(", ") : ""}]`;
2086
2120
  case "ObjectExpression": return `{${e.properties ? e.properties.map((e) => {
2087
- if (e.type === "SpreadElement") return "..." + O(e.argument, t);
2088
- let n = e.computed ? `[${O(e.key, t)}]` : e.key?.name || (typeof e.key?.value == "string" ? JSON.stringify(e.key.value) : String(e.key?.value ?? ""));
2121
+ if (e.type === "SpreadElement") return "..." + k(e.argument, t);
2122
+ let n = e.computed ? `[${k(e.key, t)}]` : e.key?.name || (typeof e.key?.value == "string" ? JSON.stringify(e.key.value) : String(e.key?.value ?? ""));
2089
2123
  if (e.kind === "get" || e.kind === "set") {
2090
2124
  let r = e.value, i = new Set(t), a = [];
2091
2125
  if (r.params) for (let e of r.params) {
2092
2126
  for (let t of w(e)) i.add(t);
2093
2127
  a.push(T(e, i));
2094
2128
  }
2095
- let o = r.body?.type === "BlockStatement" ? `{ ${r.body.body.map((e) => O(e, i)).filter(Boolean).join("; ")}; }` : `{ ${O(r.body, i)}; }`;
2129
+ let o = r.body?.type === "BlockStatement" ? `{ ${r.body.body.map((e) => k(e, i)).filter(Boolean).join("; ")}; }` : `{ ${k(r.body, i)}; }`;
2096
2130
  return `${e.kind} ${n}(${a.join(", ")}) ${o}`;
2097
2131
  }
2098
2132
  if (e.method) {
@@ -2101,52 +2135,52 @@ function O(e, t) {
2101
2135
  for (let t of w(e)) i.add(t);
2102
2136
  a.push(T(e, i));
2103
2137
  }
2104
- let o = r.async ? "async " : "", s = r.generator ? "*" : "", c = r.body?.type === "BlockStatement" ? `{ ${r.body.body.map((e) => O(e, i)).filter(Boolean).join("; ")}; }` : `{ ${O(r.body, i)}; }`;
2138
+ let o = r.async ? "async " : "", s = r.generator ? "*" : "", c = r.body?.type === "BlockStatement" ? `{ ${r.body.body.map((e) => k(e, i)).filter(Boolean).join("; ")}; }` : `{ ${k(r.body, i)}; }`;
2105
2139
  return `${o}${s}${n}(${a.join(", ")}) ${c}`;
2106
2140
  }
2107
- return `${n}: ${O(e.value, t)}`;
2141
+ return `${n}: ${k(e.value, t)}`;
2108
2142
  }).join(", ") : ""}}`;
2109
2143
  case "RestElement":
2110
- case "SpreadElement": return `...${O(e.argument, t)}`;
2111
- case "AssignmentPattern": return `${O(e.left, t)} = ${O(e.right, t)}`;
2112
- case "TemplateLiteral": return `\`${e.quasis ? e.quasis.map((n, r) => (n.value?.raw ?? "") + (e.expressions && e.expressions[r] ? "${" + O(e.expressions[r], t) + "}" : "")).join("") : ""}\``;
2113
- case "TaggedTemplateExpression": return `${O(e.tag, t)}${O(e.quasi, t)}`;
2144
+ case "SpreadElement": return `...${k(e.argument, t)}`;
2145
+ case "AssignmentPattern": return `${k(e.left, t)} = ${k(e.right, t)}`;
2146
+ case "TemplateLiteral": return `\`${e.quasis ? e.quasis.map((n, r) => (n.value?.raw ?? "") + (e.expressions && e.expressions[r] ? "${" + k(e.expressions[r], t) + "}" : "")).join("") : ""}\``;
2147
+ case "TaggedTemplateExpression": return `${k(e.tag, t)}${k(e.quasi, t)}`;
2114
2148
  case "ThisExpression": return "this";
2115
2149
  case "Super": return "super";
2116
2150
  case "BlockStatement": {
2117
2151
  let n = new Set(t);
2118
2152
  if (Array.isArray(e.body)) for (let t of e.body) if (t.type === "VariableDeclaration" && Array.isArray(t.declarations)) for (let e of t.declarations) for (let t of w(e.id)) n.add(t);
2119
2153
  else t.type === "FunctionDeclaration" && t.id?.name && n.add(t.id.name);
2120
- return `{ ${(e.body ? e.body.map((e) => O(e, n)).filter(Boolean) : []).join("; ")}; }`;
2154
+ return `{ ${(e.body ? e.body.map((e) => k(e, n)).filter(Boolean) : []).join("; ")}; }`;
2121
2155
  }
2122
- case "ExpressionStatement": return O(e.expression, t);
2123
- case "ReturnStatement": return `return ${e.argument ? O(e.argument, t) : ""}`;
2124
- case "ThrowStatement": return `throw ${e.argument ? O(e.argument, t) : ""}`;
2156
+ case "ExpressionStatement": return k(e.expression, t);
2157
+ case "ReturnStatement": return `return ${e.argument ? k(e.argument, t) : ""}`;
2158
+ case "ThrowStatement": return `throw ${e.argument ? k(e.argument, t) : ""}`;
2125
2159
  case "BreakStatement": return e.label ? `break ${e.label.name}` : "break";
2126
2160
  case "ContinueStatement": return e.label ? `continue ${e.label.name}` : "continue";
2127
- case "LabeledStatement": return `${e.label.name}: ${O(e.body, t)}`;
2128
- case "TryStatement": return `try ${O(e.block, t)} ${e.handler ? O(e.handler, t) : ""} ${e.finalizer ? `finally ${O(e.finalizer, t)}` : ""}`.trim();
2161
+ case "LabeledStatement": return `${e.label.name}: ${k(e.body, t)}`;
2162
+ case "TryStatement": return `try ${k(e.block, t)} ${e.handler ? k(e.handler, t) : ""} ${e.finalizer ? `finally ${k(e.finalizer, t)}` : ""}`.trim();
2129
2163
  case "CatchClause": {
2130
2164
  let n = new Set(t), r = "";
2131
2165
  if (e.param) {
2132
2166
  for (let t of w(e.param)) n.add(t);
2133
2167
  r = T(e.param, n);
2134
2168
  }
2135
- let i = O(e.body, n);
2169
+ let i = k(e.body, n);
2136
2170
  return r ? `catch (${r}) ${i}` : `catch ${i}`;
2137
2171
  }
2138
- case "SwitchStatement": return `switch (${O(e.discriminant, t)}) { ${e.cases ? e.cases.map((e) => O(e, t)).join(" ") : ""} }`;
2172
+ case "SwitchStatement": return `switch (${k(e.discriminant, t)}) { ${e.cases ? e.cases.map((e) => k(e, t)).join(" ") : ""} }`;
2139
2173
  case "SwitchCase": {
2140
- let n = e.test ? `case ${O(e.test, t)}:` : "default:", r = e.consequent ? e.consequent.map((e) => O(e, t)).filter(Boolean).join("; ") : "";
2174
+ let n = e.test ? `case ${k(e.test, t)}:` : "default:", r = e.consequent ? e.consequent.map((e) => k(e, t)).filter(Boolean).join("; ") : "";
2141
2175
  return `${n} ${r ? r + ";" : ""}`;
2142
2176
  }
2143
- case "IfStatement": return `if (${O(e.test, t)}) ${e.consequent.type === "BlockStatement" ? O(e.consequent, t) : `{ ${O(e.consequent, t)}; }`}${e.alternate ? ` else ${e.alternate.type === "BlockStatement" || e.alternate.type === "IfStatement" ? O(e.alternate, t) : `{ ${O(e.alternate, t)}; }`}` : ""}`;
2177
+ case "IfStatement": return `if (${k(e.test, t)}) ${e.consequent.type === "BlockStatement" ? k(e.consequent, t) : `{ ${k(e.consequent, t)}; }`}${e.alternate ? ` else ${e.alternate.type === "BlockStatement" || e.alternate.type === "IfStatement" ? k(e.alternate, t) : `{ ${k(e.alternate, t)}; }`}` : ""}`;
2144
2178
  case "ForStatement": {
2145
2179
  let n = new Set(t);
2146
2180
  if (e.init?.type === "VariableDeclaration" && e.init.declarations) for (let t of e.init.declarations) for (let e of w(t.id)) n.add(e);
2147
2181
  let r = "";
2148
- e.init?.type === "VariableDeclaration" && e.init.declarations ? r = (e.init.kind || "let") + " " + e.init.declarations.map((e) => `${e.id?.type === "Identifier" ? e.id.name : O(e.id, n)}${e.init ? ` = ${O(e.init, n)}` : ""}`).join(", ") : e.init && (r = O(e.init, n));
2149
- let i = e.test ? O(e.test, n) : "", a = e.update ? O(e.update, n) : "", o = e.body?.type === "BlockStatement" ? O(e.body, n) : `{ ${e.body ? O(e.body, n) : ""}; }`;
2182
+ e.init?.type === "VariableDeclaration" && e.init.declarations ? r = (e.init.kind || "let") + " " + e.init.declarations.map((e) => `${e.id?.type === "Identifier" ? e.id.name : k(e.id, n)}${e.init ? ` = ${k(e.init, n)}` : ""}`).join(", ") : e.init && (r = k(e.init, n));
2183
+ let i = e.test ? k(e.test, n) : "", a = e.update ? k(e.update, n) : "", o = e.body?.type === "BlockStatement" ? k(e.body, n) : `{ ${e.body ? k(e.body, n) : ""}; }`;
2150
2184
  return `for (${r}; ${i}; ${a}) ${o}`;
2151
2185
  }
2152
2186
  case "ForOfStatement": {
@@ -2155,10 +2189,10 @@ function O(e, t) {
2155
2189
  let t = e.left.kind || "let", i = e.left.declarations?.[0];
2156
2190
  if (i) {
2157
2191
  for (let e of w(i.id)) n.add(e);
2158
- r = `${t} ${i.id?.type === "Identifier" ? i.id.name : O(i.id, n)}`;
2192
+ r = `${t} ${i.id?.type === "Identifier" ? i.id.name : k(i.id, n)}`;
2159
2193
  }
2160
- } else e.left?.type === "Identifier" ? (n.add(e.left.name), r = e.left.name) : e.left && (r = O(e.left, n));
2161
- let i = `(typeof resolveIterable === 'function' ? resolveIterable : (x) => x || [])(${O(e.right, t)})`, a = e.body?.type === "BlockStatement" ? O(e.body, n) : `{ ${e.body ? O(e.body, n) : ""}; }`;
2194
+ } else e.left?.type === "Identifier" ? (n.add(e.left.name), r = e.left.name) : e.left && (r = k(e.left, n));
2195
+ let i = `(typeof resolveIterable === 'function' ? resolveIterable : (x) => x || [])(${k(e.right, t)})`, a = e.body?.type === "BlockStatement" ? k(e.body, n) : `{ ${e.body ? k(e.body, n) : ""}; }`;
2162
2196
  return `for ${e.await ? "await " : ""}(${r} of ${i}) ${a}`;
2163
2197
  }
2164
2198
  case "ForInStatement": {
@@ -2167,40 +2201,40 @@ function O(e, t) {
2167
2201
  let t = e.left.kind || "let", i = e.left.declarations?.[0];
2168
2202
  if (i) {
2169
2203
  for (let e of w(i.id)) n.add(e);
2170
- r = `${t} ${i.id?.type === "Identifier" ? i.id.name : O(i.id, n)}`;
2204
+ r = `${t} ${i.id?.type === "Identifier" ? i.id.name : k(i.id, n)}`;
2171
2205
  }
2172
- } else e.left?.type === "Identifier" ? (n.add(e.left.name), r = e.left.name) : e.left && (r = O(e.left, n));
2173
- let i = O(e.right, t), a = e.body?.type === "BlockStatement" ? O(e.body, n) : `{ ${e.body ? O(e.body, n) : ""}; }`;
2206
+ } else e.left?.type === "Identifier" ? (n.add(e.left.name), r = e.left.name) : e.left && (r = k(e.left, n));
2207
+ let i = k(e.right, t), a = e.body?.type === "BlockStatement" ? k(e.body, n) : `{ ${e.body ? k(e.body, n) : ""}; }`;
2174
2208
  return `for (${r} in ${i}) ${a}`;
2175
2209
  }
2176
- case "WhileStatement": return `while (${O(e.test, t)}) ${e.body?.type === "BlockStatement" ? O(e.body, t) : `{ ${e.body ? O(e.body, t) : ""}; }`}`;
2210
+ case "WhileStatement": return `while (${k(e.test, t)}) ${e.body?.type === "BlockStatement" ? k(e.body, t) : `{ ${e.body ? k(e.body, t) : ""}; }`}`;
2177
2211
  case "DoWhileStatement": {
2178
- let n = O(e.test, t);
2179
- return `do ${e.body?.type === "BlockStatement" ? O(e.body, t) : `{ ${e.body ? O(e.body, t) : ""}; }`} while (${n})`;
2212
+ let n = k(e.test, t);
2213
+ return `do ${e.body?.type === "BlockStatement" ? k(e.body, t) : `{ ${e.body ? k(e.body, t) : ""}; }`} while (${n})`;
2180
2214
  }
2181
- case "ArrayPattern": return `[ ${e.elements ? e.elements.map((e) => e ? e.type === "RestElement" ? "..." + O(e.argument, t) : e.type === "AssignmentPattern" ? `${O(e.left, t)} = ${O(e.right, t)}` : e.name || O(e, t) : "").join(", ") : ""} ]`;
2215
+ case "ArrayPattern": return `[ ${e.elements ? e.elements.map((e) => e ? e.type === "RestElement" ? "..." + k(e.argument, t) : e.type === "AssignmentPattern" ? `${k(e.left, t)} = ${k(e.right, t)}` : e.name || k(e, t) : "").join(", ") : ""} ]`;
2182
2216
  case "ObjectPattern": return `{ ${e.properties ? e.properties.map((e) => {
2183
2217
  if (e.type === "Property") {
2184
- let n = e.key?.name || O(e.key, t), r = e.value?.name || O(e.value, t);
2218
+ let n = e.key?.name || k(e.key, t), r = e.value?.name || k(e.value, t);
2185
2219
  return n === r ? n : `${n}: ${r}`;
2186
2220
  }
2187
- return e.type === "RestElement" ? `...${O(e.argument, t)}` : "";
2221
+ return e.type === "RestElement" ? `...${k(e.argument, t)}` : "";
2188
2222
  }).filter(Boolean).join(", ") : ""} }`;
2189
2223
  case "VariableDeclaration": {
2190
2224
  if (t) {
2191
2225
  let n = [];
2192
2226
  if (e.declarations) for (let r of e.declarations) {
2193
- let e = r.id?.type === "Identifier" ? r.id.name : O(r.id, t), i = r.init ? O(r.init, t) : void 0;
2227
+ let e = r.id?.type === "Identifier" ? r.id.name : k(r.id, t), i = r.init ? k(r.init, t) : void 0;
2194
2228
  i === void 0 ? n.push(`${e}`) : n.push(`${e} = ${i}`);
2195
2229
  }
2196
2230
  return `${e.kind || "let"} ${n.join(", ")}`;
2197
2231
  }
2198
2232
  let n = [];
2199
2233
  if (e.declarations) for (let r of e.declarations) if (r.id?.type === "ObjectPattern" || r.id?.type === "ArrayPattern") {
2200
- let e = r.init ? O(r.init, t) : "undefined", i = D(r.id, "_init", t);
2234
+ let e = r.init ? k(r.init, t) : "undefined", i = D(r.id, "_init", t);
2201
2235
  n.push(`((_init) => { ${i.join("; ")}; return _init; })(${e})`);
2202
2236
  } else {
2203
- let e = r.id?.name || O(r.id, t), i = r.init ? O(r.init, t) : "undefined";
2237
+ let e = r.id?.name || k(r.id, t), i = r.init ? k(r.init, t) : "undefined";
2204
2238
  n.push(`((scope || {})[${JSON.stringify(e)}] = ${i})`);
2205
2239
  }
2206
2240
  return `(${n.filter(Boolean).join(", ") || "undefined"})`;
@@ -2215,7 +2249,7 @@ function O(e, t) {
2215
2249
  }
2216
2250
  if (e.body?.type === "BlockStatement" && Array.isArray(e.body.body)) for (let t of e.body.body) if (t.type === "VariableDeclaration" && Array.isArray(t.declarations)) for (let e of t.declarations) for (let t of w(e.id)) r.add(t);
2217
2251
  else t.type === "FunctionDeclaration" && t.id?.name && r.add(t.id.name);
2218
- let a = i.join(", "), o = e.body?.type === "BlockStatement" ? `{ ${e.body.body.map((e) => O(e, r)).filter(Boolean).join("; ")}; }` : `{ ${O(e.body, r)}; }`, s = `${e.async ? "async " : ""}function${e.generator ? "*" : ""} ${n || ""}(${a}) ${o}`;
2252
+ let a = i.join(", "), o = e.body?.type === "BlockStatement" ? `{ ${e.body.body.map((e) => k(e, r)).filter(Boolean).join("; ")}; }` : `{ ${k(e.body, r)}; }`, s = `${e.async ? "async " : ""}function${e.generator ? "*" : ""} ${n || ""}(${a}) ${o}`;
2219
2253
  return n ? `((scope || {})[${JSON.stringify(n)}] = ${s})` : s;
2220
2254
  }
2221
2255
  case "ArrowFunctionExpression":
@@ -2230,9 +2264,9 @@ function O(e, t) {
2230
2264
  if (e.body?.type === "BlockStatement" && Array.isArray(e.body.body)) for (let t of e.body.body) if (t.type === "VariableDeclaration" && Array.isArray(t.declarations)) for (let e of t.declarations) for (let t of w(e.id)) n.add(t);
2231
2265
  else t.type === "FunctionDeclaration" && t.id?.name && n.add(t.id.name);
2232
2266
  let i = r.join(", "), a = e.async ? "async " : "";
2233
- if (e.type === "ArrowFunctionExpression") return e.body?.type === "BlockStatement" ? `(${a}(${i}) => ${`{ ${e.body.body.map((e) => O(e, n)).filter(Boolean).join("; ")}; }`})` : `(${a}(${i}) => ${O(e.body, n)})`;
2267
+ if (e.type === "ArrowFunctionExpression") return e.body?.type === "BlockStatement" ? `(${a}(${i}) => ${`{ ${e.body.body.map((e) => k(e, n)).filter(Boolean).join("; ")}; }`})` : `(${a}(${i}) => ${k(e.body, n)})`;
2234
2268
  {
2235
- let t = e.generator ? "*" : "", r = e.body?.type === "BlockStatement" ? `{ ${e.body.body.map((e) => O(e, n)).filter(Boolean).join("; ")}; }` : `{ ${O(e.body, n)}; }`;
2269
+ let t = e.generator ? "*" : "", r = e.body?.type === "BlockStatement" ? `{ ${e.body.body.map((e) => k(e, n)).filter(Boolean).join("; ")}; }` : `{ ${k(e.body, n)}; }`;
2236
2270
  return `(${a}function${t} ${e.id?.name || ""}(${i}) ${r})`;
2237
2271
  }
2238
2272
  }
@@ -2240,37 +2274,37 @@ function O(e, t) {
2240
2274
  case "ClassExpression": {
2241
2275
  let n = e.id?.name, r = new Set(t);
2242
2276
  n && r.add(n);
2243
- let i = e.superClass ? ` extends ${O(e.superClass, t)}` : "", a = O(e.body, r), o = `class ${n || ""}${i} ${a}`;
2277
+ let i = e.superClass ? ` extends ${k(e.superClass, t)}` : "", a = k(e.body, r), o = `class ${n || ""}${i} ${a}`;
2244
2278
  return e.type === "ClassDeclaration" && n ? `((scope || {})[${JSON.stringify(n)}] = ${o})` : `(${o})`;
2245
2279
  }
2246
- case "ClassBody": return `{ ${(e.body ? e.body.map((e) => O(e, t)).filter(Boolean) : []).join("; ")} }`;
2280
+ case "ClassBody": return `{ ${(e.body ? e.body.map((e) => k(e, t)).filter(Boolean) : []).join("; ")} }`;
2247
2281
  case "MethodDefinition": {
2248
- let n = e.static ? "static " : "", r = e.kind === "get" || e.kind === "set" ? `${e.kind} ` : "", i = e.value?.async ? "async " : "", a = e.value?.generator ? "*" : "", o = e.computed ? `[${O(e.key, t)}]` : e.key?.name || O(e.key, t), s = new Set(t), c = [];
2282
+ let n = e.static ? "static " : "", r = e.kind === "get" || e.kind === "set" ? `${e.kind} ` : "", i = e.value?.async ? "async " : "", a = e.value?.generator ? "*" : "", o = e.computed ? `[${k(e.key, t)}]` : e.key?.name || k(e.key, t), s = new Set(t), c = [];
2249
2283
  if (e.value?.params) for (let t of e.value.params) {
2250
2284
  for (let e of w(t)) s.add(e);
2251
2285
  c.push(T(t, s));
2252
2286
  }
2253
2287
  if (e.value?.body?.type === "BlockStatement" && Array.isArray(e.value.body.body)) for (let t of e.value.body.body) if (t.type === "VariableDeclaration" && Array.isArray(t.declarations)) for (let e of t.declarations) for (let t of w(e.id)) s.add(t);
2254
2288
  else t.type === "FunctionDeclaration" && t.id?.name && s.add(t.id.name);
2255
- return `${n}${i}${a}${r}${o}(${c.join(", ")}) ${e.value?.body ? O(e.value.body, s) : "{}"}`;
2289
+ return `${n}${i}${a}${r}${o}(${c.join(", ")}) ${e.value?.body ? k(e.value.body, s) : "{}"}`;
2256
2290
  }
2257
- case "PropertyDefinition": return `${e.static ? "static " : ""}${e.computed ? `[${O(e.key, t)}]` : e.key?.name || O(e.key, t)}${e.value ? ` = ${O(e.value, t)}` : ""}`;
2258
- case "NewExpression": return `new (${O(e.callee, t)})(${e.arguments ? e.arguments.map((e) => O(e, t)).join(", ") : ""})`;
2291
+ case "PropertyDefinition": return `${e.static ? "static " : ""}${e.computed ? `[${k(e.key, t)}]` : e.key?.name || k(e.key, t)}${e.value ? ` = ${k(e.value, t)}` : ""}`;
2292
+ case "NewExpression": return `new (${k(e.callee, t)})(${e.arguments ? e.arguments.map((e) => k(e, t)).join(", ") : ""})`;
2259
2293
  case "EmptyStatement":
2260
2294
  case "ImportDeclaration":
2261
2295
  case "ImportSpecifier":
2262
2296
  case "ImportDefaultSpecifier":
2263
2297
  case "ImportNamespaceSpecifier": return "";
2264
2298
  case "ParenthesizedExpression":
2265
- case "ChainExpression": return O(e.expression, t);
2299
+ case "ChainExpression": return k(e.expression, t);
2266
2300
  default: return "";
2267
2301
  }
2268
2302
  }
2269
2303
  //#endregion
2270
2304
  //#region src/index.ts
2271
- function k(e, t = !1) {
2272
- let n = new x(new y(new h(e)).parse()).transform(), r = new S(n).generate();
2305
+ function A(e, t = !1) {
2306
+ let n = new x(new y(new m(e)).parse()).transform(), r = new S(n).generate();
2273
2307
  return t && (console.log("--- Transformed AST ---"), console.log(JSON.stringify(n, null, 2)), console.log("--- Compiled Module ---"), console.log(JSON.stringify(r, null, 2))), r;
2274
2308
  }
2275
2309
  //#endregion
2276
- export { s as ASTNodeType, S as DriftGenerator, h as DriftLexer, c as DriftLexerError, y as DriftParser, l as DriftParserError, x as DriftTransformer, o as ExprTokenKind, a as LexerStateKind, u as Opcode, i as TokenType, O as astToJS, k as compile, w as extractBindingNames, b as traverseTemplateAST };
2310
+ export { o as ASTNodeType, S as DriftGenerator, m as DriftLexer, s as DriftLexerError, y as DriftParser, c as DriftParserError, x as DriftTransformer, a as ExprTokenKind, i as LexerStateKind, l as Opcode, r as TokenType, k as astToJS, A as compile, w as extractBindingNames, b as traverseTemplateAST };