@vobs/compiler 1.2.1 → 1.3.0

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/compile.cjs CHANGED
@@ -1,14 +1,44 @@
1
- 'use strict';
2
-
3
- var ts = require('typescript');
4
- var error = require('@vobs/runtime/error');
5
-
6
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
-
8
- var ts__default = /*#__PURE__*/_interopDefault(ts);
9
-
1
+ var __VOBS_CJS_FILE_URL = require("url").pathToFileURL(__filename).href;
2
+ "use strict";
3
+ var __create = Object.create;
10
4
  var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
9
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
10
+ var __export = (target, all) => {
11
+ for (var name in all)
12
+ __defProp(target, name, { get: all[name], enumerable: true });
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
30
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
31
+
32
+ // packages/compiler/src/compile.ts
33
+ var compile_exports = {};
34
+ __export(compile_exports, {
35
+ compile: () => compile,
36
+ compileWithSourceMap: () => compileWithSourceMap,
37
+ createCompiler: () => createCompiler
38
+ });
39
+ module.exports = __toCommonJS(compile_exports);
40
+ var import_typescript = __toESM(require("typescript"), 1);
41
+ var import_error = require("@vobs/runtime/error");
12
42
  function createCompiler(options = {}) {
13
43
  const basePlugins = options.plugins ?? [];
14
44
  return {
@@ -31,7 +61,7 @@ function compile(code, options = {}) {
31
61
  const result = compileWithSourceMap(code, options);
32
62
  const firstError = result.diagnostics.find((diagnostic) => diagnostic.severity === "error");
33
63
  if (firstError) {
34
- throw new error.VobsError({
64
+ throw new import_error.VobsError({
35
65
  code: firstError.code,
36
66
  layer: "compiler",
37
67
  message: firstError.message,
@@ -45,12 +75,12 @@ function compile(code, options = {}) {
45
75
  __name(compile, "compile");
46
76
  function compileWithSourceMap(code, options = {}) {
47
77
  const filename = options.filename ?? "component.tsx";
48
- let sourceFile = ts__default.default.createSourceFile(
78
+ let sourceFile = import_typescript.default.createSourceFile(
49
79
  filename,
50
80
  code,
51
- ts__default.default.ScriptTarget.Latest,
81
+ import_typescript.default.ScriptTarget.Latest,
52
82
  true,
53
- ts__default.default.ScriptKind.TSX
83
+ import_typescript.default.ScriptKind.TSX
54
84
  );
55
85
  const state = {
56
86
  generatedId: 0,
@@ -63,21 +93,22 @@ function compileWithSourceMap(code, options = {}) {
63
93
  sourceLocation: options.sourceLocation ?? true,
64
94
  stateAliases: collectStateAliases(sourceFile),
65
95
  localBindings: collectLocallyDeclaredNames(sourceFile),
66
- diagnostics: []
96
+ diagnostics: [],
97
+ hmrModuleId: options.hmrModuleId ?? null
67
98
  };
68
99
  const cleanFilename = filename.split(/[?#]/u, 1)[0] || filename;
69
- const diagnostics = ts__default.default.transpileModule(code, {
100
+ const diagnostics = import_typescript.default.transpileModule(code, {
70
101
  // Vite appends query strings (for example `?direct`) to module IDs;
71
102
  // strip them so TypeScript still recognizes TSX syntax for diagnostics.
72
103
  fileName: cleanFilename,
73
104
  reportDiagnostics: true,
74
- compilerOptions: { jsx: ts__default.default.JsxEmit.Preserve, target: ts__default.default.ScriptTarget.Latest }
105
+ compilerOptions: { jsx: import_typescript.default.JsxEmit.Preserve, target: import_typescript.default.ScriptTarget.Latest }
75
106
  }).diagnostics?.map((diagnostic) => toCompilerDiagnostic(diagnostic, sourceFile, cleanFilename)) ?? [];
76
107
  const plugins = options.plugins ?? [];
77
108
  validatePlugins(plugins);
78
109
  const context = {
79
110
  filename,
80
- factory: ts__default.default.factory,
111
+ factory: import_typescript.default.factory,
81
112
  addRuntimeImport(name) {
82
113
  resolveHelperName(state, name);
83
114
  },
@@ -89,15 +120,16 @@ function compileWithSourceMap(code, options = {}) {
89
120
  }
90
121
  for (const plugin of plugins) sourceFile = transformPluginNodes(sourceFile, plugin, context);
91
122
  const statements = sourceFile.statements.map(
92
- (statement) => ts__default.default.isImportDeclaration(statement) ? rebuildImport(state, statement) : transformStatement(state, statement)
123
+ (statement) => import_typescript.default.isImportDeclaration(statement) ? rebuildImport(state, statement) : transformStatement(state, statement, true)
93
124
  );
94
125
  const templateDeclarations = createTemplateDeclarations(state);
95
- const resultFile = ts__default.default.factory.updateSourceFile(sourceFile, [
126
+ let resultFile = import_typescript.default.factory.updateSourceFile(sourceFile, [
96
127
  ...createRuntimeImports(state),
97
128
  ...templateDeclarations,
98
129
  ...statements
99
130
  ]);
100
- const generated = ts__default.default.createPrinter().printFile(resultFile);
131
+ resultFile = transformResidualJsx(state, resultFile);
132
+ const generated = import_typescript.default.createPrinter().printFile(resultFile);
101
133
  return {
102
134
  code: generated,
103
135
  map: buildSourceMap(state, filename, code, generated, resultFile),
@@ -108,11 +140,11 @@ __name(compileWithSourceMap, "compileWithSourceMap");
108
140
  function toCompilerDiagnostic(diagnostic, sourceFile, filename) {
109
141
  const start = diagnostic.start ?? 0;
110
142
  const length = diagnostic.length ?? 1;
111
- const message = ts__default.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
143
+ const message = import_typescript.default.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
112
144
  const { line, column, codeFrame } = buildCodeFrame(sourceFile, start, length);
113
145
  return {
114
146
  code: `VOBS_C${String(diagnostic.code).padStart(3, "0")}`,
115
- severity: diagnostic.category === ts__default.default.DiagnosticCategory.Warning ? "warning" : "error",
147
+ severity: diagnostic.category === import_typescript.default.DiagnosticCategory.Warning ? "warning" : "error",
116
148
  message,
117
149
  location: { file: filename, line, column },
118
150
  codeFrame
@@ -135,7 +167,7 @@ function reportUnsupportedTag(state, tagName) {
135
167
  const sourceFile = tagName.getSourceFile() ?? state.sourceFile;
136
168
  if (!sourceFile) return;
137
169
  const label = tagName.getText();
138
- const kindNote = tagName.kind === ts__default.default.SyntaxKind.JsxNamespacedName ? "\uFF08JSX \u547D\u540D\u7A7A\u95F4\u6807\u7B7E\uFF09" : "";
170
+ const kindNote = tagName.kind === import_typescript.default.SyntaxKind.JsxNamespacedName ? "\uFF08JSX \u547D\u540D\u7A7A\u95F4\u6807\u7B7E\uFF09" : "";
139
171
  const { line, column, codeFrame } = buildCodeFrame(sourceFile, tagName.getStart(sourceFile), tagName.getWidth(sourceFile));
140
172
  state.diagnostics.push({
141
173
  code: "VOBS_C101",
@@ -148,7 +180,7 @@ function reportUnsupportedTag(state, tagName) {
148
180
  }
149
181
  __name(reportUnsupportedTag, "reportUnsupportedTag");
150
182
  function buildSourceMap(state, filename, source, generated, resultFile) {
151
- const reparsed = ts__default.default.createSourceFile(filename, generated, ts__default.default.ScriptTarget.Latest, true, ts__default.default.ScriptKind.TSX);
183
+ const reparsed = import_typescript.default.createSourceFile(filename, generated, import_typescript.default.ScriptTarget.Latest, true, import_typescript.default.ScriptKind.TSX);
152
184
  const segments = [];
153
185
  walkPairedTrees(state, resultFile, reparsed, reparsed, segments);
154
186
  segments.sort((a, b) => a.genLine - b.genLine || a.genCol - b.genCol);
@@ -163,8 +195,8 @@ function buildSourceMap(state, filename, source, generated, resultFile) {
163
195
  }
164
196
  __name(buildSourceMap, "buildSourceMap");
165
197
  function statementLists(node) {
166
- if (ts__default.default.isSourceFile(node) || ts__default.default.isBlock(node) || ts__default.default.isModuleBlock(node)) return node.statements;
167
- if (ts__default.default.isCaseClause(node) || ts__default.default.isDefaultClause(node)) return node.statements;
198
+ if (import_typescript.default.isSourceFile(node) || import_typescript.default.isBlock(node) || import_typescript.default.isModuleBlock(node)) return node.statements;
199
+ if (import_typescript.default.isCaseClause(node) || import_typescript.default.isDefaultClause(node)) return node.statements;
168
200
  return null;
169
201
  }
170
202
  __name(statementLists, "statementLists");
@@ -183,10 +215,10 @@ function walkPairedTrees(state, original, generated, reparsed, segments) {
183
215
  }
184
216
  const originalChildren = [];
185
217
  const generatedChildren = [];
186
- ts__default.default.forEachChild(original, (node) => {
218
+ import_typescript.default.forEachChild(original, (node) => {
187
219
  originalChildren.push(node);
188
220
  });
189
- ts__default.default.forEachChild(generated, (node) => {
221
+ import_typescript.default.forEachChild(generated, (node) => {
190
222
  generatedChildren.push(node);
191
223
  });
192
224
  if (originalChildren.length !== generatedChildren.length) return;
@@ -256,8 +288,8 @@ __name(encodeVlq, "encodeVlq");
256
288
  function validatePlugins(plugins) {
257
289
  const names = /* @__PURE__ */ new Set();
258
290
  for (const plugin of plugins) {
259
- if (!plugin.name) throw new error.VobsError({ code: "VOBS_C007", layer: "compiler", message: "\u7F16\u8BD1\u5668\u63D2\u4EF6\u5FC5\u987B\u63D0\u4F9B name", fix: "\u4E3A\u63D2\u4EF6\u6DFB\u52A0\u7A33\u5B9A\u4E14\u552F\u4E00\u7684 name\u3002" });
260
- if (names.has(plugin.name)) throw new error.VobsError({ code: "VOBS_C007", layer: "compiler", message: `\u68C0\u6D4B\u5230\u91CD\u590D\u63D2\u4EF6: ${plugin.name}`, fix: "\u4E3A\u6BCF\u4E2A\u7F16\u8BD1\u5668\u63D2\u4EF6\u4F7F\u7528\u552F\u4E00\u7684 name\u3002" });
291
+ if (!plugin.name) throw new import_error.VobsError({ code: "VOBS_C007", layer: "compiler", message: "\u7F16\u8BD1\u5668\u63D2\u4EF6\u5FC5\u987B\u63D0\u4F9B name", fix: "\u4E3A\u63D2\u4EF6\u6DFB\u52A0\u7A33\u5B9A\u4E14\u552F\u4E00\u7684 name\u3002" });
292
+ if (names.has(plugin.name)) throw new import_error.VobsError({ code: "VOBS_C007", layer: "compiler", message: `\u68C0\u6D4B\u5230\u91CD\u590D\u63D2\u4EF6: ${plugin.name}`, fix: "\u4E3A\u6BCF\u4E2A\u7F16\u8BD1\u5668\u63D2\u4EF6\u4F7F\u7528\u552F\u4E00\u7684 name\u3002" });
261
293
  names.add(plugin.name);
262
294
  }
263
295
  }
@@ -269,11 +301,11 @@ function transformPluginNodes(sourceFile, plugin, context) {
269
301
  const visit = /* @__PURE__ */ __name((node) => {
270
302
  const replacement = transformNode(node, context);
271
303
  if (replacement === null) return void 0;
272
- return ts__default.default.visitEachChild(replacement ?? node, visit, transformContext);
304
+ return import_typescript.default.visitEachChild(replacement ?? node, visit, transformContext);
273
305
  }, "visit");
274
- return ts__default.default.visitNode(root, visit);
306
+ return import_typescript.default.visitNode(root, visit);
275
307
  }, "transformer");
276
- const result = ts__default.default.transform(sourceFile, [transformer]);
308
+ const result = import_typescript.default.transform(sourceFile, [transformer]);
277
309
  try {
278
310
  return result.transformed[0];
279
311
  } finally {
@@ -284,8 +316,8 @@ __name(transformPluginNodes, "transformPluginNodes");
284
316
  function collectDeclaredNames(sourceFile) {
285
317
  const names = /* @__PURE__ */ new Set();
286
318
  const visit = /* @__PURE__ */ __name((node) => {
287
- if (ts__default.default.isIdentifier(node) && isBindingName(node)) names.add(node.text);
288
- ts__default.default.forEachChild(node, visit);
319
+ if (import_typescript.default.isIdentifier(node) && isBindingName(node)) names.add(node.text);
320
+ import_typescript.default.forEachChild(node, visit);
289
321
  }, "visit");
290
322
  visit(sourceFile);
291
323
  return names;
@@ -294,11 +326,11 @@ __name(collectDeclaredNames, "collectDeclaredNames");
294
326
  function collectStateAliases(sourceFile) {
295
327
  const aliases = /* @__PURE__ */ new Set();
296
328
  for (const statement of sourceFile.statements) {
297
- if (!ts__default.default.isImportDeclaration(statement) || !ts__default.default.isStringLiteral(statement.moduleSpecifier)) continue;
298
- const module = statement.moduleSpecifier.text;
299
- if (module !== "@vobs/reactivity" && module !== "@vobs/vobs") continue;
329
+ if (!import_typescript.default.isImportDeclaration(statement) || !import_typescript.default.isStringLiteral(statement.moduleSpecifier)) continue;
330
+ const module2 = statement.moduleSpecifier.text;
331
+ if (module2 !== "@vobs/reactivity" && module2 !== "@vobs/vobs") continue;
300
332
  const clause = statement.importClause;
301
- if (!clause?.namedBindings || !ts__default.default.isNamedImports(clause.namedBindings)) continue;
333
+ if (!clause?.namedBindings || !import_typescript.default.isNamedImports(clause.namedBindings)) continue;
302
334
  for (const element of clause.namedBindings.elements) {
303
335
  if (element.propertyName ? element.propertyName.text === "state" : element.name.text === "state") {
304
336
  aliases.add(element.name.text);
@@ -311,9 +343,9 @@ __name(collectStateAliases, "collectStateAliases");
311
343
  function collectLocallyDeclaredNames(sourceFile) {
312
344
  const names = /* @__PURE__ */ new Set();
313
345
  const visit = /* @__PURE__ */ __name((node) => {
314
- if (ts__default.default.isImportDeclaration(node)) return;
315
- if (ts__default.default.isIdentifier(node) && isBindingName(node)) names.add(node.text);
316
- ts__default.default.forEachChild(node, visit);
346
+ if (import_typescript.default.isImportDeclaration(node)) return;
347
+ if (import_typescript.default.isIdentifier(node) && isBindingName(node)) names.add(node.text);
348
+ import_typescript.default.forEachChild(node, visit);
317
349
  }, "visit");
318
350
  visit(sourceFile);
319
351
  return names;
@@ -322,9 +354,9 @@ __name(collectLocallyDeclaredNames, "collectLocallyDeclaredNames");
322
354
  function isBindingName(node) {
323
355
  const parent = node.parent;
324
356
  if (!parent) return false;
325
- if (ts__default.default.isPropertyAccessExpression(parent) && parent.name === node) return false;
326
- if (ts__default.default.isQualifiedName(parent) && parent.right === node) return false;
327
- if (ts__default.default.isJsxAttribute(parent)) return false;
357
+ if (import_typescript.default.isPropertyAccessExpression(parent) && parent.name === node) return false;
358
+ if (import_typescript.default.isQualifiedName(parent) && parent.right === node) return false;
359
+ if (import_typescript.default.isJsxAttribute(parent)) return false;
328
360
  return parent.name === node;
329
361
  }
330
362
  __name(isBindingName, "isBindingName");
@@ -342,45 +374,45 @@ function resolveHelperName(state, name) {
342
374
  }
343
375
  __name(resolveHelperName, "resolveHelperName");
344
376
  function helperRef(state, name) {
345
- return ts__default.default.factory.createIdentifier(resolveHelperName(state, name));
377
+ return import_typescript.default.factory.createIdentifier(resolveHelperName(state, name));
346
378
  }
347
379
  __name(helperRef, "helperRef");
348
380
  function createRuntimeImports(state) {
349
381
  const modules = /* @__PURE__ */ new Map();
350
382
  for (const [name, alias] of state.helperAliases) {
351
- const module = name === "insertResourceBoundary" ? "@vobs/resource" : "@vobs/vobs";
352
- const imported = modules.get(module) ?? [];
353
- imported.push(ts__default.default.factory.createImportSpecifier(
383
+ const module2 = name === "insertResourceBoundary" ? "@vobs/resource" : "@vobs/vobs";
384
+ const imported = modules.get(module2) ?? [];
385
+ imported.push(import_typescript.default.factory.createImportSpecifier(
354
386
  false,
355
- alias === name ? void 0 : ts__default.default.factory.createIdentifier(name),
356
- ts__default.default.factory.createIdentifier(alias)
387
+ alias === name ? void 0 : import_typescript.default.factory.createIdentifier(name),
388
+ import_typescript.default.factory.createIdentifier(alias)
357
389
  ));
358
- modules.set(module, imported);
390
+ modules.set(module2, imported);
359
391
  }
360
- return [...modules.entries()].map(([module, imported]) => ts__default.default.factory.createImportDeclaration(
392
+ return [...modules.entries()].map(([module2, imported]) => import_typescript.default.factory.createImportDeclaration(
361
393
  void 0,
362
- ts__default.default.factory.createImportClause(
394
+ import_typescript.default.factory.createImportClause(
363
395
  false,
364
396
  void 0,
365
- ts__default.default.factory.createNamedImports(imported)
397
+ import_typescript.default.factory.createNamedImports(imported)
366
398
  ),
367
- ts__default.default.factory.createStringLiteral(module)
399
+ import_typescript.default.factory.createStringLiteral(module2)
368
400
  ));
369
401
  }
370
402
  __name(createRuntimeImports, "createRuntimeImports");
371
403
  function rebuildImport(state, node) {
372
- if (!ts__default.default.isStringLiteral(node.moduleSpecifier)) return node;
373
- return tagStatement(state, ts__default.default.factory.createImportDeclaration(
404
+ if (!import_typescript.default.isStringLiteral(node.moduleSpecifier)) return node;
405
+ return tagStatement(state, import_typescript.default.factory.createImportDeclaration(
374
406
  node.modifiers,
375
407
  node.importClause,
376
- ts__default.default.factory.createStringLiteral(node.moduleSpecifier.text),
408
+ import_typescript.default.factory.createStringLiteral(node.moduleSpecifier.text),
377
409
  node.attributes
378
410
  ), node);
379
411
  }
380
412
  __name(rebuildImport, "rebuildImport");
381
- function transformStatement(state, node) {
382
- if (ts__default.default.isFunctionDeclaration(node) && node.body) {
383
- return tagStatement(state, ts__default.default.factory.updateFunctionDeclaration(
413
+ function transformStatement(state, node, moduleScope = false) {
414
+ if (import_typescript.default.isFunctionDeclaration(node) && node.body) {
415
+ return tagStatement(state, import_typescript.default.factory.updateFunctionDeclaration(
384
416
  node,
385
417
  node.modifiers,
386
418
  node.asteriskToken,
@@ -391,20 +423,20 @@ function transformStatement(state, node) {
391
423
  transformBlock(state, node.body)
392
424
  ), node);
393
425
  }
394
- if (ts__default.default.isVariableStatement(node)) return transformVariableStatement(state, node);
395
- if (ts__default.default.isExportAssignment(node) && containsJsx(node.expression)) {
396
- return tagStatement(state, ts__default.default.factory.updateExportAssignment(node, node.modifiers, transformEmbeddedExpression(state, node.expression)), node);
426
+ if (import_typescript.default.isVariableStatement(node)) return transformVariableStatement(state, node, moduleScope);
427
+ if (import_typescript.default.isExportAssignment(node) && containsJsx(node.expression)) {
428
+ return tagStatement(state, import_typescript.default.factory.updateExportAssignment(node, node.modifiers, transformEmbeddedExpression(state, node.expression)), node);
397
429
  }
398
- if (ts__default.default.isExpressionStatement(node) && containsJsx(node.expression)) {
399
- return tagStatement(state, ts__default.default.factory.updateExpressionStatement(node, transformEmbeddedExpression(state, node.expression)), node);
430
+ if (import_typescript.default.isExpressionStatement(node) && containsJsx(node.expression)) {
431
+ return tagStatement(state, import_typescript.default.factory.updateExpressionStatement(node, transformEmbeddedExpression(state, node.expression)), node);
400
432
  }
401
- if (ts__default.default.isReturnStatement(node) && node.expression && containsJsx(node.expression)) {
402
- return tagStatement(state, ts__default.default.factory.updateReturnStatement(node, transformEmbeddedExpression(state, node.expression)), node);
433
+ if (import_typescript.default.isReturnStatement(node) && node.expression && containsJsx(node.expression)) {
434
+ return tagStatement(state, import_typescript.default.factory.updateReturnStatement(node, transformEmbeddedExpression(state, node.expression)), node);
403
435
  }
404
436
  return node;
405
437
  }
406
438
  __name(transformStatement, "transformStatement");
407
- function transformVariableStatement(state, node) {
439
+ function transformVariableStatement(state, node, moduleScope = false) {
408
440
  let changed = false;
409
441
  const declarations = node.declarationList.declarations.map((declaration) => {
410
442
  const initializer = declaration.initializer;
@@ -412,10 +444,12 @@ function transformVariableStatement(state, node) {
412
444
  let nextInitializer = inferStateDebugName(state, declaration, initializer) ?? initializer;
413
445
  if (containsJsx(nextInitializer)) {
414
446
  nextInitializer = transformEmbeddedExpression(state, nextInitializer);
447
+ } else if (moduleScope && state.hmrModuleId !== null) {
448
+ nextInitializer = wrapStateWithHmrRef(state, declaration, nextInitializer) ?? nextInitializer;
415
449
  }
416
450
  if (nextInitializer === initializer) return declaration;
417
451
  changed = true;
418
- return ts__default.default.factory.updateVariableDeclaration(
452
+ return import_typescript.default.factory.updateVariableDeclaration(
419
453
  declaration,
420
454
  declaration.name,
421
455
  declaration.exclamationToken,
@@ -424,31 +458,54 @@ function transformVariableStatement(state, node) {
424
458
  );
425
459
  });
426
460
  if (!changed) return node;
427
- return tagStatement(state, ts__default.default.factory.updateVariableStatement(
461
+ return tagStatement(state, import_typescript.default.factory.updateVariableStatement(
428
462
  node,
429
463
  node.modifiers,
430
- ts__default.default.factory.updateVariableDeclarationList(node.declarationList, declarations)
464
+ import_typescript.default.factory.updateVariableDeclarationList(node.declarationList, declarations)
431
465
  ), node);
432
466
  }
433
467
  __name(transformVariableStatement, "transformVariableStatement");
434
468
  function inferStateDebugName(state, declaration, initializer) {
435
469
  if (state.stateAliases.size === 0) return void 0;
436
- if (!ts__default.default.isIdentifier(declaration.name)) return void 0;
470
+ if (!import_typescript.default.isIdentifier(declaration.name)) return void 0;
437
471
  let call = initializer;
438
- while (ts__default.default.isParenthesizedExpression(call) || ts__default.default.isAsExpression(call) || ts__default.default.isTypeAssertionExpression(call) || ts__default.default.isSatisfiesExpression(call)) {
472
+ while (import_typescript.default.isParenthesizedExpression(call) || import_typescript.default.isAsExpression(call) || import_typescript.default.isTypeAssertionExpression(call) || import_typescript.default.isSatisfiesExpression(call)) {
439
473
  call = call.expression;
440
474
  }
441
- if (!ts__default.default.isCallExpression(call)) return void 0;
475
+ if (!import_typescript.default.isCallExpression(call)) return void 0;
442
476
  const callee = call.expression;
443
- if (!ts__default.default.isIdentifier(callee) || !state.stateAliases.has(callee.text)) return void 0;
477
+ if (!import_typescript.default.isIdentifier(callee) || !state.stateAliases.has(callee.text)) return void 0;
444
478
  if (state.localBindings.has(callee.text)) return void 0;
445
479
  if (call.arguments.length !== 1) return void 0;
446
- return ts__default.default.factory.createCallExpression(callee, call.typeArguments, [
480
+ return import_typescript.default.factory.createCallExpression(callee, call.typeArguments, [
447
481
  ...call.arguments,
448
- ts__default.default.factory.createStringLiteral(declaration.name.text)
482
+ import_typescript.default.factory.createStringLiteral(declaration.name.text)
449
483
  ]);
450
484
  }
451
485
  __name(inferStateDebugName, "inferStateDebugName");
486
+ function wrapStateWithHmrRef(state, declaration, initializer) {
487
+ let call = initializer;
488
+ while (import_typescript.default.isParenthesizedExpression(call) || import_typescript.default.isAsExpression(call) || import_typescript.default.isTypeAssertionExpression(call) || import_typescript.default.isSatisfiesExpression(call)) {
489
+ call = call.expression;
490
+ }
491
+ if (!import_typescript.default.isCallExpression(call)) return void 0;
492
+ const callee = call.expression;
493
+ if (!import_typescript.default.isIdentifier(callee) || !state.stateAliases.has(callee.text)) return void 0;
494
+ if (state.localBindings.has(callee.text)) return void 0;
495
+ if (!import_typescript.default.isIdentifier(declaration.name)) return void 0;
496
+ return import_typescript.default.factory.createCallExpression(helperRef(state, "hmrStateRef"), void 0, [
497
+ import_typescript.default.factory.createStringLiteral(`${state.hmrModuleId}#${declaration.name.text}`),
498
+ import_typescript.default.factory.createArrowFunction(
499
+ void 0,
500
+ void 0,
501
+ [],
502
+ void 0,
503
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
504
+ initializer
505
+ )
506
+ ]);
507
+ }
508
+ __name(wrapStateWithHmrRef, "wrapStateWithHmrRef");
452
509
  function containsJsx(expression) {
453
510
  let found = false;
454
511
  const visit = /* @__PURE__ */ __name((node) => {
@@ -456,7 +513,7 @@ function containsJsx(expression) {
456
513
  found = true;
457
514
  return;
458
515
  }
459
- ts__default.default.forEachChild(node, visit);
516
+ import_typescript.default.forEachChild(node, visit);
460
517
  }, "visit");
461
518
  visit(expression);
462
519
  return found;
@@ -464,20 +521,20 @@ function containsJsx(expression) {
464
521
  __name(containsJsx, "containsJsx");
465
522
  function transformBlock(state, block) {
466
523
  const statements = block.statements.map((statement) => {
467
- if (!ts__default.default.isReturnStatement(statement) || !statement.expression) return transformStatement(state, statement);
468
- const expression = ts__default.default.isParenthesizedExpression(statement.expression) ? statement.expression.expression : statement.expression;
469
- return isJsxExpression(expression) ? tagStatement(state, ts__default.default.factory.updateReturnStatement(statement, transformJsxExpression(state, expression)), statement) : statement;
524
+ if (!import_typescript.default.isReturnStatement(statement) || !statement.expression) return transformStatement(state, statement);
525
+ const expression = import_typescript.default.isParenthesizedExpression(statement.expression) ? statement.expression.expression : statement.expression;
526
+ return isJsxExpression(expression) ? tagStatement(state, import_typescript.default.factory.updateReturnStatement(statement, transformJsxExpression(state, expression)), statement) : statement;
470
527
  });
471
- return ts__default.default.factory.updateBlock(block, statements);
528
+ return import_typescript.default.factory.updateBlock(block, statements);
472
529
  }
473
530
  __name(transformBlock, "transformBlock");
474
531
  function isJsxExpression(node) {
475
- return ts__default.default.isJsxElement(node) || ts__default.default.isJsxSelfClosingElement(node) || ts__default.default.isJsxFragment(node);
532
+ return import_typescript.default.isJsxElement(node) || import_typescript.default.isJsxSelfClosingElement(node) || import_typescript.default.isJsxFragment(node);
476
533
  }
477
534
  __name(isJsxExpression, "isJsxExpression");
478
535
  function transformJsxExpression(state, node) {
479
- if (ts__default.default.isJsxFragment(node)) return transformFragment(state, node.children);
480
- if (ts__default.default.isJsxElement(node)) {
536
+ if (import_typescript.default.isJsxFragment(node)) return transformFragment(state, node.children);
537
+ if (import_typescript.default.isJsxElement(node)) {
481
538
  return transformElement(state, node, node.openingElement.tagName, node.openingElement.attributes, node.children);
482
539
  }
483
540
  return transformElement(state, node, node.tagName, node.attributes, []);
@@ -485,35 +542,35 @@ function transformJsxExpression(state, node) {
485
542
  __name(transformJsxExpression, "transformJsxExpression");
486
543
  function transformElement(state, node, tagName, attributes, children) {
487
544
  if (isFragmentTag(tagName)) return transformFragment(state, children);
488
- if (!ts__default.default.isIdentifier(tagName)) {
545
+ if (!import_typescript.default.isIdentifier(tagName)) {
489
546
  reportUnsupportedTag(state, tagName);
490
547
  }
491
- if (ts__default.default.isIdentifier(tagName) && tagName.text === "ResourceBoundary") {
548
+ if (import_typescript.default.isIdentifier(tagName) && tagName.text === "ResourceBoundary") {
492
549
  return transformResourceBoundary(state, node, attributes, children);
493
550
  }
494
- if (ts__default.default.isIdentifier(tagName) && tagName.text === "AsyncBoundary") {
551
+ if (import_typescript.default.isIdentifier(tagName) && tagName.text === "AsyncBoundary") {
495
552
  return transformAsyncBoundary(state, node, attributes, children);
496
553
  }
497
- if (ts__default.default.isIdentifier(tagName) && tagName.text === "ErrorBoundary") {
554
+ if (import_typescript.default.isIdentifier(tagName) && tagName.text === "ErrorBoundary") {
498
555
  return transformErrorBoundary(state, node, attributes, children);
499
556
  }
500
- if (ts__default.default.isIdentifier(tagName) && tagName.text === "Profiler") {
557
+ if (import_typescript.default.isIdentifier(tagName) && tagName.text === "Profiler") {
501
558
  return transformProfiler(state, node, attributes, children);
502
559
  }
503
- if (ts__default.default.isIdentifier(tagName) && /^[A-Z]/.test(tagName.text)) {
560
+ if (import_typescript.default.isIdentifier(tagName) && /^[A-Z]/.test(tagName.text)) {
504
561
  const args = [
505
- ts__default.default.factory.createCallExpression(helperRef(state, "resolveComponent"), void 0, [
562
+ import_typescript.default.factory.createCallExpression(helperRef(state, "resolveComponent"), void 0, [
506
563
  tagName,
507
- ts__default.default.factory.createStringLiteral(state.filename),
508
- ts__default.default.factory.createStringLiteral(tagName.text)
564
+ import_typescript.default.factory.createStringLiteral(state.filename),
565
+ import_typescript.default.factory.createStringLiteral(tagName.text)
509
566
  ]),
510
567
  createComponentProps(state, attributes, children)
511
568
  ];
512
569
  if (state.sourceLocation) args.push(createSourceLocation(tagName));
513
- return ts__default.default.factory.createCallExpression(helperRef(state, "createComponent"), void 0, args);
570
+ return import_typescript.default.factory.createCallExpression(helperRef(state, "createComponent"), void 0, args);
514
571
  }
515
572
  if (isStaticElement(tagName, attributes, children)) {
516
- return ts__default.default.factory.createCallExpression(
573
+ return import_typescript.default.factory.createCallExpression(
517
574
  helperRef(state, "cloneTemplate"),
518
575
  void 0,
519
576
  [registerTemplate(state, serializeStaticHtml(node))]
@@ -525,25 +582,25 @@ function transformElement(state, node, tagName, attributes, children) {
525
582
  createConstStatement(
526
583
  state,
527
584
  elementId,
528
- ts__default.default.factory.createCallExpression(
585
+ import_typescript.default.factory.createCallExpression(
529
586
  helperRef(state, "createElement"),
530
587
  void 0,
531
- [ts__default.default.factory.createStringLiteral(elementName)]
588
+ [import_typescript.default.factory.createStringLiteral(elementName)]
532
589
  ),
533
590
  node
534
591
  )
535
592
  ];
536
593
  appendAttributes(state, statements, elementId, attributes);
537
594
  appendChildren(state, statements, elementId, children);
538
- statements.push(tagStatement(state, ts__default.default.factory.createReturnStatement(elementId), node));
539
- return ts__default.default.factory.createCallExpression(
540
- ts__default.default.factory.createArrowFunction(
595
+ statements.push(tagStatement(state, import_typescript.default.factory.createReturnStatement(elementId), node));
596
+ return import_typescript.default.factory.createCallExpression(
597
+ import_typescript.default.factory.createArrowFunction(
541
598
  void 0,
542
599
  void 0,
543
600
  [],
544
601
  void 0,
545
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.EqualsGreaterThanToken),
546
- ts__default.default.factory.createBlock(statements, true)
602
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
603
+ import_typescript.default.factory.createBlock(statements, true)
547
604
  ),
548
605
  void 0,
549
606
  []
@@ -559,29 +616,29 @@ function transformFragment(state, children) {
559
616
  const anchor = nextIdentifier(state, "_fragmentAnchor");
560
617
  const statements = [];
561
618
  appendChildren(state, statements, parent, children, anchor);
562
- return ts__default.default.factory.createCallExpression(
619
+ return import_typescript.default.factory.createCallExpression(
563
620
  helperRef(state, "createFragment"),
564
621
  void 0,
565
- [ts__default.default.factory.createArrowFunction(
622
+ [import_typescript.default.factory.createArrowFunction(
566
623
  void 0,
567
624
  void 0,
568
625
  [
569
- ts__default.default.factory.createParameterDeclaration(void 0, void 0, parent),
570
- ts__default.default.factory.createParameterDeclaration(void 0, void 0, anchor)
626
+ import_typescript.default.factory.createParameterDeclaration(void 0, void 0, parent),
627
+ import_typescript.default.factory.createParameterDeclaration(void 0, void 0, anchor)
571
628
  ],
572
629
  void 0,
573
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.EqualsGreaterThanToken),
574
- ts__default.default.factory.createBlock(statements, true)
630
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
631
+ import_typescript.default.factory.createBlock(statements, true)
575
632
  )]
576
633
  );
577
634
  }
578
635
  __name(transformFragment, "transformFragment");
579
636
  function transformResourceBoundary(state, node, attributes, children) {
580
637
  const resource = getAttributeExpression(attributes, "resource");
581
- if (!resource) throw new error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "ResourceBoundary \u5FC5\u987B\u63D0\u4F9B resource \u5C5E\u6027", fix: "\u4E3A ResourceBoundary \u6DFB\u52A0 resource={resource}\u3002" });
638
+ if (!resource) throw new import_error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "ResourceBoundary \u5FC5\u987B\u63D0\u4F9B resource \u5C5E\u6027", fix: "\u4E3A ResourceBoundary \u6DFB\u52A0 resource={resource}\u3002" });
582
639
  const options = [
583
- ts__default.default.factory.createPropertyAssignment("resource", transformEmbeddedExpression(state, resource)),
584
- ts__default.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children))
640
+ import_typescript.default.factory.createPropertyAssignment("resource", transformEmbeddedExpression(state, resource)),
641
+ import_typescript.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children))
585
642
  ];
586
643
  appendBoundaryOptionalProperty(state, options, attributes, "loading");
587
644
  appendBoundaryOptionalProperty(state, options, attributes, "empty");
@@ -591,34 +648,34 @@ function transformResourceBoundary(state, node, attributes, children) {
591
648
  __name(transformResourceBoundary, "transformResourceBoundary");
592
649
  function transformErrorBoundary(state, node, attributes, children) {
593
650
  const fallback = getAttributeExpression(attributes, "fallback");
594
- if (!fallback) throw new error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "ErrorBoundary \u5FC5\u987B\u63D0\u4F9B fallback \u5C5E\u6027", fix: "\u4E3A ErrorBoundary \u6DFB\u52A0 fallback={(error, retry) => ...}\u3002" });
651
+ if (!fallback) throw new import_error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "ErrorBoundary \u5FC5\u987B\u63D0\u4F9B fallback \u5C5E\u6027", fix: "\u4E3A ErrorBoundary \u6DFB\u52A0 fallback={(error, retry) => ...}\u3002" });
595
652
  return createBoundaryFragment(state, node, "insertErrorBoundary", [
596
- ts__default.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children)),
597
- ts__default.default.factory.createPropertyAssignment("fallback", transformEmbeddedExpression(state, fallback))
653
+ import_typescript.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children)),
654
+ import_typescript.default.factory.createPropertyAssignment("fallback", transformEmbeddedExpression(state, fallback))
598
655
  ]);
599
656
  }
600
657
  __name(transformErrorBoundary, "transformErrorBoundary");
601
658
  function transformAsyncBoundary(state, node, attributes, children) {
602
659
  const promise = getAttributeExpression(attributes, "promise");
603
- if (!promise) throw new error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "AsyncBoundary \u5FC5\u987B\u63D0\u4F9B promise \u5C5E\u6027", fix: "\u4E3A AsyncBoundary \u6DFB\u52A0 promise={promise}\u3002" });
660
+ if (!promise) throw new import_error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "AsyncBoundary \u5FC5\u987B\u63D0\u4F9B promise \u5C5E\u6027", fix: "\u4E3A AsyncBoundary \u6DFB\u52A0 promise={promise}\u3002" });
604
661
  const options = [
605
- ts__default.default.factory.createPropertyAssignment("promise", transformEmbeddedExpression(state, promise)),
606
- ts__default.default.factory.createPropertyAssignment("children", createAsyncFactory(state, children))
662
+ import_typescript.default.factory.createPropertyAssignment("promise", transformEmbeddedExpression(state, promise)),
663
+ import_typescript.default.factory.createPropertyAssignment("children", createAsyncFactory(state, children))
607
664
  ];
608
665
  appendBoundaryOptionalProperty(state, options, attributes, "loading");
609
666
  appendBoundaryOptionalProperty(state, options, attributes, "fallback");
610
667
  const resetKey = getAttributeExpression(attributes, "resetKey");
611
- if (resetKey) options.push(ts__default.default.factory.createPropertyAssignment("resetKey", createGetter(resetKey)));
668
+ if (resetKey) options.push(import_typescript.default.factory.createPropertyAssignment("resetKey", createGetter(resetKey)));
612
669
  return createBoundaryFragment(state, node, "insertAsyncBoundary", options);
613
670
  }
614
671
  __name(transformAsyncBoundary, "transformAsyncBoundary");
615
672
  function transformProfiler(state, node, attributes, children) {
616
- const idAttribute = attributes.properties.find((attribute) => ts__default.default.isJsxAttribute(attribute) && attribute.name.getText() === "id");
617
- const id = idAttribute && ts__default.default.isJsxAttribute(idAttribute) && idAttribute.initializer && ts__default.default.isStringLiteral(idAttribute.initializer) ? ts__default.default.factory.createStringLiteral(idAttribute.initializer.text) : idAttribute && ts__default.default.isJsxAttribute(idAttribute) && idAttribute.initializer && ts__default.default.isJsxExpression(idAttribute.initializer) ? idAttribute.initializer.expression : null;
618
- if (!id) throw new error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "Profiler \u5FC5\u987B\u63D0\u4F9B id \u5C5E\u6027", fix: '\u4E3A Profiler \u6DFB\u52A0 id="ComponentName"\u3002' });
673
+ const idAttribute = attributes.properties.find((attribute) => import_typescript.default.isJsxAttribute(attribute) && attribute.name.getText() === "id");
674
+ const id = idAttribute && import_typescript.default.isJsxAttribute(idAttribute) && idAttribute.initializer && import_typescript.default.isStringLiteral(idAttribute.initializer) ? import_typescript.default.factory.createStringLiteral(idAttribute.initializer.text) : idAttribute && import_typescript.default.isJsxAttribute(idAttribute) && idAttribute.initializer && import_typescript.default.isJsxExpression(idAttribute.initializer) ? idAttribute.initializer.expression : null;
675
+ if (!id) throw new import_error.VobsError({ code: "VOBS_C002", layer: "compiler", message: "Profiler \u5FC5\u987B\u63D0\u4F9B id \u5C5E\u6027", fix: '\u4E3A Profiler \u6DFB\u52A0 id="ComponentName"\u3002' });
619
676
  const options = [
620
- ts__default.default.factory.createPropertyAssignment("id", transformEmbeddedExpression(state, id)),
621
- ts__default.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children))
677
+ import_typescript.default.factory.createPropertyAssignment("id", transformEmbeddedExpression(state, id)),
678
+ import_typescript.default.factory.createPropertyAssignment("children", createBoundaryFactory(state, children))
622
679
  ];
623
680
  appendBoundaryOptionalProperty(state, options, attributes, "onRender");
624
681
  return createBoundaryFragment(state, node, "insertProfiler", options);
@@ -627,22 +684,22 @@ __name(transformProfiler, "transformProfiler");
627
684
  function createBoundaryFragment(state, node, helper, options) {
628
685
  const parent = nextIdentifier(state, "_boundaryParent");
629
686
  const anchor = nextIdentifier(state, "_boundaryAnchor");
630
- return ts__default.default.factory.createCallExpression(
687
+ return import_typescript.default.factory.createCallExpression(
631
688
  helperRef(state, "createFragment"),
632
689
  void 0,
633
- [ts__default.default.factory.createArrowFunction(
690
+ [import_typescript.default.factory.createArrowFunction(
634
691
  void 0,
635
692
  void 0,
636
693
  [
637
- ts__default.default.factory.createParameterDeclaration(void 0, void 0, parent),
638
- ts__default.default.factory.createParameterDeclaration(void 0, void 0, anchor)
694
+ import_typescript.default.factory.createParameterDeclaration(void 0, void 0, parent),
695
+ import_typescript.default.factory.createParameterDeclaration(void 0, void 0, anchor)
639
696
  ],
640
697
  void 0,
641
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.EqualsGreaterThanToken),
642
- ts__default.default.factory.createBlock([callStatement(state, helper, [
698
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
699
+ import_typescript.default.factory.createBlock([callStatement(state, helper, [
643
700
  parent,
644
701
  anchor,
645
- ts__default.default.factory.createObjectLiteralExpression(options, true)
702
+ import_typescript.default.factory.createObjectLiteralExpression(options, true)
646
703
  ], node)], true)
647
704
  )]
648
705
  );
@@ -650,27 +707,27 @@ function createBoundaryFragment(state, node, helper, options) {
650
707
  __name(createBoundaryFragment, "createBoundaryFragment");
651
708
  function createBoundaryFactory(state, children) {
652
709
  const content = transformFragment(state, children);
653
- return ts__default.default.factory.createArrowFunction(
710
+ return import_typescript.default.factory.createArrowFunction(
654
711
  void 0,
655
712
  void 0,
656
713
  [],
657
714
  void 0,
658
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.EqualsGreaterThanToken),
715
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
659
716
  content
660
717
  );
661
718
  }
662
719
  __name(createBoundaryFactory, "createBoundaryFactory");
663
720
  function createAsyncFactory(state, children) {
664
- const value = ts__default.default.factory.createIdentifier("value");
665
- const expressionChild = children.length === 1 && children[0].kind === ts__default.default.SyntaxKind.JsxExpression ? children[0].expression : void 0;
666
- if (expressionChild && ts__default.default.isArrowFunction(expressionChild)) {
721
+ const value = import_typescript.default.factory.createIdentifier("value");
722
+ const expressionChild = children.length === 1 && children[0].kind === import_typescript.default.SyntaxKind.JsxExpression ? children[0].expression : void 0;
723
+ if (expressionChild && import_typescript.default.isArrowFunction(expressionChild)) {
667
724
  const transformed = transformEmbeddedExpression(state, expressionChild);
668
725
  return transformed;
669
726
  }
670
727
  const content = transformFragment(state, children);
671
- return ts__default.default.factory.createArrowFunction(void 0, void 0, [
672
- ts__default.default.factory.createParameterDeclaration(void 0, void 0, value)
673
- ], void 0, ts__default.default.factory.createToken(ts__default.default.SyntaxKind.EqualsGreaterThanToken), content);
728
+ return import_typescript.default.factory.createArrowFunction(void 0, void 0, [
729
+ import_typescript.default.factory.createParameterDeclaration(void 0, void 0, value)
730
+ ], void 0, import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken), content);
674
731
  }
675
732
  __name(createAsyncFactory, "createAsyncFactory");
676
733
  function appendBoundaryOptionalProperty(state, properties, attributes, name) {
@@ -678,14 +735,14 @@ function appendBoundaryOptionalProperty(state, properties, attributes, name) {
678
735
  if (expression) {
679
736
  const transformed = transformEmbeddedExpression(state, expression);
680
737
  const value = isJsxExpression(unwrapExpression(expression)) ? createGetter(transformed) : transformed;
681
- properties.push(ts__default.default.factory.createPropertyAssignment(name, value));
738
+ properties.push(import_typescript.default.factory.createPropertyAssignment(name, value));
682
739
  }
683
740
  }
684
741
  __name(appendBoundaryOptionalProperty, "appendBoundaryOptionalProperty");
685
742
  function getAttributeExpression(attributes, name) {
686
743
  for (const attribute of attributes.properties) {
687
- if (!ts__default.default.isJsxAttribute(attribute) || attribute.name.getText() !== name) continue;
688
- if (attribute.initializer && ts__default.default.isJsxExpression(attribute.initializer)) {
744
+ if (!import_typescript.default.isJsxAttribute(attribute) || attribute.name.getText() !== name) continue;
745
+ if (attribute.initializer && import_typescript.default.isJsxExpression(attribute.initializer)) {
689
746
  return attribute.initializer.expression ?? null;
690
747
  }
691
748
  }
@@ -693,14 +750,14 @@ function getAttributeExpression(attributes, name) {
693
750
  }
694
751
  __name(getAttributeExpression, "getAttributeExpression");
695
752
  function transformEmbeddedExpression(state, expression) {
696
- const result = ts__default.default.transform(expression, [(context) => (root) => {
753
+ const result = import_typescript.default.transform(expression, [(context) => (root) => {
697
754
  const visit = /* @__PURE__ */ __name((node) => {
698
- if (ts__default.default.isJsxElement(node) || ts__default.default.isJsxSelfClosingElement(node) || ts__default.default.isJsxFragment(node)) {
755
+ if (import_typescript.default.isJsxElement(node) || import_typescript.default.isJsxSelfClosingElement(node) || import_typescript.default.isJsxFragment(node)) {
699
756
  return transformJsxExpression(state, node);
700
757
  }
701
- return ts__default.default.visitEachChild(node, visit, context);
758
+ return import_typescript.default.visitEachChild(node, visit, context);
702
759
  }, "visit");
703
- return ts__default.default.visitNode(root, visit);
760
+ return import_typescript.default.visitNode(root, visit);
704
761
  }]);
705
762
  try {
706
763
  return result.transformed[0];
@@ -709,21 +766,42 @@ function transformEmbeddedExpression(state, expression) {
709
766
  }
710
767
  }
711
768
  __name(transformEmbeddedExpression, "transformEmbeddedExpression");
769
+ function transformResidualJsx(state, sourceFile) {
770
+ if (!containsJsx(sourceFile)) return sourceFile;
771
+ const result = import_typescript.default.transform(sourceFile, [(context) => (root) => {
772
+ const visit = /* @__PURE__ */ __name((node) => {
773
+ if (import_typescript.default.isReturnStatement(node) && node.expression && containsJsx(node.expression)) {
774
+ return import_typescript.default.factory.updateReturnStatement(node, transformEmbeddedExpression(state, node.expression));
775
+ }
776
+ if (isJsxExpression(node)) {
777
+ return transformJsxExpression(state, node);
778
+ }
779
+ return import_typescript.default.visitEachChild(node, visit, context);
780
+ }, "visit");
781
+ return import_typescript.default.visitNode(root, visit);
782
+ }]);
783
+ try {
784
+ return result.transformed[0];
785
+ } finally {
786
+ result.dispose();
787
+ }
788
+ }
789
+ __name(transformResidualJsx, "transformResidualJsx");
712
790
  function isStaticElement(tagName, attributes, children) {
713
- if (!ts__default.default.isIdentifier(tagName) || !/^[a-z]/.test(tagName.text)) return false;
791
+ if (!import_typescript.default.isIdentifier(tagName) || !/^[a-z]/.test(tagName.text)) return false;
714
792
  for (const attribute of attributes.properties) {
715
- if (ts__default.default.isJsxSpreadAttribute(attribute)) return false;
716
- if (!ts__default.default.isJsxAttribute(attribute)) return false;
793
+ if (import_typescript.default.isJsxSpreadAttribute(attribute)) return false;
794
+ if (!import_typescript.default.isJsxAttribute(attribute)) return false;
717
795
  const name = attribute.name.getText();
718
796
  if (name === "key" || name === "ref" || name.startsWith("on")) return false;
719
797
  if (isPropertyAttribute(name)) return false;
720
798
  const initializer = attribute.initializer;
721
- if (initializer && !ts__default.default.isStringLiteral(initializer)) return false;
799
+ if (initializer && !import_typescript.default.isStringLiteral(initializer)) return false;
722
800
  }
723
801
  for (const child of children) {
724
- if (ts__default.default.isJsxText(child)) continue;
725
- if (ts__default.default.isJsxElement(child) || ts__default.default.isJsxSelfClosingElement(child)) {
726
- const nested = ts__default.default.isJsxElement(child) ? { tagName: child.openingElement.tagName, attributes: child.openingElement.attributes, children: child.children } : { tagName: child.tagName, attributes: child.attributes, children: [] };
802
+ if (import_typescript.default.isJsxText(child)) continue;
803
+ if (import_typescript.default.isJsxElement(child) || import_typescript.default.isJsxSelfClosingElement(child)) {
804
+ const nested = import_typescript.default.isJsxElement(child) ? { tagName: child.openingElement.tagName, attributes: child.openingElement.attributes, children: child.children } : { tagName: child.tagName, attributes: child.attributes, children: [] };
727
805
  if (!isStaticElement(nested.tagName, nested.attributes, nested.children)) return false;
728
806
  continue;
729
807
  }
@@ -733,7 +811,7 @@ function isStaticElement(tagName, attributes, children) {
733
811
  }
734
812
  __name(isStaticElement, "isStaticElement");
735
813
  function serializeStaticHtml(node) {
736
- const { tagName, attributes, children } = ts__default.default.isJsxElement(node) ? { tagName: node.openingElement.tagName, attributes: node.openingElement.attributes, children: node.children } : { tagName: node.tagName, attributes: node.attributes, children: [] };
814
+ const { tagName, attributes, children } = import_typescript.default.isJsxElement(node) ? { tagName: node.openingElement.tagName, attributes: node.openingElement.attributes, children: node.children } : { tagName: node.tagName, attributes: node.attributes, children: [] };
737
815
  return serializeStaticElement(tagName, attributes, children);
738
816
  }
739
817
  __name(serializeStaticHtml, "serializeStaticHtml");
@@ -741,25 +819,25 @@ function serializeStaticElement(tagName, attributes, children) {
741
819
  const name = tagName.getText();
742
820
  let html = `<${name}`;
743
821
  for (const attribute of attributes.properties) {
744
- if (!ts__default.default.isJsxAttribute(attribute)) continue;
822
+ if (!import_typescript.default.isJsxAttribute(attribute)) continue;
745
823
  const attributeName = attribute.name.getText() === "className" ? "class" : attribute.name.getText();
746
824
  const initializer = attribute.initializer;
747
825
  if (!initializer) {
748
826
  html += ` ${attributeName}=""`;
749
827
  continue;
750
828
  }
751
- if (ts__default.default.isStringLiteral(initializer)) {
829
+ if (import_typescript.default.isStringLiteral(initializer)) {
752
830
  html += ` ${attributeName}="${escapeHtmlAttribute(initializer.text)}"`;
753
831
  }
754
832
  }
755
833
  html += ">";
756
834
  for (const child of children) {
757
- if (ts__default.default.isJsxText(child)) {
835
+ if (import_typescript.default.isJsxText(child)) {
758
836
  const text = child.text.replace(/\s+/g, " ").trimStart();
759
837
  if (text.trim()) html += escapeHtmlText(text);
760
838
  continue;
761
839
  }
762
- if (ts__default.default.isJsxElement(child)) {
840
+ if (import_typescript.default.isJsxElement(child)) {
763
841
  html += serializeStaticElement(
764
842
  child.openingElement.tagName,
765
843
  child.openingElement.attributes,
@@ -767,7 +845,7 @@ function serializeStaticElement(tagName, attributes, children) {
767
845
  );
768
846
  continue;
769
847
  }
770
- if (ts__default.default.isJsxSelfClosingElement(child)) {
848
+ if (import_typescript.default.isJsxSelfClosingElement(child)) {
771
849
  html += serializeStaticElement(child.tagName, child.attributes, []);
772
850
  }
773
851
  }
@@ -793,103 +871,103 @@ function registerTemplate(state, html) {
793
871
  __name(registerTemplate, "registerTemplate");
794
872
  function createTemplateDeclarations(state) {
795
873
  return [...state.templates.entries()].map(
796
- ([html, identifier]) => ts__default.default.factory.createVariableStatement(void 0, ts__default.default.factory.createVariableDeclarationList([
797
- ts__default.default.factory.createVariableDeclaration(identifier, void 0, void 0, ts__default.default.factory.createCallExpression(
874
+ ([html, identifier]) => import_typescript.default.factory.createVariableStatement(void 0, import_typescript.default.factory.createVariableDeclarationList([
875
+ import_typescript.default.factory.createVariableDeclaration(identifier, void 0, void 0, import_typescript.default.factory.createCallExpression(
798
876
  helperRef(state, "createTemplate"),
799
877
  void 0,
800
- [ts__default.default.factory.createStringLiteral(html)]
878
+ [import_typescript.default.factory.createStringLiteral(html)]
801
879
  ))
802
- ], ts__default.default.NodeFlags.Const))
880
+ ], import_typescript.default.NodeFlags.Const))
803
881
  );
804
882
  }
805
883
  __name(createTemplateDeclarations, "createTemplateDeclarations");
806
884
  function appendAttributes(state, statements, element, attributes) {
807
885
  const staticProps = [];
808
- const hasSpread = attributes.properties.some((attribute) => ts__default.default.isJsxSpreadAttribute(attribute));
886
+ const hasSpread = attributes.properties.some((attribute) => import_typescript.default.isJsxSpreadAttribute(attribute));
809
887
  for (const attribute of attributes.properties) {
810
- if (ts__default.default.isJsxSpreadAttribute(attribute)) {
888
+ if (import_typescript.default.isJsxSpreadAttribute(attribute)) {
811
889
  statements.push(callStatement(state, "spreadProps", [element, transformEmbeddedExpression(state, attribute.expression)], attribute));
812
890
  continue;
813
891
  }
814
- if (!ts__default.default.isJsxAttribute(attribute)) continue;
892
+ if (!import_typescript.default.isJsxAttribute(attribute)) continue;
815
893
  const name = attribute.name.getText();
816
894
  if (name === "key") continue;
817
895
  if (name === "ref") {
818
896
  const initializer2 = attribute.initializer;
819
- if (initializer2 && ts__default.default.isJsxExpression(initializer2) && initializer2.expression) {
897
+ if (initializer2 && import_typescript.default.isJsxExpression(initializer2) && initializer2.expression) {
820
898
  statements.push(callStatement(state, "setRef", [element, transformEmbeddedExpression(state, initializer2.expression)], attribute));
821
899
  }
822
900
  continue;
823
901
  }
824
902
  const initializer = attribute.initializer;
825
- if (name.startsWith("on") && initializer && ts__default.default.isJsxExpression(initializer) && initializer.expression) {
903
+ if (name.startsWith("on") && initializer && import_typescript.default.isJsxExpression(initializer) && initializer.expression) {
826
904
  statements.push(callStatement(state, "addEventListener", [
827
905
  element,
828
- ts__default.default.factory.createStringLiteral(name.slice(2).toLowerCase()),
906
+ import_typescript.default.factory.createStringLiteral(name.slice(2).toLowerCase()),
829
907
  initializer.expression
830
908
  ], attribute));
831
909
  continue;
832
910
  }
833
911
  if (!initializer) {
834
912
  if (hasSpread) {
835
- statements.push(callStatement(state, isPropertyAttribute(name) ? "setProperty" : "setAttribute", [element, ts__default.default.factory.createStringLiteral(isPropertyAttribute(name) ? name : name === "className" ? "class" : name), isPropertyAttribute(name) ? ts__default.default.factory.createTrue() : ts__default.default.factory.createStringLiteral("")], attribute));
913
+ statements.push(callStatement(state, isPropertyAttribute(name) ? "setProperty" : "setAttribute", [element, import_typescript.default.factory.createStringLiteral(isPropertyAttribute(name) ? name : name === "className" ? "class" : name), isPropertyAttribute(name) ? import_typescript.default.factory.createTrue() : import_typescript.default.factory.createStringLiteral("")], attribute));
836
914
  continue;
837
915
  }
838
- if (isPropertyAttribute(name)) staticProps.push(createStaticProperty(name, ts__default.default.factory.createTrue()));
839
- else staticProps.push(createStaticProperty(name === "className" ? "class" : name, ts__default.default.factory.createStringLiteral("")));
916
+ if (isPropertyAttribute(name)) staticProps.push(createStaticProperty(name, import_typescript.default.factory.createTrue()));
917
+ else staticProps.push(createStaticProperty(name === "className" ? "class" : name, import_typescript.default.factory.createStringLiteral("")));
840
918
  continue;
841
919
  }
842
- if (ts__default.default.isStringLiteral(initializer)) {
920
+ if (import_typescript.default.isStringLiteral(initializer)) {
843
921
  if (hasSpread) {
844
- statements.push(callStatement(state, isPropertyAttribute(name) ? "setProperty" : "setAttribute", [element, ts__default.default.factory.createStringLiteral(isPropertyAttribute(name) ? name : name === "className" ? "class" : name), ts__default.default.factory.createStringLiteral(initializer.text)], attribute));
922
+ statements.push(callStatement(state, isPropertyAttribute(name) ? "setProperty" : "setAttribute", [element, import_typescript.default.factory.createStringLiteral(isPropertyAttribute(name) ? name : name === "className" ? "class" : name), import_typescript.default.factory.createStringLiteral(initializer.text)], attribute));
845
923
  continue;
846
924
  }
847
925
  staticProps.push(createStaticProperty(
848
926
  isPropertyAttribute(name) ? name : name === "className" ? "class" : name,
849
- ts__default.default.factory.createStringLiteral(initializer.text)
927
+ import_typescript.default.factory.createStringLiteral(initializer.text)
850
928
  ));
851
929
  continue;
852
930
  }
853
931
  const attributeName = name === "className" ? "class" : name;
854
932
  const propertyAttribute = isPropertyAttribute(name);
855
- if (ts__default.default.isJsxExpression(initializer) && initializer.expression) {
933
+ if (import_typescript.default.isJsxExpression(initializer) && initializer.expression) {
856
934
  statements.push(callStatement(state, propertyAttribute ? "bindProperty" : "bindAttribute", [
857
935
  element,
858
- ts__default.default.factory.createStringLiteral(propertyAttribute ? name : attributeName),
936
+ import_typescript.default.factory.createStringLiteral(propertyAttribute ? name : attributeName),
859
937
  createGetter(initializer.expression)
860
938
  ], attribute));
861
939
  }
862
940
  }
863
941
  if (staticProps.length) statements.splice(1, 0, callStatement(state, "setStaticProps", [
864
942
  element,
865
- ts__default.default.factory.createObjectLiteralExpression(staticProps, true)
943
+ import_typescript.default.factory.createObjectLiteralExpression(staticProps, true)
866
944
  ], attributes));
867
945
  }
868
946
  __name(appendAttributes, "appendAttributes");
869
947
  function createStaticProperty(name, value) {
870
- return ts__default.default.factory.createPropertyAssignment(ts__default.default.factory.createStringLiteral(name), value);
948
+ return import_typescript.default.factory.createPropertyAssignment(import_typescript.default.factory.createStringLiteral(name), value);
871
949
  }
872
950
  __name(createStaticProperty, "createStaticProperty");
873
951
  function isPropertyAttribute(name) {
874
952
  return name === "value" || name === "checked" || name === "selected" || name === "disabled" || name === "multiple" || name === "readOnly" || name === "required" || name === "autofocus" || name === "hidden" || name === "tabIndex";
875
953
  }
876
954
  __name(isPropertyAttribute, "isPropertyAttribute");
877
- function appendChildren(state, statements, element, children, anchor = ts__default.default.factory.createNull()) {
955
+ function appendChildren(state, statements, element, children, anchor = import_typescript.default.factory.createNull()) {
878
956
  for (const child of children) {
879
- if (ts__default.default.isJsxText(child)) {
957
+ if (import_typescript.default.isJsxText(child)) {
880
958
  const text = child.text.replace(/\s+/g, " ").trimStart();
881
959
  if (text.trim()) {
882
960
  statements.push(callStatement(state, "insertBefore", [
883
961
  element,
884
- ts__default.default.factory.createCallExpression(helperRef(state, "createText"), void 0, [
885
- ts__default.default.factory.createStringLiteral(text)
962
+ import_typescript.default.factory.createCallExpression(helperRef(state, "createText"), void 0, [
963
+ import_typescript.default.factory.createStringLiteral(text)
886
964
  ]),
887
965
  anchor
888
966
  ], child));
889
967
  }
890
968
  continue;
891
969
  }
892
- if (ts__default.default.isJsxElement(child) || ts__default.default.isJsxSelfClosingElement(child) || ts__default.default.isJsxFragment(child)) {
970
+ if (import_typescript.default.isJsxElement(child) || import_typescript.default.isJsxSelfClosingElement(child) || import_typescript.default.isJsxFragment(child)) {
893
971
  statements.push(callStatement(state, "insertBefore", [
894
972
  element,
895
973
  transformJsxExpression(state, child),
@@ -897,7 +975,7 @@ function appendChildren(state, statements, element, children, anchor = ts__defau
897
975
  ], child));
898
976
  continue;
899
977
  }
900
- if (child.kind === ts__default.default.SyntaxKind.JsxExpression) {
978
+ if (child.kind === import_typescript.default.SyntaxKind.JsxExpression) {
901
979
  const expression = child.expression;
902
980
  if (!expression) continue;
903
981
  const list = transformListExpression(state, element, expression, anchor);
@@ -910,9 +988,9 @@ function appendChildren(state, statements, element, children, anchor = ts__defau
910
988
  statements.push(callStatement(state, "insertDynamic", [element, anchor, dynamic], child));
911
989
  continue;
912
990
  }
913
- if (!containsJsx(expression) && !ts__default.default.isIdentifier(expression)) {
991
+ if (!containsJsx(expression) && !import_typescript.default.isIdentifier(expression)) {
914
992
  const textId = nextIdentifier(state, "_text");
915
- statements.push(createConstStatement(state, textId, ts__default.default.factory.createCallExpression(helperRef(state, "createText"), void 0, [ts__default.default.factory.createStringLiteral("")]), child));
993
+ statements.push(createConstStatement(state, textId, import_typescript.default.factory.createCallExpression(helperRef(state, "createText"), void 0, [import_typescript.default.factory.createStringLiteral("")]), child));
916
994
  statements.push(callStatement(state, "insertBefore", [element, textId, anchor], child));
917
995
  statements.push(callStatement(state, "bindText", [textId, createGetter(expression)], child));
918
996
  continue;
@@ -926,18 +1004,18 @@ __name(appendChildren, "appendChildren");
926
1004
  function createComponentProps(state, attributes, children) {
927
1005
  const properties = [];
928
1006
  for (const attribute of attributes.properties) {
929
- if (ts__default.default.isJsxSpreadAttribute(attribute)) {
930
- properties.push(ts__default.default.factory.createSpreadAssignment(attribute.expression));
1007
+ if (import_typescript.default.isJsxSpreadAttribute(attribute)) {
1008
+ properties.push(import_typescript.default.factory.createSpreadAssignment(attribute.expression));
931
1009
  continue;
932
1010
  }
933
1011
  const name = propertyName(attribute.name.getText());
934
1012
  if (attribute.name.getText() === "key") continue;
935
1013
  const initializer = attribute.initializer;
936
1014
  if (!initializer) {
937
- properties.push(ts__default.default.factory.createPropertyAssignment(name, ts__default.default.factory.createTrue()));
938
- } else if (ts__default.default.isStringLiteral(initializer)) {
939
- properties.push(ts__default.default.factory.createPropertyAssignment(name, ts__default.default.factory.createStringLiteral(initializer.text)));
940
- } else if (ts__default.default.isJsxExpression(initializer) && initializer.expression) {
1015
+ properties.push(import_typescript.default.factory.createPropertyAssignment(name, import_typescript.default.factory.createTrue()));
1016
+ } else if (import_typescript.default.isStringLiteral(initializer)) {
1017
+ properties.push(import_typescript.default.factory.createPropertyAssignment(name, import_typescript.default.factory.createStringLiteral(initializer.text)));
1018
+ } else if (import_typescript.default.isJsxExpression(initializer) && initializer.expression) {
941
1019
  properties.push(createGetterProperty(name, transformEmbeddedExpression(state, initializer.expression)));
942
1020
  }
943
1021
  }
@@ -945,62 +1023,78 @@ function createComponentProps(state, attributes, children) {
945
1023
  if (childExpressions.length === 1) {
946
1024
  properties.push(createGetterProperty("children", childExpressions[0]));
947
1025
  } else if (childExpressions.length > 1) {
948
- properties.push(createGetterProperty("children", ts__default.default.factory.createArrayLiteralExpression(childExpressions)));
1026
+ properties.push(createGetterProperty("children", import_typescript.default.factory.createArrayLiteralExpression(childExpressions)));
949
1027
  }
950
- return ts__default.default.factory.createObjectLiteralExpression(properties, true);
1028
+ return import_typescript.default.factory.createObjectLiteralExpression(properties, true);
951
1029
  }
952
1030
  __name(createComponentProps, "createComponentProps");
953
1031
  function createSourceLocation(node) {
954
1032
  const sourceFile = node.getSourceFile();
955
1033
  const position = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
956
- return ts__default.default.factory.createObjectLiteralExpression([
957
- ts__default.default.factory.createPropertyAssignment("file", ts__default.default.factory.createStringLiteral(sourceFile.fileName)),
958
- ts__default.default.factory.createPropertyAssignment("line", ts__default.default.factory.createNumericLiteral(position.line + 1)),
959
- ts__default.default.factory.createPropertyAssignment("column", ts__default.default.factory.createNumericLiteral(position.character + 1))
1034
+ return import_typescript.default.factory.createObjectLiteralExpression([
1035
+ import_typescript.default.factory.createPropertyAssignment("file", import_typescript.default.factory.createStringLiteral(sourceFile.fileName)),
1036
+ import_typescript.default.factory.createPropertyAssignment("line", import_typescript.default.factory.createNumericLiteral(position.line + 1)),
1037
+ import_typescript.default.factory.createPropertyAssignment("column", import_typescript.default.factory.createNumericLiteral(position.character + 1))
960
1038
  ], true);
961
1039
  }
962
1040
  __name(createSourceLocation, "createSourceLocation");
963
1041
  function transformDynamicExpression(state, expression) {
964
- if (ts__default.default.isBinaryExpression(expression) && expression.operatorToken.kind === ts__default.default.SyntaxKind.AmpersandAmpersandToken) {
1042
+ const converted = convertDynamicNodeExpression(state, expression);
1043
+ return converted ? createGetter(converted) : null;
1044
+ }
1045
+ __name(transformDynamicExpression, "transformDynamicExpression");
1046
+ function convertDynamicNodeExpression(state, expression) {
1047
+ if (import_typescript.default.isBinaryExpression(expression) && expression.operatorToken.kind === import_typescript.default.SyntaxKind.AmpersandAmpersandToken) {
965
1048
  const right = unwrapExpression(expression.right);
966
- if (!isJsxExpression(right)) return null;
967
- return createGetter(ts__default.default.factory.createConditionalExpression(
968
- expression.left,
969
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.QuestionToken),
970
- transformJsxExpression(state, right),
971
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.ColonToken),
972
- ts__default.default.factory.createNull()
973
- ));
1049
+ if (isJsxExpression(right)) {
1050
+ return createNodeConditional(expression.left, transformJsxExpression(state, right), null);
1051
+ }
1052
+ const convertedRight = convertDynamicNodeExpression(state, right);
1053
+ if (convertedRight) return createNodeConditional(expression.left, convertedRight, null);
1054
+ return null;
974
1055
  }
975
- if (ts__default.default.isConditionalExpression(expression)) {
1056
+ if (import_typescript.default.isConditionalExpression(expression)) {
976
1057
  const whenTrue = transformDynamicBranch(state, expression.whenTrue);
977
1058
  const whenFalse = transformDynamicBranch(state, expression.whenFalse);
978
1059
  if (!whenTrue && !whenFalse) return null;
979
- return createGetter(ts__default.default.factory.createConditionalExpression(
1060
+ return import_typescript.default.factory.createConditionalExpression(
980
1061
  expression.condition,
981
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.QuestionToken),
982
- whenTrue ?? ts__default.default.factory.createNull(),
983
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.ColonToken),
984
- whenFalse ?? ts__default.default.factory.createNull()
985
- ));
1062
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.QuestionToken),
1063
+ whenTrue ?? import_typescript.default.factory.createNull(),
1064
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.ColonToken),
1065
+ whenFalse ?? import_typescript.default.factory.createNull()
1066
+ );
986
1067
  }
987
1068
  return null;
988
1069
  }
989
- __name(transformDynamicExpression, "transformDynamicExpression");
1070
+ __name(convertDynamicNodeExpression, "convertDynamicNodeExpression");
1071
+ function createNodeConditional(condition, whenTrue, whenFalse) {
1072
+ return import_typescript.default.factory.createConditionalExpression(
1073
+ condition,
1074
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.QuestionToken),
1075
+ whenTrue,
1076
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.ColonToken),
1077
+ whenFalse ?? import_typescript.default.factory.createNull()
1078
+ );
1079
+ }
1080
+ __name(createNodeConditional, "createNodeConditional");
990
1081
  function transformDynamicBranch(state, expression) {
991
1082
  const branch = unwrapExpression(expression);
992
1083
  if (isJsxExpression(branch)) return transformJsxExpression(state, branch);
993
- if (branch.kind === ts__default.default.SyntaxKind.NullKeyword || branch.kind === ts__default.default.SyntaxKind.FalseKeyword) return branch;
1084
+ if (branch.kind === import_typescript.default.SyntaxKind.NullKeyword || branch.kind === import_typescript.default.SyntaxKind.FalseKeyword) return branch;
1085
+ if (import_typescript.default.isConditionalExpression(branch) || import_typescript.default.isBinaryExpression(branch) && branch.operatorToken.kind === import_typescript.default.SyntaxKind.AmpersandAmpersandToken) {
1086
+ return convertDynamicNodeExpression(state, branch);
1087
+ }
994
1088
  return null;
995
1089
  }
996
1090
  __name(transformDynamicBranch, "transformDynamicBranch");
997
1091
  function transformListExpression(state, parent, expression, anchor) {
998
- if (!ts__default.default.isCallExpression(expression) || expression.arguments.length !== 1) return null;
999
- if (!ts__default.default.isPropertyAccessExpression(expression.expression) || expression.expression.name.text !== "map") return null;
1092
+ if (!import_typescript.default.isCallExpression(expression) || expression.arguments.length !== 1) return null;
1093
+ if (!import_typescript.default.isPropertyAccessExpression(expression.expression) || expression.expression.name.text !== "map") return null;
1000
1094
  const callback = expression.arguments[0];
1001
- if (!ts__default.default.isArrowFunction(callback) && !ts__default.default.isFunctionExpression(callback)) return null;
1095
+ if (!import_typescript.default.isArrowFunction(callback) && !import_typescript.default.isFunctionExpression(callback)) return null;
1002
1096
  const body = unwrapExpression(callback.body);
1003
- if (!isJsxExpression(body) || ts__default.default.isJsxFragment(body)) return null;
1097
+ if (!isJsxExpression(body) || import_typescript.default.isJsxFragment(body)) return null;
1004
1098
  const key = findKeyExpression(body);
1005
1099
  const renderItem = transformListCallback(callback, transformJsxExpression(state, body));
1006
1100
  const args = [
@@ -1014,8 +1108,8 @@ function transformListExpression(state, parent, expression, anchor) {
1014
1108
  }
1015
1109
  __name(transformListExpression, "transformListExpression");
1016
1110
  function transformListCallback(callback, body) {
1017
- if (ts__default.default.isArrowFunction(callback)) {
1018
- return ts__default.default.factory.updateArrowFunction(
1111
+ if (import_typescript.default.isArrowFunction(callback)) {
1112
+ return import_typescript.default.factory.updateArrowFunction(
1019
1113
  callback,
1020
1114
  callback.modifiers,
1021
1115
  callback.typeParameters,
@@ -1025,7 +1119,7 @@ function transformListCallback(callback, body) {
1025
1119
  body
1026
1120
  );
1027
1121
  }
1028
- return ts__default.default.factory.updateFunctionExpression(
1122
+ return import_typescript.default.factory.updateFunctionExpression(
1029
1123
  callback,
1030
1124
  callback.modifiers,
1031
1125
  callback.asteriskToken,
@@ -1033,26 +1127,26 @@ function transformListCallback(callback, body) {
1033
1127
  callback.typeParameters,
1034
1128
  callback.parameters,
1035
1129
  callback.type,
1036
- ts__default.default.factory.createBlock([ts__default.default.factory.createReturnStatement(body)], true)
1130
+ import_typescript.default.factory.createBlock([import_typescript.default.factory.createReturnStatement(body)], true)
1037
1131
  );
1038
1132
  }
1039
1133
  __name(transformListCallback, "transformListCallback");
1040
1134
  function createKeyCallback(callback, key) {
1041
- return ts__default.default.factory.createArrowFunction(
1135
+ return import_typescript.default.factory.createArrowFunction(
1042
1136
  void 0,
1043
1137
  void 0,
1044
1138
  callback.parameters,
1045
1139
  void 0,
1046
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.EqualsGreaterThanToken),
1140
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
1047
1141
  key
1048
1142
  );
1049
1143
  }
1050
1144
  __name(createKeyCallback, "createKeyCallback");
1051
1145
  function findKeyExpression(node) {
1052
- const attributes = ts__default.default.isJsxElement(node) ? node.openingElement.attributes : node.attributes;
1146
+ const attributes = import_typescript.default.isJsxElement(node) ? node.openingElement.attributes : node.attributes;
1053
1147
  for (const attribute of attributes.properties) {
1054
- if (!ts__default.default.isJsxAttribute(attribute) || attribute.name.getText() !== "key") continue;
1055
- if (attribute.initializer && ts__default.default.isJsxExpression(attribute.initializer)) {
1148
+ if (!import_typescript.default.isJsxAttribute(attribute) || attribute.name.getText() !== "key") continue;
1149
+ if (attribute.initializer && import_typescript.default.isJsxExpression(attribute.initializer)) {
1056
1150
  return attribute.initializer.expression ?? null;
1057
1151
  }
1058
1152
  }
@@ -1060,18 +1154,18 @@ function findKeyExpression(node) {
1060
1154
  }
1061
1155
  __name(findKeyExpression, "findKeyExpression");
1062
1156
  function unwrapExpression(node) {
1063
- return ts__default.default.isParenthesizedExpression(node) ? node.expression : node;
1157
+ return import_typescript.default.isParenthesizedExpression(node) ? node.expression : node;
1064
1158
  }
1065
1159
  __name(unwrapExpression, "unwrapExpression");
1066
1160
  function childToComponentExpression(state, child) {
1067
- if (ts__default.default.isJsxText(child)) {
1161
+ if (import_typescript.default.isJsxText(child)) {
1068
1162
  const text = child.text.replace(/\s+/g, " ").trim();
1069
- return text ? [ts__default.default.factory.createStringLiteral(text)] : [];
1163
+ return text ? [import_typescript.default.factory.createStringLiteral(text)] : [];
1070
1164
  }
1071
- if (ts__default.default.isJsxElement(child) || ts__default.default.isJsxSelfClosingElement(child) || ts__default.default.isJsxFragment(child)) {
1165
+ if (import_typescript.default.isJsxElement(child) || import_typescript.default.isJsxSelfClosingElement(child) || import_typescript.default.isJsxFragment(child)) {
1072
1166
  return [transformJsxExpression(state, child)];
1073
1167
  }
1074
- if (child.kind === ts__default.default.SyntaxKind.JsxExpression) {
1168
+ if (child.kind === import_typescript.default.SyntaxKind.JsxExpression) {
1075
1169
  const expression = child.expression;
1076
1170
  return expression ? [transformEmbeddedExpression(state, expression)] : [];
1077
1171
  }
@@ -1079,43 +1173,43 @@ function childToComponentExpression(state, child) {
1079
1173
  }
1080
1174
  __name(childToComponentExpression, "childToComponentExpression");
1081
1175
  function propertyName(name) {
1082
- return /^[$A-Z_a-z][$\w]*$/u.test(name) ? ts__default.default.factory.createIdentifier(name) : ts__default.default.factory.createStringLiteral(name);
1176
+ return /^[$A-Z_a-z][$\w]*$/u.test(name) ? import_typescript.default.factory.createIdentifier(name) : import_typescript.default.factory.createStringLiteral(name);
1083
1177
  }
1084
1178
  __name(propertyName, "propertyName");
1085
1179
  function createGetter(expression) {
1086
- return ts__default.default.factory.createArrowFunction(
1180
+ return import_typescript.default.factory.createArrowFunction(
1087
1181
  void 0,
1088
1182
  void 0,
1089
1183
  [],
1090
1184
  void 0,
1091
- ts__default.default.factory.createToken(ts__default.default.SyntaxKind.EqualsGreaterThanToken),
1185
+ import_typescript.default.factory.createToken(import_typescript.default.SyntaxKind.EqualsGreaterThanToken),
1092
1186
  expression
1093
1187
  );
1094
1188
  }
1095
1189
  __name(createGetter, "createGetter");
1096
1190
  function createGetterProperty(name, expression) {
1097
- return ts__default.default.factory.createGetAccessorDeclaration(
1191
+ return import_typescript.default.factory.createGetAccessorDeclaration(
1098
1192
  void 0,
1099
1193
  typeof name === "string" ? propertyName(name) : name,
1100
1194
  [],
1101
1195
  void 0,
1102
- ts__default.default.factory.createBlock([ts__default.default.factory.createReturnStatement(expression)], true)
1196
+ import_typescript.default.factory.createBlock([import_typescript.default.factory.createReturnStatement(expression)], true)
1103
1197
  );
1104
1198
  }
1105
1199
  __name(createGetterProperty, "createGetterProperty");
1106
1200
  function callStatement(state, name, args, source) {
1107
- const statement = ts__default.default.factory.createExpressionStatement(
1108
- ts__default.default.factory.createCallExpression(helperRef(state, name), void 0, args)
1201
+ const statement = import_typescript.default.factory.createExpressionStatement(
1202
+ import_typescript.default.factory.createCallExpression(helperRef(state, name), void 0, args)
1109
1203
  );
1110
1204
  return source ? tagStatement(state, statement, source) : statement;
1111
1205
  }
1112
1206
  __name(callStatement, "callStatement");
1113
1207
  function createConstStatement(state, name, initializer, source) {
1114
- const statement = ts__default.default.factory.createVariableStatement(
1208
+ const statement = import_typescript.default.factory.createVariableStatement(
1115
1209
  void 0,
1116
- ts__default.default.factory.createVariableDeclarationList([
1117
- ts__default.default.factory.createVariableDeclaration(name, void 0, void 0, initializer)
1118
- ], ts__default.default.NodeFlags.Const)
1210
+ import_typescript.default.factory.createVariableDeclarationList([
1211
+ import_typescript.default.factory.createVariableDeclaration(name, void 0, void 0, initializer)
1212
+ ], import_typescript.default.NodeFlags.Const)
1119
1213
  );
1120
1214
  return source ? tagStatement(state, statement, source) : statement;
1121
1215
  }
@@ -1138,12 +1232,13 @@ function nextIdentifier(state, prefix) {
1138
1232
  do {
1139
1233
  name = `${prefix}${state.generatedId++}`;
1140
1234
  } while (state.takenNames.has(name));
1141
- return ts__default.default.factory.createIdentifier(name);
1235
+ return import_typescript.default.factory.createIdentifier(name);
1142
1236
  }
1143
1237
  __name(nextIdentifier, "nextIdentifier");
1144
-
1145
- exports.compile = compile;
1146
- exports.compileWithSourceMap = compileWithSourceMap;
1147
- exports.createCompiler = createCompiler;
1148
- //# sourceMappingURL=compile.cjs.map
1238
+ // Annotate the CommonJS export names for ESM import in node:
1239
+ 0 && (module.exports = {
1240
+ compile,
1241
+ compileWithSourceMap,
1242
+ createCompiler
1243
+ });
1149
1244
  //# sourceMappingURL=compile.cjs.map