driftjs-compiler 0.0.13 → 0.0.14

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