@zessjs/compiler 1.0.5 → 1.0.6

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.
@@ -0,0 +1,1375 @@
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
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;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+
24
+ //#endregion
25
+ const astring = __toESM(require("astring"));
26
+ const entities = __toESM(require("entities"));
27
+ const merge_source_map = __toESM(require("merge-source-map"));
28
+ const meriyah = __toESM(require("meriyah"));
29
+ const source_map = __toESM(require("source-map"));
30
+
31
+ //#region src/visit.ts
32
+ const ESTreeNodeKeys = {
33
+ AccessorProperty: [
34
+ "key",
35
+ "value",
36
+ "$decorators"
37
+ ],
38
+ ArrayExpression: ["$elements"],
39
+ ArrayPattern: ["$elements"],
40
+ ArrowFunctionExpression: ["$params", "body"],
41
+ AssignmentExpression: ["left", "right"],
42
+ AssignmentPattern: ["left", "right"],
43
+ AwaitExpression: ["argument"],
44
+ BinaryExpression: ["left", "right"],
45
+ BlockStatement: ["$body"],
46
+ BreakStatement: ["label"],
47
+ CallExpression: ["callee", "$arguments"],
48
+ ChainExpression: ["expression"],
49
+ ImportExpression: ["source", "options"],
50
+ CatchClause: ["param", "body"],
51
+ ClassBody: ["$body"],
52
+ ClassDeclaration: [
53
+ "id",
54
+ "body",
55
+ "superClass",
56
+ "$decorators"
57
+ ],
58
+ ClassExpression: [
59
+ "id",
60
+ "body",
61
+ "superClass",
62
+ "$decorators"
63
+ ],
64
+ ConditionalExpression: [
65
+ "test",
66
+ "consequent",
67
+ "alternate"
68
+ ],
69
+ ContinueStatement: ["label"],
70
+ Decorator: ["expression"],
71
+ DoWhileStatement: ["test", "body"],
72
+ ExportAllDeclaration: [
73
+ "source",
74
+ "exported",
75
+ "$attributes"
76
+ ],
77
+ ExportDefaultDeclaration: ["declaration"],
78
+ ExportNamedDeclaration: [
79
+ "declaration",
80
+ "$specifiers",
81
+ "source",
82
+ "$attributes"
83
+ ],
84
+ ExportSpecifier: ["local", "exported"],
85
+ ExpressionStatement: ["expression"],
86
+ PropertyDefinition: [
87
+ "key",
88
+ "value",
89
+ "$decorators"
90
+ ],
91
+ ForInStatement: [
92
+ "left",
93
+ "right",
94
+ "body"
95
+ ],
96
+ ForOfStatement: [
97
+ "left",
98
+ "right",
99
+ "body"
100
+ ],
101
+ ForStatement: [
102
+ "init",
103
+ "test",
104
+ "update",
105
+ "body"
106
+ ],
107
+ FunctionDeclaration: [
108
+ "id",
109
+ "$params",
110
+ "body"
111
+ ],
112
+ FunctionExpression: [
113
+ "id",
114
+ "$params",
115
+ "body"
116
+ ],
117
+ IfStatement: [
118
+ "test",
119
+ "consequent",
120
+ "alternate"
121
+ ],
122
+ ImportDeclaration: [
123
+ "source",
124
+ "$specifiers",
125
+ "$attributes"
126
+ ],
127
+ ImportDefaultSpecifier: ["local"],
128
+ ImportAttribute: ["key", "value"],
129
+ ImportNamespaceSpecifier: ["local"],
130
+ ImportSpecifier: ["local", "imported"],
131
+ JSXNamespacedName: ["namespace", "name"],
132
+ JSXAttribute: ["name", "value"],
133
+ JSXClosingElement: ["name"],
134
+ JSXElement: [
135
+ "openingElement",
136
+ "closingElement",
137
+ "$children"
138
+ ],
139
+ JSXExpressionContainer: ["expression"],
140
+ JSXFragment: [
141
+ "openingFragment",
142
+ "closingFragment",
143
+ "$children"
144
+ ],
145
+ JSXOpeningElement: ["name", "$attributes"],
146
+ JSXSpreadAttribute: ["argument"],
147
+ JSXSpreadChild: ["expression"],
148
+ JSXMemberExpression: ["object", "property"],
149
+ LabeledStatement: ["label", "body"],
150
+ LogicalExpression: ["left", "right"],
151
+ MemberExpression: ["object", "property"],
152
+ MetaProperty: ["meta", "property"],
153
+ MethodDefinition: [
154
+ "key",
155
+ "value",
156
+ "$decorators"
157
+ ],
158
+ NewExpression: ["callee", "$arguments"],
159
+ ObjectExpression: ["$properties"],
160
+ ObjectPattern: ["$properties"],
161
+ ParenthesizedExpression: ["expression"],
162
+ Program: ["$body"],
163
+ Property: ["key", "value"],
164
+ RestElement: ["argument", "value"],
165
+ ReturnStatement: ["argument"],
166
+ SequenceExpression: ["$expressions"],
167
+ SpreadElement: ["argument"],
168
+ StaticBlock: ["$body"],
169
+ SwitchCase: ["test", "$consequent"],
170
+ SwitchStatement: ["discriminant", "$cases"],
171
+ TaggedTemplateExpression: ["tag", "quasi"],
172
+ TemplateLiteral: ["$quasis", "$expressions"],
173
+ ThrowStatement: ["argument"],
174
+ TryStatement: [
175
+ "block",
176
+ "handler",
177
+ "finalizer"
178
+ ],
179
+ UpdateExpression: ["argument"],
180
+ UnaryExpression: ["argument"],
181
+ VariableDeclaration: ["$declarations"],
182
+ VariableDeclarator: ["id", "init"],
183
+ WhileStatement: ["test", "body"],
184
+ WithStatement: ["object", "body"],
185
+ YieldExpression: ["argument"]
186
+ };
187
+ function visit(ast, config) {
188
+ let shouldBreak = false;
189
+ let shouldSkipChildren = false;
190
+ const traverse = (node, parent, key, index) => {
191
+ if (shouldBreak) return;
192
+ let nodeToReplace;
193
+ let nodeToRemove;
194
+ const context = {
195
+ replace(newNode) {
196
+ nodeToReplace = newNode;
197
+ },
198
+ remove() {
199
+ nodeToRemove = node;
200
+ },
201
+ skip() {
202
+ shouldSkipChildren = true;
203
+ },
204
+ break() {
205
+ shouldBreak = true;
206
+ }
207
+ };
208
+ if (config.enter) {
209
+ config.enter.call(context, node, parent, key, index);
210
+ if (shouldBreak) return;
211
+ }
212
+ if (config[node.type]) {
213
+ config[node.type].call(context, node, parent, key, index);
214
+ if (shouldBreak) return;
215
+ }
216
+ if ((nodeToReplace || nodeToRemove) && parent && key) {
217
+ if (index === void 0) parent[key] = nodeToReplace ?? null;
218
+ else {
219
+ const nodes = parent[key];
220
+ if (nodeToReplace) nodes[index] = nodeToReplace;
221
+ else nodes.splice(index, 1);
222
+ }
223
+ if (nodeToReplace) traverse(nodeToReplace, parent, key, index);
224
+ return;
225
+ }
226
+ if (shouldSkipChildren) shouldSkipChildren = false;
227
+ else if (ESTreeNodeKeys[node.type]) {
228
+ const keys = ESTreeNodeKeys[node.type];
229
+ for (let i = 0; i < keys.length; ++i) {
230
+ const key$1 = keys[i];
231
+ if (key$1[0] === "$") {
232
+ const nodesKey = key$1.slice(1);
233
+ const values = node[nodesKey];
234
+ if (!values) continue;
235
+ let length = values.length;
236
+ for (let j = 0; j < length; ++j) {
237
+ const child = values[j];
238
+ if (!child) continue;
239
+ traverse(child, node, nodesKey, j);
240
+ if (shouldBreak) return;
241
+ if (length > values.length) {
242
+ length--;
243
+ j--;
244
+ }
245
+ }
246
+ } else {
247
+ const nodeKey = key$1;
248
+ const value = node[nodeKey];
249
+ if (!value) continue;
250
+ traverse(value, node, nodeKey);
251
+ if (shouldBreak) return;
252
+ }
253
+ }
254
+ }
255
+ if (config.exit) config.exit.call(context, node, parent, key, index);
256
+ };
257
+ traverse(ast);
258
+ }
259
+
260
+ //#endregion
261
+ //#region src/compiler.ts
262
+ const UPPERCASE_REGEX = /^[A-Z]/;
263
+ const NATIVE_EVENT_REGEX = /^on[a-z]+$/;
264
+ const NON_BLANK_LINE_REGEX = /\S|^[^\S\r\n]+$/;
265
+ const EDGE_SPACE_REGEX = /^\s*[\r\n]\s*|[\r\n]\s*$/g;
266
+ const SPACE_REGEX = /\s+/g;
267
+ const IDENTIFIER_REGEX = /^[a-z_$][\w$]*$/i;
268
+ const SVGTags = new Set([
269
+ "animate",
270
+ "animateMotion",
271
+ "animateTransform",
272
+ "circle",
273
+ "clipPath",
274
+ "cursor",
275
+ "defs",
276
+ "desc",
277
+ "ellipse",
278
+ "feBlend",
279
+ "feColorMatrix",
280
+ "feComponentTransfer",
281
+ "feComposite",
282
+ "feConvolveMatrix",
283
+ "feDiffuseLighting",
284
+ "feDisplacementMap",
285
+ "feDistantLight",
286
+ "feDropShadow",
287
+ "feFlood",
288
+ "feFuncA",
289
+ "feFuncB",
290
+ "feFuncG",
291
+ "feFuncR",
292
+ "feGaussianBlur",
293
+ "feImage",
294
+ "feMerge",
295
+ "feMergeNode",
296
+ "feMorphology",
297
+ "feOffset",
298
+ "fePointLight",
299
+ "feSpecularLighting",
300
+ "feSpotLight",
301
+ "feTile",
302
+ "feTurbulence",
303
+ "filter",
304
+ "font-face",
305
+ "font-face-format",
306
+ "font-face-name",
307
+ "font-face-src",
308
+ "font-face-uri",
309
+ "foreignObject",
310
+ "g",
311
+ "glyph",
312
+ "glyphRef",
313
+ "hkern",
314
+ "line",
315
+ "linearGradient",
316
+ "marker",
317
+ "mask",
318
+ "metadata",
319
+ "missing-glyph",
320
+ "mpath",
321
+ "path",
322
+ "pattern",
323
+ "polygon",
324
+ "polyline",
325
+ "radialGradient",
326
+ "rect",
327
+ "set",
328
+ "stop",
329
+ "svg",
330
+ "switch",
331
+ "symbol",
332
+ "text",
333
+ "textPath",
334
+ "tref",
335
+ "tspan",
336
+ "use",
337
+ "view",
338
+ "vkern"
339
+ ]);
340
+ const MathMLTags = new Set([
341
+ "annotation",
342
+ "annotation-xml",
343
+ "maction",
344
+ "math",
345
+ "menclose",
346
+ "merror",
347
+ "mfenced",
348
+ "mfrac",
349
+ "mi",
350
+ "mmultiscripts",
351
+ "mn",
352
+ "mo",
353
+ "mover",
354
+ "mpadded",
355
+ "mphantom",
356
+ "mprescripts",
357
+ "mroot",
358
+ "mrow",
359
+ "ms",
360
+ "mspace",
361
+ "msqrt",
362
+ "mstyle",
363
+ "msub",
364
+ "msubsup",
365
+ "msup",
366
+ "mtable",
367
+ "mtd",
368
+ "mtext",
369
+ "mtr",
370
+ "munder",
371
+ "munderover",
372
+ "semantics"
373
+ ]);
374
+ const DOMProperties = new Set([
375
+ "allowFullscreen",
376
+ "async",
377
+ "autofocus",
378
+ "autoplay",
379
+ "checked",
380
+ "controls",
381
+ "default",
382
+ "disabled",
383
+ "formNoValidate",
384
+ "hidden",
385
+ "indeterminate",
386
+ "inert",
387
+ "innerHTML",
388
+ "innerText",
389
+ "isMap",
390
+ "loop",
391
+ "multiple",
392
+ "muted",
393
+ "noValidate",
394
+ "nomodule",
395
+ "open",
396
+ "playsInline",
397
+ "readOnly",
398
+ "required",
399
+ "reversed",
400
+ "seamless",
401
+ "selected",
402
+ "textContent",
403
+ "value"
404
+ ]);
405
+ const keywords = new Set([
406
+ "async",
407
+ "await",
408
+ "break",
409
+ "case",
410
+ "catch",
411
+ "class",
412
+ "const",
413
+ "continue",
414
+ "debugger",
415
+ "default",
416
+ "delete",
417
+ "do",
418
+ "else",
419
+ "enum",
420
+ "export",
421
+ "extends",
422
+ "false",
423
+ "finally",
424
+ "for",
425
+ "function",
426
+ "if",
427
+ "import",
428
+ "in",
429
+ "instanceof",
430
+ "let",
431
+ "new",
432
+ "null",
433
+ "return",
434
+ "super",
435
+ "switch",
436
+ "this",
437
+ "throw",
438
+ "true",
439
+ "try",
440
+ "typeof",
441
+ "var",
442
+ "void",
443
+ "while",
444
+ "with",
445
+ "yield"
446
+ ]);
447
+ let currentContext;
448
+ function compile(code, options = {}) {
449
+ let prevFunctionParent;
450
+ let prevHasThisInFunction;
451
+ const ast = (0, meriyah.parse)(code, {
452
+ jsx: true,
453
+ next: true,
454
+ module: true,
455
+ ranges: true,
456
+ loc: true
457
+ });
458
+ currentContext = {
459
+ config: {
460
+ sourcemap: options.sourcemap,
461
+ file: options.file ?? "output.js",
462
+ sourceRoot: options.sourceRoot ?? "",
463
+ modulePath: options.modulePath ?? "@zessjs/core"
464
+ },
465
+ ast,
466
+ events: [],
467
+ eventsCache: new Set(),
468
+ generatedFunctions: new WeakSet()
469
+ };
470
+ visit(ast, {
471
+ JSXElement(node) {
472
+ currentContext.JSXId ??= 0;
473
+ currentContext.refId ??= 0;
474
+ currentContext.thisId ??= 0;
475
+ const stmts = transformElement(node);
476
+ let expression;
477
+ if (stmts.length === 1) if (stmts[0].type === "VariableDeclaration") expression = stmts[0].declarations[0].init;
478
+ else expression = stmts[0].expression;
479
+ else {
480
+ const stmt = stmts[0];
481
+ const id = stmt.declarations[0].id;
482
+ const callExpressionPosition = copyPosition(node);
483
+ expression = createCallExpression(createArrowFunctionExpression(createBlockStatement([...stmts, createReturnStatement(id, callExpressionPosition)], callExpressionPosition), callExpressionPosition), [], callExpressionPosition);
484
+ }
485
+ currentContext.JSXParent ??= expression;
486
+ this.replace(expression);
487
+ },
488
+ JSXFragment(node) {
489
+ currentContext.JSXId ??= 0;
490
+ currentContext.refId ??= 0;
491
+ currentContext.thisId ??= 0;
492
+ const expression = transformFragment(node.children, copyPosition(node.openingFragment));
493
+ currentContext.JSXParent ??= expression;
494
+ this.replace(expression);
495
+ },
496
+ FunctionDeclaration(node) {
497
+ prevFunctionParent = currentContext.functionParent;
498
+ prevHasThisInFunction = currentContext.hasThisInFunction;
499
+ currentContext.functionParent = node;
500
+ currentContext.hasThisInFunction = false;
501
+ },
502
+ FunctionExpression(node) {
503
+ if (currentContext.generatedFunctions.has(node)) currentContext.generatedFunctions.delete(node);
504
+ else {
505
+ prevFunctionParent = currentContext.functionParent;
506
+ prevHasThisInFunction = currentContext.hasThisInFunction;
507
+ currentContext.functionParent = node;
508
+ currentContext.hasThisInFunction = false;
509
+ }
510
+ },
511
+ ArrowFunctionExpression(node, parent, key) {
512
+ if (parent?.type === "PropertyDefinition" && key === "value") {
513
+ prevFunctionParent = currentContext.functionParent;
514
+ prevHasThisInFunction = currentContext.hasThisInFunction;
515
+ currentContext.functionParent = node;
516
+ currentContext.hasThisInFunction = false;
517
+ }
518
+ },
519
+ ThisExpression(node) {
520
+ const expression = transformThisExpression(node);
521
+ if (expression) this.replace(expression);
522
+ },
523
+ exit(node) {
524
+ if (node === currentContext.functionParent) {
525
+ currentContext.functionParent = prevFunctionParent;
526
+ currentContext.hasThisInFunction = prevHasThisInFunction;
527
+ } else if (node === currentContext.JSXParent) {
528
+ currentContext.JSXId = void 0;
529
+ currentContext.refId = void 0;
530
+ currentContext.thisId = void 0;
531
+ currentContext.JSXParent = void 0;
532
+ }
533
+ }
534
+ });
535
+ injectRuntimeImport(ast);
536
+ const sourceMap = new source_map.SourceMapGenerator({
537
+ file: currentContext.config.file,
538
+ sourceRoot: currentContext.config.sourceRoot
539
+ });
540
+ code = (0, astring.generate)(ast, { sourceMap });
541
+ let map = sourceMap.toJSON();
542
+ if (currentContext.config.sourcemap) map = (0, merge_source_map.default)(currentContext.config.sourcemap, map);
543
+ return {
544
+ code,
545
+ map
546
+ };
547
+ }
548
+ function transformElement(node) {
549
+ const stmts = [];
550
+ const opening = node.openingElement;
551
+ const tagName = transformJSXTagName(opening.name);
552
+ const tagNamePosition = copyPosition(tagName);
553
+ if (tagName.type === "Literal") {
554
+ const value = tagName.value;
555
+ const args = [createLiteral(value, tagNamePosition)];
556
+ const JSXId = createIdentifier(getUniqueId("el", "JSXId"), tagNamePosition);
557
+ const namespace = SVGTags.has(value) ? 1 : MathMLTags.has(value) ? 2 : 0;
558
+ if (namespace) args.push(createLiteral(namespace, tagNamePosition));
559
+ currentContext.shouldImportCreateElement = true;
560
+ stmts.push(createVariableDeclaration(JSXId, createCallExpression(createIdentifier("_$createElement", tagNamePosition), args, tagNamePosition), tagNamePosition), ...transformAttributes(opening.attributes, JSXId), ...transformChildren(node.children, JSXId));
561
+ } else {
562
+ const elementPosition = copyPosition(node);
563
+ currentContext.shouldImportCreateComponent = true;
564
+ stmts.push(createExpressionStatement(createCallExpression(createIdentifier("_$createComponent", elementPosition), [tagName, transformProperties(opening.attributes, node.children, copyPosition(opening))], elementPosition), elementPosition));
565
+ }
566
+ return stmts;
567
+ }
568
+ function transformFragment(children, position, isInComponent) {
569
+ const elements = [];
570
+ let hasDynamicChildren = false;
571
+ let shouldImportUseMemo = false;
572
+ let textContent;
573
+ let textPosition;
574
+ let elementsPosition;
575
+ let childExpression;
576
+ for (let i = 0; i < children.length; ++i) {
577
+ const childNode = children[i];
578
+ if (childNode.type === "JSXText") {
579
+ const text = childNode.value;
580
+ if (isBlankLine(text)) continue;
581
+ if (textContent) textContent = `${textContent}${text}`;
582
+ else {
583
+ textContent = text;
584
+ textPosition = copyPosition(childNode);
585
+ elementsPosition ??= textPosition;
586
+ }
587
+ } else if (isJSXEmptyExpression(childNode)) continue;
588
+ else if (childNode.type === "JSXFragment") children.splice(i--, 1, ...childNode.children);
589
+ else {
590
+ const childPosition = copyPosition(childNode);
591
+ let childElement;
592
+ if (textContent) {
593
+ elements.push(createLiteral(decodeText(textContent), textPosition));
594
+ textContent = textPosition = void 0;
595
+ }
596
+ if (childNode.type === "JSXElement") {
597
+ const stmts = transformElement(childNode);
598
+ if (isInComponent) hasDynamicChildren = true;
599
+ if (stmts.length > 1) {
600
+ const stmt = stmts[0];
601
+ const id = stmt.declarations[0].id;
602
+ childElement = createCallExpression(createArrowFunctionExpression(createBlockStatement([...stmts, createReturnStatement(id, childPosition)], childPosition), childPosition), [], childPosition);
603
+ } else if (stmts[0].type === "VariableDeclaration") childElement = stmts[0].declarations[0].init;
604
+ else childElement = stmts[0].expression;
605
+ } else {
606
+ const expression = childNode.expression;
607
+ if (isInComponent) childExpression ??= expression;
608
+ if (isDynamicExpression(expression, isInComponent)) {
609
+ shouldImportUseMemo = hasDynamicChildren = true;
610
+ childElement = createCallExpression(createIdentifier("_$memo", childPosition), [!isInComponent && isBareIdentifierCall(expression) ? expression.callee : createArrowFunctionExpression(expression, copyPosition(expression))], childPosition);
611
+ } else childElement = expression;
612
+ }
613
+ elements.push(childElement);
614
+ elementsPosition ??= childPosition;
615
+ }
616
+ }
617
+ if (textContent) elements.push(createLiteral(decodeText(textContent), textPosition));
618
+ if (isInComponent) {
619
+ currentContext.prevHasDynamicChildrenInComponent = currentContext.hasDynamicChildrenInComponent;
620
+ currentContext.hasDynamicChildrenInComponent = hasDynamicChildren;
621
+ }
622
+ if (elements.length > 1) {
623
+ if (shouldImportUseMemo) currentContext.shouldImportUseMemo = true;
624
+ return createArrayExpression(elements, elementsPosition);
625
+ }
626
+ if (elements.length === 1) {
627
+ if (!childExpression) {
628
+ if (shouldImportUseMemo) currentContext.shouldImportUseMemo = true;
629
+ return elements[0];
630
+ }
631
+ return childExpression;
632
+ }
633
+ if (!isInComponent) return createArrayExpression(elements, position);
634
+ }
635
+ function transformThisExpression(node) {
636
+ if (!currentContext.JSXParent) return;
637
+ const thisId = createIdentifier(getUniqueId("self", "thisId"), copyPosition(node));
638
+ if (!currentContext.functionParent) {
639
+ if (currentContext.hasThisInProgram) return thisId;
640
+ const { body } = currentContext.ast;
641
+ const programPosition = copyPosition(currentContext.ast);
642
+ currentContext.hasThisInProgram = true;
643
+ for (let i = 0; i < body.length; ++i) {
644
+ if (body[i].type === "ImportDeclaration") continue;
645
+ body.splice(i, 0, createVariableDeclaration(thisId, createThisExpression(programPosition), programPosition));
646
+ break;
647
+ }
648
+ } else if (!currentContext.hasThisInFunction) {
649
+ const functionPosition = copyPosition(currentContext.functionParent);
650
+ const block = currentContext.functionParent.body;
651
+ const declaration = createVariableDeclaration(thisId, createThisExpression(functionPosition), functionPosition);
652
+ currentContext.hasThisInFunction = true;
653
+ if (block.type === "BlockStatement") block.body.unshift(declaration);
654
+ else currentContext.functionParent.body = createBlockStatement([declaration, createReturnStatement(block, copyPosition(block))], functionPosition);
655
+ }
656
+ return thisId;
657
+ }
658
+ function injectRuntimeImport(ast) {
659
+ const specifiers = [];
660
+ const programPosition = copyPosition(ast);
661
+ if (currentContext.shouldImportCreateComponent) specifiers.push(createImportSpecifier("_$createComponent", "createComponent", programPosition));
662
+ if (currentContext.shouldImportCreateElement) specifiers.push(createImportSpecifier("_$createElement", "createElement", programPosition));
663
+ if (currentContext.events.length) {
664
+ specifiers.push(createImportSpecifier("_$delegateEvents", "delegateEvents", programPosition));
665
+ ast.body.push(createExpressionStatement(createCallExpression(createIdentifier("_$delegateEvents", programPosition), [createArrayExpression(currentContext.events, programPosition)], programPosition), programPosition));
666
+ }
667
+ if (currentContext.shouldImportInsert) specifiers.push(createImportSpecifier("_$insert", "insert", programPosition));
668
+ if (currentContext.shouldImportMergeProps) specifiers.push(createImportSpecifier("_$mergeProps", "mergeProps", programPosition));
669
+ if (currentContext.shouldImportSetAttribute) specifiers.push(createImportSpecifier("_$setAttribute", "setAttribute", programPosition));
670
+ if (currentContext.shouldImportSetAttributeNS) specifiers.push(createImportSpecifier("_$setAttributeNS", "setAttributeNS", programPosition));
671
+ if (currentContext.shouldImportSetClassName) specifiers.push(createImportSpecifier("_$className", "setClassName", programPosition));
672
+ if (currentContext.shouldImportSetStyle) specifiers.push(createImportSpecifier("_$style", "setStyle", programPosition));
673
+ if (currentContext.shouldImportSpread) specifiers.push(createImportSpecifier("_$spread", "spread", programPosition));
674
+ if (currentContext.shouldImportUse) specifiers.push(createImportSpecifier("_$use", "use", programPosition));
675
+ if (currentContext.shouldImportUseEffect) specifiers.push(createImportSpecifier("_$effect", "useRenderEffect", programPosition));
676
+ if (currentContext.shouldImportUseMemo) specifiers.push(createImportSpecifier("_$memo", "useMemo", programPosition));
677
+ if (specifiers.length) ast.body.unshift({
678
+ type: "ImportDeclaration",
679
+ specifiers,
680
+ attributes: [],
681
+ source: createLiteral(currentContext.config.modulePath, programPosition),
682
+ ...programPosition
683
+ });
684
+ }
685
+ function transformJSXTagName(node) {
686
+ const tagNamePosition = copyPosition(node);
687
+ if (node.type === "JSXNamespacedName") {
688
+ const namespace = node.namespace;
689
+ return createLiteral(`${namespace.name}:${node.name.name}`, tagNamePosition);
690
+ }
691
+ let object;
692
+ let expression;
693
+ if (node.type === "JSXMemberExpression") {
694
+ object = expression = tagNamePosition;
695
+ do {
696
+ const isValidPropertyName = isValidIdentifier(node.property.name);
697
+ const propertyPosition = copyPosition(node.property);
698
+ object.type = "MemberExpression";
699
+ object.property = isValidPropertyName ? createIdentifier(node.property.name, propertyPosition) : createLiteral(node.property.name, propertyPosition);
700
+ object.computed = !isValidPropertyName;
701
+ object.object = object = copyPosition(node.object);
702
+ node = node.object;
703
+ } while (node.type === "JSXMemberExpression");
704
+ }
705
+ const tagName = node;
706
+ if (tagName.name === "this") {
707
+ const id = transformThisExpression(tagName);
708
+ if (expression) {
709
+ object.type = "Identifier";
710
+ object.name = id.name;
711
+ } else expression = id;
712
+ } else if (expression || UPPERCASE_REGEX.test(tagName.name)) if (expression) {
713
+ object.type = "Identifier";
714
+ object.name = tagName.name;
715
+ } else expression = createIdentifier(tagName.name, tagNamePosition);
716
+ else expression = createLiteral(tagName.name, tagNamePosition);
717
+ return expression;
718
+ }
719
+ function transformAttributes(attrs, id) {
720
+ const stmts = [];
721
+ const attributeNameCache = new Set(["children"]);
722
+ let shouldImportSpread = false;
723
+ let shouldImportMergeProps = false;
724
+ let properties = [];
725
+ let shouldImportSetStyle;
726
+ let shouldImportSetClassName;
727
+ let shouldImportSetAttribute;
728
+ let shouldImportSetAttributeNS;
729
+ let shouldImportUseEffect;
730
+ let ref;
731
+ let events;
732
+ let objectPosition;
733
+ let spreadArgs;
734
+ let spreadArgsPosition;
735
+ let effect;
736
+ let effectProperty;
737
+ let effectStmts;
738
+ let effectParameter;
739
+ let effectFunction;
740
+ let effectPosition;
741
+ let dynamicCount;
742
+ for (let i = 0; i < attrs.length; ++i) {
743
+ let expression;
744
+ const attr = attrs[i];
745
+ const attributePosition = copyPosition(attr);
746
+ if (attr.type === "JSXAttribute") {
747
+ const attributeName = getAttributeName(attr.name);
748
+ if (attributeNameCache.has(attributeName)) continue;
749
+ let value;
750
+ let isDynamicValue = false;
751
+ const attributeNamePosition = copyPosition(attr.name);
752
+ attributeNameCache.add(attributeName);
753
+ if (!attr.value) value = createLiteral(true, attributeNamePosition);
754
+ else if (attr.value.type === "Literal") value = attr.value;
755
+ else if (attr.value.type === "JSXExpressionContainer") {
756
+ expression = attr.value.expression;
757
+ if (attributeName === "ref") {
758
+ if (matchesType(expression, isRightValue)) {
759
+ const refId = createIdentifier(getUniqueId("ref", "refId"), attributeNamePosition);
760
+ const binaryExpression = createBinaryExpression(createUnaryExpression(refId, attributePosition), createLiteral("function", attributePosition), "===", attributePosition);
761
+ const callExpression = createCallExpression(createIdentifier("_$use", attributePosition), [refId, id], attributePosition);
762
+ currentContext.shouldImportUse = true;
763
+ ref = [createVariableDeclaration(refId, expression, attributePosition), createExpressionStatement(isLeftValue(expression) ? createConditionalExpression(binaryExpression, callExpression, createAssignmentExpression(expression, id, attributePosition), attributePosition) : createLogicalExpression(binaryExpression, callExpression, attributePosition), attributePosition)];
764
+ continue;
765
+ }
766
+ if (isFunctionExpression(expression)) {
767
+ currentContext.shouldImportUse = true;
768
+ ref = [createExpressionStatement(createCallExpression(createIdentifier("_$use", attributePosition), [expression, id], attributePosition), attributePosition)];
769
+ continue;
770
+ }
771
+ } else if (!shouldImportSpread && attributeName.startsWith("on") && matchesType(expression, isListener)) {
772
+ let eventName;
773
+ if (NATIVE_EVENT_REGEX.test(attributeName)) eventName = attributeName;
774
+ else {
775
+ eventName = attributeName.slice(2).toLowerCase();
776
+ if (eventName === "doubleclick") eventName = "dblclick";
777
+ if (!currentContext.eventsCache.has(eventName)) {
778
+ currentContext.eventsCache.add(eventName);
779
+ currentContext.events.push(createLiteral(eventName, attributeNamePosition));
780
+ }
781
+ eventName = `$$${eventName}`;
782
+ }
783
+ (events ??= []).push(createExpressionStatement(createAssignmentExpression(createMemberExpression(id, createIdentifier(eventName, attributeNamePosition), false, attributeNamePosition), expression, attributePosition), attributePosition));
784
+ continue;
785
+ }
786
+ value = expression;
787
+ isDynamicValue = isDynamicExpression(value);
788
+ }
789
+ const isValidPropertyName = isValidIdentifier(attributeName);
790
+ const property = createProperty(isValidPropertyName ? createIdentifier(attributeName, attributeNamePosition) : createLiteral(attributeName, attributeNamePosition), isDynamicValue ? createFunctionExpression([createReturnStatement(value, attributePosition)]) : value, isDynamicValue ? "get" : "init", !isValidPropertyName, false, attributePosition);
791
+ objectPosition ??= attributePosition;
792
+ properties.push(property);
793
+ if (shouldImportSpread) continue;
794
+ let styleOrClassArgs;
795
+ if (attributeName === "style") if (matchesType(value, isStylesheet)) {
796
+ shouldImportSetStyle = true;
797
+ expression = createCallExpression(createIdentifier("_$style", attributeNamePosition), styleOrClassArgs = [id, value], attributePosition);
798
+ } else expression = createAssignmentExpression(createMemberExpression(createMemberExpression(id, createIdentifier(attributeName, attributeNamePosition), false, attributeNamePosition), createIdentifier("cssText", attributeNamePosition), false, attributeNamePosition), value, attributePosition);
799
+ else if (attributeName === "class" || attributeName === "className") if (matchesType(value, isStylesheet)) {
800
+ shouldImportSetClassName = true;
801
+ expression = createCallExpression(createIdentifier("_$className", attributeNamePosition), styleOrClassArgs = [id, value], attributePosition);
802
+ } else {
803
+ shouldImportSetAttribute = true;
804
+ expression = createCallExpression(createIdentifier("_$setAttribute", attributeNamePosition), [
805
+ id,
806
+ createLiteral("class", attributeNamePosition),
807
+ value
808
+ ], attributePosition);
809
+ }
810
+ else if (DOMProperties.has(attributeName) || attributeName.startsWith("on")) expression = createAssignmentExpression(createMemberExpression(id, createIdentifier(attributeName, attributeNamePosition), false, attributeNamePosition), value, attributePosition);
811
+ else {
812
+ let method;
813
+ let attributeArgs;
814
+ const prefix = attributeName.split(":")[0];
815
+ const namespace = prefix === "xlink" ? 3 : prefix === "xml" ? 4 : 0;
816
+ const name = createLiteral(attributeName, attributeNamePosition);
817
+ if (namespace) {
818
+ method = "_$setAttributeNS";
819
+ shouldImportSetAttributeNS = true;
820
+ attributeArgs = [
821
+ id,
822
+ createLiteral(namespace, attributeNamePosition),
823
+ name,
824
+ value
825
+ ];
826
+ } else {
827
+ method = "_$setAttribute";
828
+ shouldImportSetAttribute = true;
829
+ attributeArgs = [
830
+ id,
831
+ name,
832
+ value
833
+ ];
834
+ }
835
+ expression = createCallExpression(createIdentifier(method, attributeNamePosition), attributeArgs, attributePosition);
836
+ }
837
+ if (isDynamicValue) {
838
+ if (effect) {
839
+ let valueId;
840
+ let effectKey;
841
+ let member;
842
+ let object;
843
+ let assignment;
844
+ let declaration;
845
+ if (effect.arguments.length === 1) {
846
+ let hasEffectParameter;
847
+ let effectValue;
848
+ let effectCall = effectFunction.body;
849
+ effectKey = effectProperty.key;
850
+ if (effectParameter) hasEffectParameter = true;
851
+ else {
852
+ hasEffectParameter = false;
853
+ effectParameter = createIdentifier(getUniqueId("p"), effectPosition);
854
+ }
855
+ dynamicCount = 0;
856
+ valueId = createIdentifier(getUniqueId("v", ++dynamicCount), effectPosition);
857
+ member = createMemberExpression(effectParameter, effectKey, effectProperty.computed, effectPosition);
858
+ if (hasEffectParameter) {
859
+ const args = effectCall.arguments;
860
+ effectValue = args[1];
861
+ args[1] = valueId;
862
+ args[2] = member;
863
+ effectCall = createAssignmentExpression(member, effectCall, effectPosition);
864
+ } else {
865
+ assignment = createAssignmentExpression(member, valueId, effectPosition);
866
+ if (effectCall.type === "CallExpression") {
867
+ const index = effectCall.arguments.length - 1;
868
+ effectValue = effectCall.arguments[index];
869
+ effectCall.arguments[index] = assignment;
870
+ } else {
871
+ effectValue = effectCall.right;
872
+ effectCall.right = assignment;
873
+ }
874
+ effectCall = createLogicalExpression(createBinaryExpression(valueId, member, "!==", effectPosition), effectCall, effectPosition);
875
+ effectFunction.params.push(effectParameter);
876
+ }
877
+ declaration = createVariableDeclaration(valueId, effectValue, effectPosition);
878
+ effectStmts = [declaration, createExpressionStatement(effectCall, effectPosition)];
879
+ effectFunction.body = createBlockStatement(effectStmts, effectPosition);
880
+ object = createObjectExpression([createProperty(effectKey, createIdentifier("undefined", effectPosition), "init", effectProperty.computed, false, effectPosition)], effectPosition);
881
+ effect.arguments.push(object);
882
+ } else {
883
+ object = effect.arguments[1];
884
+ declaration = effectStmts[0];
885
+ }
886
+ effectKey = property.key;
887
+ valueId = createIdentifier(getUniqueId("v", ++dynamicCount), attributePosition);
888
+ member = createMemberExpression(effectParameter, effectKey, property.computed, attributePosition);
889
+ if (styleOrClassArgs) {
890
+ styleOrClassArgs[1] = valueId;
891
+ styleOrClassArgs.push(member);
892
+ expression = createAssignmentExpression(member, expression, attributePosition);
893
+ } else {
894
+ assignment = createAssignmentExpression(member, valueId, attributePosition);
895
+ if (expression.type === "CallExpression") expression.arguments[expression.arguments.length - 1] = assignment;
896
+ else expression.right = assignment;
897
+ expression = createLogicalExpression(createBinaryExpression(valueId, member, "!==", attributePosition), expression, attributePosition);
898
+ }
899
+ object.properties.push(createProperty(effectKey, createIdentifier("undefined", attributePosition), "init", property.computed, false, attributePosition));
900
+ declaration.declarations.push(createVariableDeclarator(valueId, value, attributePosition));
901
+ effectStmts.push(createExpressionStatement(expression, attributePosition));
902
+ continue;
903
+ }
904
+ effectProperty = property;
905
+ effectPosition = attributePosition;
906
+ effectFunction = createArrowFunctionExpression(expression, effectPosition);
907
+ if (styleOrClassArgs) {
908
+ effectParameter = createIdentifier(getUniqueId("p"), effectPosition);
909
+ effectFunction.params.push(effectParameter);
910
+ styleOrClassArgs.push(effectParameter);
911
+ }
912
+ shouldImportUseEffect = true;
913
+ expression = effect = createCallExpression(createIdentifier("_$effect", effectPosition), [effectFunction], effectPosition);
914
+ }
915
+ } else {
916
+ let { argument } = attr;
917
+ spreadArgs ??= [id];
918
+ if (properties.length) {
919
+ spreadArgs.push(createObjectExpression(properties, objectPosition));
920
+ properties = [];
921
+ spreadArgsPosition ??= objectPosition;
922
+ objectPosition = void 0;
923
+ }
924
+ if (isDynamicExpression(argument)) {
925
+ shouldImportMergeProps = true;
926
+ argument = isBareIdentifierCall(argument) ? argument.callee : createArrowFunctionExpression(argument, copyPosition(argument));
927
+ }
928
+ spreadArgs.push(argument);
929
+ if (shouldImportSpread) continue;
930
+ currentContext.shouldImportSpread = shouldImportSpread = true;
931
+ spreadArgsPosition ??= attributePosition;
932
+ shouldImportSetStyle = false;
933
+ shouldImportSetClassName = false;
934
+ shouldImportSetAttribute = false;
935
+ shouldImportSetAttributeNS = false;
936
+ shouldImportUseEffect = false;
937
+ stmts.length = 0;
938
+ expression = createCallExpression(createIdentifier("_$spread", attributePosition), spreadArgs, attributePosition);
939
+ }
940
+ stmts.push(createExpressionStatement(expression, attributePosition));
941
+ }
942
+ if (spreadArgs) {
943
+ if (properties.length) spreadArgs.push(createObjectExpression(properties, objectPosition));
944
+ if (shouldImportMergeProps || spreadArgs.length > 2) {
945
+ currentContext.shouldImportMergeProps = true;
946
+ spreadArgs.splice(1, spreadArgs.length - 1, createCallExpression(createIdentifier("_$mergeProps", spreadArgsPosition), spreadArgs.slice(1), spreadArgsPosition));
947
+ }
948
+ } else {
949
+ if (shouldImportSetStyle) currentContext.shouldImportSetStyle = true;
950
+ if (shouldImportSetClassName) currentContext.shouldImportSetClassName = true;
951
+ if (shouldImportSetAttribute) currentContext.shouldImportSetAttribute = true;
952
+ if (shouldImportSetAttributeNS) currentContext.shouldImportSetAttributeNS = true;
953
+ if (shouldImportUseEffect) {
954
+ currentContext.shouldImportUseEffect = true;
955
+ if (effectStmts) effectStmts.push(createReturnStatement(effectParameter, effectPosition));
956
+ }
957
+ }
958
+ if (events) stmts.unshift(...events);
959
+ if (ref) stmts.unshift(...ref);
960
+ return stmts;
961
+ }
962
+ function transformChildren(children, id) {
963
+ const stmts = [];
964
+ let elements = [];
965
+ let textContent;
966
+ let textPosition;
967
+ let elementsPosition;
968
+ for (let i = 0; i < children.length; ++i) {
969
+ const childNode = children[i];
970
+ if (childNode.type === "JSXText") {
971
+ const text = childNode.value;
972
+ if (isBlankLine(text)) continue;
973
+ if (textContent) textContent = `${textContent}${text}`;
974
+ else {
975
+ textContent = text;
976
+ textPosition = copyPosition(childNode);
977
+ elementsPosition ??= textPosition;
978
+ }
979
+ } else if (isJSXEmptyExpression(childNode)) continue;
980
+ else if (childNode.type === "JSXFragment") children.splice(i--, 1, ...childNode.children);
981
+ else {
982
+ const childPosition = copyPosition(childNode);
983
+ let expression;
984
+ if (textContent) {
985
+ elements.push(createLiteral(decodeText(textContent), textPosition));
986
+ textContent = textPosition = void 0;
987
+ }
988
+ if (childNode.type === "JSXElement") {
989
+ const childStmts = transformElement(childNode);
990
+ if (childStmts.length > 1) {
991
+ const stmt = childStmts[0];
992
+ elements.push(stmt.declarations[0].id);
993
+ elementsPosition ??= childPosition;
994
+ stmts.push(...childStmts);
995
+ continue;
996
+ } else if (childStmts[0].type === "VariableDeclaration") {
997
+ elements.push(childStmts[0].declarations[0].init);
998
+ elementsPosition ??= childPosition;
999
+ continue;
1000
+ } else expression = childStmts[0].expression;
1001
+ } else {
1002
+ expression = childNode.expression;
1003
+ if (isBareIdentifierCall(expression)) expression = expression.callee;
1004
+ else if (isDynamicExpression(expression)) expression = createArrowFunctionExpression(expression, copyPosition(expression));
1005
+ }
1006
+ if (elements.length) {
1007
+ stmts.push(createExpressionStatement(createCallExpression(createMemberExpression(id, createIdentifier("append", elementsPosition), false, elementsPosition), elements, elementsPosition), elementsPosition));
1008
+ elements = [];
1009
+ elementsPosition = void 0;
1010
+ }
1011
+ currentContext.shouldImportInsert = true;
1012
+ stmts.push(createExpressionStatement(createCallExpression(createIdentifier("_$insert", childPosition), [id, expression], childPosition), childPosition));
1013
+ }
1014
+ }
1015
+ if (textContent) elements.push(createLiteral(decodeText(textContent), textPosition));
1016
+ if (elements.length) stmts.push(createExpressionStatement(createCallExpression(createMemberExpression(id, createIdentifier("append", elementsPosition), false, elementsPosition), elements, elementsPosition), elementsPosition));
1017
+ return stmts;
1018
+ }
1019
+ function transformProperties(attrs, children, position) {
1020
+ const args = [];
1021
+ const propertyNameCache = new Set(["children"]);
1022
+ let shouldImportMergeProps = false;
1023
+ let properties = [];
1024
+ let objectPosition;
1025
+ let argsPosition;
1026
+ for (let i = 0; i < attrs.length; ++i) {
1027
+ const attr = attrs[i];
1028
+ const propertyPosition = copyPosition(attr);
1029
+ if (attr.type === "JSXAttribute") {
1030
+ const propertyName = getAttributeName(attr.name);
1031
+ if (propertyNameCache.has(propertyName)) continue;
1032
+ let value;
1033
+ let isDynamicValue = false;
1034
+ const propertyNamePosition = copyPosition(attr.name);
1035
+ propertyNameCache.add(propertyName);
1036
+ if (!attr.value) value = createLiteral(true, propertyNamePosition);
1037
+ else if (attr.value.type === "Literal") value = attr.value;
1038
+ else if (attr.value.type === "JSXExpressionContainer") {
1039
+ const expression = attr.value.expression;
1040
+ if (propertyName === "ref") {
1041
+ if (matchesType(expression, isRightValue)) {
1042
+ const refId = createIdentifier(getUniqueId("ref", "refId"), propertyNamePosition);
1043
+ const argument = createIdentifier(getUniqueId("r"), copyPosition(expression));
1044
+ const binaryExpression = createBinaryExpression(createUnaryExpression(refId, propertyPosition), createLiteral("function", propertyPosition), "===", propertyPosition);
1045
+ const callExpression = createCallExpression(refId, [argument], propertyPosition);
1046
+ objectPosition ??= propertyPosition;
1047
+ properties.push(createProperty(createIdentifier(propertyName, propertyNamePosition), createFunctionExpression([createVariableDeclaration(refId, expression, propertyPosition), createExpressionStatement(isLeftValue(expression) ? createConditionalExpression(binaryExpression, callExpression, createAssignmentExpression(expression, argument, propertyPosition), propertyPosition) : createLogicalExpression(binaryExpression, callExpression, propertyPosition), propertyPosition)], argument), "init", false, true, propertyPosition));
1048
+ } else if (isFunctionExpression(expression)) {
1049
+ objectPosition ??= propertyPosition;
1050
+ properties.push(createProperty(createIdentifier(propertyName, propertyNamePosition), expression, "init", false, false, propertyPosition));
1051
+ }
1052
+ continue;
1053
+ }
1054
+ value = expression;
1055
+ isDynamicValue = isDynamicExpression(value, true);
1056
+ }
1057
+ const isValidPropertyName = isValidIdentifier(propertyName);
1058
+ objectPosition ??= propertyPosition;
1059
+ properties.push(createProperty(isValidPropertyName ? createIdentifier(propertyName, propertyNamePosition) : createLiteral(propertyName, propertyNamePosition), isDynamicValue ? createFunctionExpression([createReturnStatement(value, propertyPosition)]) : value, isDynamicValue ? "get" : "init", !isValidPropertyName, false, propertyPosition));
1060
+ } else {
1061
+ let { argument } = attr;
1062
+ if (properties.length) {
1063
+ args.push(createObjectExpression(properties, objectPosition));
1064
+ properties = [];
1065
+ argsPosition ??= objectPosition;
1066
+ objectPosition = void 0;
1067
+ }
1068
+ if (isDynamicExpression(argument)) {
1069
+ shouldImportMergeProps = true;
1070
+ argument = isBareIdentifierCall(argument) ? argument.callee : createArrowFunctionExpression(argument, copyPosition(argument));
1071
+ }
1072
+ args.push(argument);
1073
+ argsPosition ??= propertyPosition;
1074
+ }
1075
+ }
1076
+ if (children.length) {
1077
+ const childrenPosition = copyPosition(children[0]);
1078
+ const childrenExpression = transformFragment(children, childrenPosition, true);
1079
+ if (childrenExpression) {
1080
+ const hasDynamicChildren = currentContext.hasDynamicChildrenInComponent;
1081
+ properties.push(createProperty(createIdentifier("children", childrenPosition), hasDynamicChildren ? createFunctionExpression([createReturnStatement(childrenExpression, childrenPosition)]) : childrenExpression, hasDynamicChildren ? "get" : "init", false, false, childrenPosition));
1082
+ }
1083
+ currentContext.hasDynamicChildrenInComponent = currentContext.prevHasDynamicChildrenInComponent;
1084
+ }
1085
+ if (properties.length) {
1086
+ args.push(createObjectExpression(properties, objectPosition));
1087
+ argsPosition ??= objectPosition;
1088
+ }
1089
+ if (shouldImportMergeProps || args.length > 1) {
1090
+ currentContext.shouldImportMergeProps = true;
1091
+ return createCallExpression(createIdentifier("_$mergeProps", argsPosition), args, argsPosition);
1092
+ }
1093
+ if (args.length === 1) return args[0];
1094
+ return createObjectExpression(properties, position);
1095
+ }
1096
+ function getAttributeName(node) {
1097
+ if (node.type === "JSXIdentifier") return node.name;
1098
+ const namespace = node.namespace;
1099
+ return `${namespace.name}:${node.name.name}`;
1100
+ }
1101
+ function copyPosition(node) {
1102
+ return {
1103
+ start: node.start,
1104
+ end: node.end,
1105
+ range: node.range,
1106
+ loc: node.loc
1107
+ };
1108
+ }
1109
+ function createExpressionStatement(expression, position) {
1110
+ return {
1111
+ type: "ExpressionStatement",
1112
+ expression,
1113
+ ...position
1114
+ };
1115
+ }
1116
+ function createVariableDeclaration(id, init, position) {
1117
+ return {
1118
+ type: "VariableDeclaration",
1119
+ kind: "const",
1120
+ declarations: [createVariableDeclarator(id, init, position)],
1121
+ ...position
1122
+ };
1123
+ }
1124
+ function createReturnStatement(argument, position) {
1125
+ return {
1126
+ type: "ReturnStatement",
1127
+ argument,
1128
+ ...position
1129
+ };
1130
+ }
1131
+ function createBlockStatement(body, position) {
1132
+ return {
1133
+ type: "BlockStatement",
1134
+ body,
1135
+ ...position
1136
+ };
1137
+ }
1138
+ function createArrowFunctionExpression(body, position) {
1139
+ return {
1140
+ type: "ArrowFunctionExpression",
1141
+ params: [],
1142
+ body,
1143
+ async: false,
1144
+ generator: false,
1145
+ expression: body.type !== "BlockStatement",
1146
+ ...position
1147
+ };
1148
+ }
1149
+ function createFunctionExpression(body, parameter) {
1150
+ const functionPosition = copyPosition(body[0]);
1151
+ const FunctionExpression = {
1152
+ type: "FunctionExpression",
1153
+ params: parameter ? [parameter] : [],
1154
+ body: createBlockStatement(body, functionPosition),
1155
+ async: false,
1156
+ generator: false,
1157
+ id: null,
1158
+ ...functionPosition
1159
+ };
1160
+ currentContext.generatedFunctions.add(FunctionExpression);
1161
+ return FunctionExpression;
1162
+ }
1163
+ function createCallExpression(callee, args, position) {
1164
+ return {
1165
+ type: "CallExpression",
1166
+ callee,
1167
+ arguments: args,
1168
+ optional: false,
1169
+ ...position
1170
+ };
1171
+ }
1172
+ function createMemberExpression(object, property, computed, position) {
1173
+ return {
1174
+ type: "MemberExpression",
1175
+ object,
1176
+ property,
1177
+ computed,
1178
+ optional: false,
1179
+ ...position
1180
+ };
1181
+ }
1182
+ function createProperty(key, value, kind, computed, method, position) {
1183
+ return {
1184
+ type: "Property",
1185
+ key,
1186
+ value,
1187
+ kind,
1188
+ computed,
1189
+ method,
1190
+ shorthand: false,
1191
+ ...position
1192
+ };
1193
+ }
1194
+ function createImportSpecifier(local, imported, position) {
1195
+ return {
1196
+ type: "ImportSpecifier",
1197
+ local: createIdentifier(local, position),
1198
+ imported: createIdentifier(imported, position),
1199
+ ...position
1200
+ };
1201
+ }
1202
+ function createObjectExpression(properties, position) {
1203
+ return {
1204
+ type: "ObjectExpression",
1205
+ properties,
1206
+ ...position
1207
+ };
1208
+ }
1209
+ function createArrayExpression(elements, position) {
1210
+ return {
1211
+ type: "ArrayExpression",
1212
+ elements,
1213
+ ...position
1214
+ };
1215
+ }
1216
+ function createAssignmentExpression(left, right, position) {
1217
+ return {
1218
+ type: "AssignmentExpression",
1219
+ left,
1220
+ right,
1221
+ operator: "=",
1222
+ ...position
1223
+ };
1224
+ }
1225
+ function createBinaryExpression(left, right, operator, position) {
1226
+ return {
1227
+ type: "BinaryExpression",
1228
+ left,
1229
+ right,
1230
+ operator,
1231
+ ...position
1232
+ };
1233
+ }
1234
+ function createLogicalExpression(left, right, position) {
1235
+ return {
1236
+ type: "LogicalExpression",
1237
+ left,
1238
+ right,
1239
+ operator: "&&",
1240
+ ...position
1241
+ };
1242
+ }
1243
+ function createConditionalExpression(test, consequent, alternate, position) {
1244
+ return {
1245
+ type: "ConditionalExpression",
1246
+ test,
1247
+ consequent,
1248
+ alternate,
1249
+ ...position
1250
+ };
1251
+ }
1252
+ function createUnaryExpression(argument, position) {
1253
+ return {
1254
+ type: "UnaryExpression",
1255
+ operator: "typeof",
1256
+ argument,
1257
+ prefix: true,
1258
+ ...position
1259
+ };
1260
+ }
1261
+ function createVariableDeclarator(id, init, position) {
1262
+ return {
1263
+ type: "VariableDeclarator",
1264
+ id,
1265
+ init,
1266
+ ...position
1267
+ };
1268
+ }
1269
+ function createIdentifier(name, position) {
1270
+ return {
1271
+ type: "Identifier",
1272
+ name,
1273
+ ...position
1274
+ };
1275
+ }
1276
+ function createLiteral(value, position) {
1277
+ return {
1278
+ type: "Literal",
1279
+ value,
1280
+ raw: JSON.stringify(value),
1281
+ ...position
1282
+ };
1283
+ }
1284
+ function createThisExpression(position) {
1285
+ return {
1286
+ type: "ThisExpression",
1287
+ ...position
1288
+ };
1289
+ }
1290
+ function getUniqueId(prefix, key) {
1291
+ let id;
1292
+ if (currentContext[key] != null && currentContext[key]++) id = currentContext[key];
1293
+ else if (key > 1) id = key;
1294
+ else id = "";
1295
+ return `_${prefix}$${id}`;
1296
+ }
1297
+ function isBlankLine(text) {
1298
+ return !NON_BLANK_LINE_REGEX.test(text);
1299
+ }
1300
+ function decodeText(text) {
1301
+ return (0, entities.decodeHTML)(text.replaceAll(EDGE_SPACE_REGEX, "").replaceAll(SPACE_REGEX, " "));
1302
+ }
1303
+ function isValidIdentifier(name) {
1304
+ return IDENTIFIER_REGEX.test(name) && !keywords.has(name);
1305
+ }
1306
+ function matchesType(node, predicate) {
1307
+ if (predicate(node)) return true;
1308
+ if (node.type === "LogicalExpression") return predicate(node.left) || predicate(node.right);
1309
+ if (node.type === "ConditionalExpression") return predicate(node.consequent) || predicate(node.alternate);
1310
+ if (node.type === "AssignmentExpression") return predicate(node.right);
1311
+ if (node.type === "AwaitExpression") return predicate(node.argument);
1312
+ if (node.type === "YieldExpression" && node.argument) return predicate(node.argument);
1313
+ if (node.type === "SequenceExpression") return predicate(node.expressions.at(-1));
1314
+ return false;
1315
+ }
1316
+ function isListener(node) {
1317
+ return isFunctionExpression(node) || isRightValue(node);
1318
+ }
1319
+ function isStylesheet(node) {
1320
+ return node.type === "ObjectExpression" || isRightValue(node);
1321
+ }
1322
+ function isRightValue(node) {
1323
+ return isLeftValue(node) || node.type === "CallExpression" || node.type === "ChainExpression" || node.type === "JSXElement" || node.type === "JSXFragment" || node.type === "ThisExpression" || node.type === "NewExpression" || node.type === "TaggedTemplateExpression" || node.type === "ImportExpression" || node.type === "MetaProperty";
1324
+ }
1325
+ function isLeftValue(node) {
1326
+ return node.type === "Identifier" || node.type === "MemberExpression";
1327
+ }
1328
+ function isFunctionExpression(node) {
1329
+ return node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression";
1330
+ }
1331
+ function isBareIdentifierCall(node) {
1332
+ return node.type === "CallExpression" && node.callee.type === "Identifier" && node.arguments.length === 0;
1333
+ }
1334
+ function isJSXEmptyExpression(node) {
1335
+ return node.type === "JSXEmptyExpression" || (node.type === "JSXExpressionContainer" || node.type === "JSXSpreadChild") && node.expression.type === "JSXEmptyExpression";
1336
+ }
1337
+ function isDynamicExpression(node, checkTags) {
1338
+ let isDynamic = false;
1339
+ visit(node, {
1340
+ ArrowFunctionExpression() {
1341
+ this.skip();
1342
+ },
1343
+ FunctionExpression() {
1344
+ this.skip();
1345
+ },
1346
+ CallExpression() {
1347
+ isDynamic = true;
1348
+ this.break();
1349
+ },
1350
+ MemberExpression() {
1351
+ isDynamic = true;
1352
+ this.break();
1353
+ },
1354
+ ChainExpression() {
1355
+ isDynamic = true;
1356
+ this.break();
1357
+ },
1358
+ JSXElement() {
1359
+ if (checkTags) {
1360
+ isDynamic = true;
1361
+ this.break();
1362
+ }
1363
+ },
1364
+ JSXFragment(node$1) {
1365
+ if (checkTags && node$1.children.length) {
1366
+ isDynamic = true;
1367
+ this.break();
1368
+ }
1369
+ }
1370
+ });
1371
+ return isDynamic;
1372
+ }
1373
+
1374
+ //#endregion
1375
+ exports.compile = compile