@zeus-js/compiler 0.1.0-alpha.1

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,3920 @@
1
+ /**
2
+ * compiler vundefined
3
+ * (c) 2025 baicie
4
+ * Released under the MIT License.
5
+ **/
6
+ import * as SyntaxJSX from '@babel/plugin-syntax-jsx';
7
+ import * as t from '@babel/types';
8
+ import { addNamed } from '@babel/helper-module-imports';
9
+ import { decode } from 'html-entities';
10
+ import { parseFragment, parse, serialize } from 'parse5';
11
+
12
+ const voidElements = [
13
+ "area",
14
+ "base",
15
+ "br",
16
+ "col",
17
+ "embed",
18
+ "hr",
19
+ "img",
20
+ "input",
21
+ "keygen",
22
+ "link",
23
+ "menuitem",
24
+ "meta",
25
+ "param",
26
+ "source",
27
+ "track",
28
+ "wbr"
29
+ ];
30
+
31
+ const reservedNameSpaces = /* @__PURE__ */ new Set([
32
+ "class",
33
+ "on",
34
+ "oncapture",
35
+ "style",
36
+ "use",
37
+ "prop",
38
+ "attr",
39
+ "bool"
40
+ ]);
41
+ const nonSpreadNameSpaces = /* @__PURE__ */ new Set([
42
+ "class",
43
+ "style",
44
+ "use",
45
+ "prop",
46
+ "attr",
47
+ "bool"
48
+ ]);
49
+ function getConfig(path) {
50
+ var _a, _b;
51
+ return (_b = (_a = path.hub.file) == null ? void 0 : _a.metadata.config) != null ? _b : {};
52
+ }
53
+ const getRendererConfig = (path, renderer) => {
54
+ var _a, _b;
55
+ const config = getConfig(path);
56
+ return (_b = (_a = config == null ? void 0 : config.renderers) == null ? void 0 : _a.find((r) => r.name === renderer)) != null ? _b : config;
57
+ };
58
+ function registerImportMethod(path, name, moduleName) {
59
+ const program = path.scope.getProgramParent();
60
+ const imports = program.data.imports || (program.data.imports = /* @__PURE__ */ new Map());
61
+ moduleName = moduleName || getConfig(path).moduleName;
62
+ const key = `${moduleName}:${name}`;
63
+ if (!imports.has(key)) {
64
+ const id = addNamed(path, name, moduleName, {
65
+ nameHint: `_$${name}`
66
+ });
67
+ imports.set(key, id);
68
+ return id;
69
+ } else {
70
+ const id = imports.get(key);
71
+ return t.cloneNode(id);
72
+ }
73
+ }
74
+ function jsxElementNameToString(node) {
75
+ if (t.isJSXMemberExpression(node)) {
76
+ return `${jsxElementNameToString(node.object)}.${node.property.name}`;
77
+ }
78
+ if (t.isJSXIdentifier(node) || t.isIdentifier(node)) {
79
+ return node.name;
80
+ }
81
+ return `${node.namespace.name}:${node.name.name}`;
82
+ }
83
+ function getTagName(tag) {
84
+ const jsxName = tag.openingElement.name;
85
+ return jsxElementNameToString(jsxName);
86
+ }
87
+ function isComponent(tagName) {
88
+ return tagName[0] && tagName[0].toLowerCase() !== tagName[0] || tagName.includes(".") || /[^a-zA-Z]/.test(tagName[0]);
89
+ }
90
+ function hasStaticMarker(object, path) {
91
+ if (!object) return false;
92
+ if (object.leadingComments && object.leadingComments[0] && object.leadingComments[0].value.trim() === getConfig(path).staticMarker)
93
+ return true;
94
+ if (object.expression) return hasStaticMarker(object.expression, path);
95
+ }
96
+ function isDynamic(path, {
97
+ checkMember,
98
+ checkTags,
99
+ checkCallExpressions = true,
100
+ native
101
+ }) {
102
+ const config = getConfig(path);
103
+ if (config.generate === "ssr" && native) {
104
+ checkMember = false;
105
+ checkCallExpressions = false;
106
+ }
107
+ const expr = path.node;
108
+ if (t.isFunction(expr)) return false;
109
+ if (expr.leadingComments && expr.leadingComments[0] && expr.leadingComments[0].value.trim() === config.staticMarker) {
110
+ return false;
111
+ }
112
+ if (checkCallExpressions && (t.isCallExpression(expr) || t.isOptionalCallExpression(expr) || t.isTaggedTemplateExpression(expr))) {
113
+ return true;
114
+ }
115
+ if (checkMember && t.isMemberExpression(expr)) {
116
+ const object = path.get("object").node;
117
+ if (t.isIdentifier(object) && (!expr.computed || !isDynamic(path.get("property"), {
118
+ checkMember,
119
+ checkTags,
120
+ checkCallExpressions,
121
+ native
122
+ }))) {
123
+ const binding = path.scope.getBinding(object.name);
124
+ if (binding && binding.path.isImportNamespaceSpecifier()) {
125
+ return false;
126
+ }
127
+ }
128
+ return true;
129
+ }
130
+ if (checkMember && (t.isOptionalMemberExpression(expr) || t.isSpreadElement(expr) || t.isBinaryExpression(expr) && expr.operator === "in")) {
131
+ return true;
132
+ }
133
+ if (checkTags && (t.isJSXElement(expr) || t.isJSXFragment(expr) && expr.children.length)) {
134
+ return true;
135
+ }
136
+ let dynamic;
137
+ path.traverse({
138
+ Function(p) {
139
+ if (t.isObjectMethod(p.node) && p.node.computed) {
140
+ dynamic = isDynamic(p.get("key"), {
141
+ checkMember,
142
+ checkTags,
143
+ checkCallExpressions,
144
+ native
145
+ });
146
+ }
147
+ p.skip();
148
+ },
149
+ CallExpression(p) {
150
+ checkCallExpressions && (dynamic = true) && p.stop();
151
+ },
152
+ OptionalCallExpression(p) {
153
+ checkCallExpressions && (dynamic = true) && p.stop();
154
+ },
155
+ MemberExpression(p) {
156
+ checkMember && (dynamic = true) && p.stop();
157
+ },
158
+ OptionalMemberExpression(p) {
159
+ checkMember && (dynamic = true) && p.stop();
160
+ },
161
+ SpreadElement(p) {
162
+ checkMember && (dynamic = true) && p.stop();
163
+ },
164
+ BinaryExpression(p) {
165
+ checkMember && p.node.operator === "in" && (dynamic = true) && p.stop();
166
+ },
167
+ JSXElement(p) {
168
+ checkTags ? (dynamic = true) && p.stop() : p.skip();
169
+ },
170
+ JSXFragment(p) {
171
+ checkTags && p.node.children.length ? (dynamic = true) && p.stop() : p.skip();
172
+ }
173
+ });
174
+ return dynamic;
175
+ }
176
+ function getStaticExpression(path) {
177
+ const node = path.node;
178
+ let value, type;
179
+ return t.isJSXExpressionContainer(node) && t.isJSXElement(path.parent) && !isComponent(getTagName(path.parent)) && !t.isSequenceExpression(node.expression) && (value = path.get("expression").evaluate().value) !== void 0 && ((type = typeof value) === "string" || type === "number") && value;
180
+ }
181
+ function filterChildren(children) {
182
+ return children.filter(
183
+ ({ node: child }) => !(t.isJSXExpressionContainer(child) && t.isJSXEmptyExpression(child.expression)) && (!t.isJSXText(child) || !/^[\r\n]\s*$/.test(child.extra.raw))
184
+ );
185
+ }
186
+ function checkLength(children) {
187
+ let i = 0;
188
+ children.forEach((path) => {
189
+ const child = path.node;
190
+ !(t.isJSXExpressionContainer(child) && t.isJSXEmptyExpression(child.expression)) && (!t.isJSXText(child) || !/^\s*$/.test(child.extra.raw) || /^ *$/.test(child.extra.raw)) && i++;
191
+ });
192
+ return i > 1;
193
+ }
194
+ function trimWhitespace(text) {
195
+ text = text.replace(/\r/g, "");
196
+ if (/\n/g.test(text)) {
197
+ text = text.split("\n").map((t2, i) => i ? t2.replace(/^\s*/g, "") : t2).filter((s) => !/^\s*$/.test(s)).join(" ");
198
+ }
199
+ return text.replace(/\s+/g, " ");
200
+ }
201
+ function toEventName(name) {
202
+ return name.slice(2).toLowerCase();
203
+ }
204
+ function toPropertyName(name) {
205
+ return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
206
+ }
207
+ function wrappedByText(list, startIndex) {
208
+ let index = startIndex, wrapped;
209
+ while (--index >= 0) {
210
+ const node = list[index];
211
+ if (!node) continue;
212
+ if (node.text) {
213
+ wrapped = true;
214
+ break;
215
+ }
216
+ if (node.id) return false;
217
+ }
218
+ if (!wrapped) return false;
219
+ index = startIndex;
220
+ while (++index < list.length) {
221
+ const node = list[index];
222
+ if (!node) continue;
223
+ if (node.text) return true;
224
+ if (node.id) return false;
225
+ }
226
+ return false;
227
+ }
228
+ function transformCondition(path, inline, deep) {
229
+ const config = getConfig(path);
230
+ const expr = path.node;
231
+ const memo = registerImportMethod(path, config.memoWrapper);
232
+ let dTest = false;
233
+ let cond;
234
+ let id;
235
+ if (t.isConditionalExpression(expr) && (isDynamic(path.get("consequent"), {
236
+ checkTags: true,
237
+ checkMember: true
238
+ }) || isDynamic(path.get("alternate"), { checkTags: true, checkMember: true }))) {
239
+ dTest = isDynamic(path.get("test"), { checkMember: true });
240
+ if (dTest) {
241
+ cond = expr.test;
242
+ if (!t.isBinaryExpression(cond)) {
243
+ cond = t.unaryExpression("!", t.unaryExpression("!", cond, true), true);
244
+ }
245
+ id = inline ? t.callExpression(memo, [t.arrowFunctionExpression([], cond)]) : path.scope.generateUidIdentifier("_c$");
246
+ expr.test = t.callExpression(id, []);
247
+ if (t.isConditionalExpression(expr.consequent) || t.isLogicalExpression(expr.consequent)) {
248
+ expr.consequent = transformCondition(
249
+ path.get("consequent"),
250
+ true,
251
+ true
252
+ );
253
+ }
254
+ if (t.isConditionalExpression(expr.alternate) || t.isLogicalExpression(expr.alternate)) {
255
+ expr.alternate = transformCondition(
256
+ path.get("alternate"),
257
+ true,
258
+ true
259
+ );
260
+ }
261
+ }
262
+ } else if (t.isLogicalExpression(expr)) {
263
+ let nextPath = path;
264
+ while (nextPath.node.operator !== "&&" && t.isLogicalExpression(nextPath.node.left)) {
265
+ nextPath = nextPath.get("left");
266
+ }
267
+ if (nextPath.node.operator === "&&" && isDynamic(nextPath.get("right"), { checkTags: true, checkMember: true })) {
268
+ dTest = isDynamic(nextPath.get("left"), { checkMember: true });
269
+ if (dTest) {
270
+ cond = nextPath.node.left;
271
+ if (!t.isBinaryExpression(cond)) {
272
+ cond = t.unaryExpression(
273
+ "!",
274
+ t.unaryExpression("!", cond, true),
275
+ true
276
+ );
277
+ }
278
+ id = inline ? t.callExpression(memo, [t.arrowFunctionExpression([], cond)]) : path.scope.generateUidIdentifier("_c$");
279
+ nextPath.node.left = t.callExpression(id, []);
280
+ }
281
+ }
282
+ }
283
+ if (dTest && !inline && cond && id) {
284
+ const statements = [
285
+ t.variableDeclaration("var", [
286
+ t.variableDeclarator(
287
+ id,
288
+ config.memoWrapper ? t.callExpression(memo, [t.arrowFunctionExpression([], cond)]) : t.arrowFunctionExpression([], cond)
289
+ )
290
+ ]),
291
+ t.expressionStatement(t.arrowFunctionExpression([], expr))
292
+ ];
293
+ return deep ? t.callExpression(
294
+ t.arrowFunctionExpression(
295
+ [],
296
+ t.blockStatement([
297
+ statements[0],
298
+ t.returnStatement(
299
+ statements[1].expression
300
+ )
301
+ ])
302
+ ),
303
+ []
304
+ ) : statements;
305
+ }
306
+ return deep ? expr : t.arrowFunctionExpression([], expr);
307
+ }
308
+ function escapeHTML(s, attr) {
309
+ if (typeof s !== "string") return s;
310
+ const delim = attr ? '"' : "<";
311
+ const escDelim = attr ? "&quot;" : "&lt;";
312
+ let iDelim = s.indexOf(delim);
313
+ let iAmp = s.indexOf("&");
314
+ if (iDelim < 0 && iAmp < 0) return s;
315
+ let left = 0, out = "";
316
+ while (iDelim >= 0 && iAmp >= 0) {
317
+ if (iDelim < iAmp) {
318
+ if (left < iDelim) out += s.substring(left, iDelim);
319
+ out += escDelim;
320
+ left = iDelim + 1;
321
+ iDelim = s.indexOf(delim, left);
322
+ } else {
323
+ if (left < iAmp) out += s.substring(left, iAmp);
324
+ out += "&amp;";
325
+ left = iAmp + 1;
326
+ iAmp = s.indexOf("&", left);
327
+ }
328
+ }
329
+ if (iDelim >= 0) {
330
+ do {
331
+ if (left < iDelim) out += s.substring(left, iDelim);
332
+ out += escDelim;
333
+ left = iDelim + 1;
334
+ iDelim = s.indexOf(delim, left);
335
+ } while (iDelim >= 0);
336
+ } else {
337
+ while (iAmp >= 0) {
338
+ if (left < iAmp) out += s.substring(left, iAmp);
339
+ out += "&amp;";
340
+ left = iAmp + 1;
341
+ iAmp = s.indexOf("&", left);
342
+ }
343
+ }
344
+ return left < s.length ? out + s.substring(left) : out;
345
+ }
346
+ function convertJSXIdentifier(node) {
347
+ if (t.isJSXIdentifier(node)) {
348
+ if (t.isValidIdentifier(node.name)) {
349
+ node.type = "Identifier";
350
+ } else {
351
+ return t.stringLiteral(node.name);
352
+ }
353
+ } else if (t.isJSXMemberExpression(node)) {
354
+ return t.memberExpression(
355
+ convertJSXIdentifier(node.object),
356
+ convertJSXIdentifier(node.property)
357
+ );
358
+ } else if (t.isJSXNamespacedName(node)) {
359
+ return t.stringLiteral(`${node.namespace.name}:${node.name.name}`);
360
+ }
361
+ return node;
362
+ }
363
+ function canNativeSpread(key, { checkNameSpaces } = {}) {
364
+ if (checkNameSpaces && key.includes(":") && nonSpreadNameSpaces.has(key.split(":")[0]))
365
+ return false;
366
+ if (key === "ref") return false;
367
+ return true;
368
+ }
369
+ const chars = "etaoinshrdlucwmfygpbTAOISWCBvkxjqzPHFMDRELNGUKVYJQZX_$";
370
+ const base = chars.length;
371
+ function getNumberedId(num) {
372
+ let out = "";
373
+ do {
374
+ const digit = num % base;
375
+ num = Math.floor(num / base);
376
+ out = chars[digit] + out;
377
+ } while (num !== 0);
378
+ return out;
379
+ }
380
+ function escapeStringForTemplate(str) {
381
+ return str.replace(
382
+ /[{\\`\n\t\b\f\v\r\u2028\u2029]/g,
383
+ (ch) => templateEscapes.get(ch)
384
+ );
385
+ }
386
+ const templateEscapes = /* @__PURE__ */ new Map([
387
+ ["{", "\\{"],
388
+ ["`", "\\`"],
389
+ ["\\", "\\\\"],
390
+ ["\n", "\\n"],
391
+ [" ", "\\t"],
392
+ ["\b", "\\b"],
393
+ ["\f", "\\f"],
394
+ ["\v", "\\v"],
395
+ ["\r", "\\r"],
396
+ ["\u2028", "\\u2028"],
397
+ ["\u2029", "\\u2029"]
398
+ ]);
399
+ function isJSXElementPath(path) {
400
+ return t.isJSXElement(path.node);
401
+ }
402
+
403
+ const booleans = [
404
+ "allowfullscreen",
405
+ "async",
406
+ "alpha",
407
+ // HTMLInputElement
408
+ "autofocus",
409
+ // HTMLElement prop
410
+ "autoplay",
411
+ "checked",
412
+ "controls",
413
+ "default",
414
+ "disabled",
415
+ "formnovalidate",
416
+ "hidden",
417
+ // HTMLElement prop - not a boolean
418
+ "indeterminate",
419
+ "inert",
420
+ // HTMLElement prop
421
+ "ismap",
422
+ "loop",
423
+ "multiple",
424
+ "muted",
425
+ "nomodule",
426
+ "novalidate",
427
+ "open",
428
+ "playsinline",
429
+ "readonly",
430
+ "required",
431
+ "reversed",
432
+ "seamless",
433
+ // HTMLIframeElement - non-standard
434
+ "selected",
435
+ "adauctionheaders",
436
+ // experimental
437
+ "browsingtopics",
438
+ // experimental
439
+ "credentialless",
440
+ // experimental
441
+ "defaultchecked",
442
+ "defaultmuted",
443
+ "defaultselected",
444
+ "defer",
445
+ "disablepictureinpicture",
446
+ "disableremoteplayback",
447
+ "preservespitch",
448
+ // appears as camelCase property only (not as attribute)
449
+ "shadowrootclonable",
450
+ "shadowrootcustomelementregistry",
451
+ // experimental - doesnt seem to have a prop yet
452
+ "shadowrootdelegatesfocus",
453
+ "shadowrootserializable",
454
+ // experimental
455
+ "sharedstoragewritable"
456
+ // experimental
457
+ ];
458
+ const InlineElements = [
459
+ "a",
460
+ "abbr",
461
+ "acronym",
462
+ "b",
463
+ "bdi",
464
+ "bdo",
465
+ "big",
466
+ "br",
467
+ "button",
468
+ "canvas",
469
+ "cite",
470
+ "code",
471
+ "data",
472
+ "datalist",
473
+ "del",
474
+ "dfn",
475
+ "em",
476
+ "embed",
477
+ "i",
478
+ "iframe",
479
+ "img",
480
+ "input",
481
+ "ins",
482
+ "kbd",
483
+ "label",
484
+ "map",
485
+ "mark",
486
+ "meter",
487
+ "noscript",
488
+ "object",
489
+ "output",
490
+ "picture",
491
+ "progress",
492
+ "q",
493
+ "ruby",
494
+ "s",
495
+ "samp",
496
+ "script",
497
+ "select",
498
+ "slot",
499
+ "small",
500
+ "span",
501
+ "strong",
502
+ "sub",
503
+ "sup",
504
+ "svg",
505
+ "template",
506
+ "textarea",
507
+ "time",
508
+ "u",
509
+ "tt",
510
+ "var",
511
+ "video"
512
+ ];
513
+ const BlockElements = [
514
+ "address",
515
+ "article",
516
+ "aside",
517
+ "blockquote",
518
+ "dd",
519
+ "details",
520
+ "dialog",
521
+ "div",
522
+ "dl",
523
+ "dt",
524
+ "fieldset",
525
+ "figcaption",
526
+ "figure",
527
+ "footer",
528
+ "form",
529
+ "h1",
530
+ "h2",
531
+ "h3",
532
+ "h4",
533
+ "h5",
534
+ "h6",
535
+ "header",
536
+ "hgroup",
537
+ "hr",
538
+ "li",
539
+ "main",
540
+ "menu",
541
+ "nav",
542
+ "ol",
543
+ "p",
544
+ "pre",
545
+ "section",
546
+ "table",
547
+ "ul"
548
+ ];
549
+ const BooleanAttributes = new Set(booleans);
550
+ const Aliases = Object.assign(
551
+ /* @__PURE__ */ Object.create(null),
552
+ {
553
+ className: "class",
554
+ htmlFor: "for"
555
+ }
556
+ );
557
+ const ChildProperties = /* @__PURE__ */ new Set([
558
+ "innerHTML",
559
+ "textContent",
560
+ "innerText",
561
+ "children"
562
+ ]);
563
+ const DelegatedEvents = /* @__PURE__ */ new Set([
564
+ "beforeinput",
565
+ "click",
566
+ "dblclick",
567
+ "contextmenu",
568
+ "focusin",
569
+ "focusout",
570
+ "input",
571
+ "keydown",
572
+ "keyup",
573
+ "mousedown",
574
+ "mousemove",
575
+ "mouseout",
576
+ "mouseover",
577
+ "mouseup",
578
+ "pointerdown",
579
+ "pointermove",
580
+ "pointerout",
581
+ "pointerover",
582
+ "pointerup",
583
+ "touchend",
584
+ "touchmove",
585
+ "touchstart"
586
+ ]);
587
+ const Properties = /* @__PURE__ */ new Set([
588
+ // locked to properties
589
+ "className",
590
+ "value",
591
+ // booleans with camelCase
592
+ "readOnly",
593
+ "noValidate",
594
+ "formNoValidate",
595
+ "isMap",
596
+ "noModule",
597
+ "playsInline",
598
+ "adAuctionHeaders",
599
+ // experimental
600
+ "allowFullscreen",
601
+ "browsingTopics",
602
+ // experimental
603
+ "defaultChecked",
604
+ "defaultMuted",
605
+ "defaultSelected",
606
+ "disablePictureInPicture",
607
+ "disableRemotePlayback",
608
+ "preservesPitch",
609
+ "shadowRootClonable",
610
+ "shadowRootCustomElementRegistry",
611
+ // experimental
612
+ "shadowRootDelegatesFocus",
613
+ "shadowRootSerializable",
614
+ // experimental
615
+ "sharedStorageWritable",
616
+ // experimental
617
+ ...booleans
618
+ ]);
619
+ const SVGElements = /* @__PURE__ */ new Set([
620
+ // "a",
621
+ "altGlyph",
622
+ "altGlyphDef",
623
+ "altGlyphItem",
624
+ "animate",
625
+ "animateColor",
626
+ "animateMotion",
627
+ "animateTransform",
628
+ "circle",
629
+ "clipPath",
630
+ "color-profile",
631
+ "cursor",
632
+ "defs",
633
+ "desc",
634
+ "ellipse",
635
+ "feBlend",
636
+ "feColorMatrix",
637
+ "feComponentTransfer",
638
+ "feComposite",
639
+ "feConvolveMatrix",
640
+ "feDiffuseLighting",
641
+ "feDisplacementMap",
642
+ "feDistantLight",
643
+ "feDropShadow",
644
+ "feFlood",
645
+ "feFuncA",
646
+ "feFuncB",
647
+ "feFuncG",
648
+ "feFuncR",
649
+ "feGaussianBlur",
650
+ "feImage",
651
+ "feMerge",
652
+ "feMergeNode",
653
+ "feMorphology",
654
+ "feOffset",
655
+ "fePointLight",
656
+ "feSpecularLighting",
657
+ "feSpotLight",
658
+ "feTile",
659
+ "feTurbulence",
660
+ "filter",
661
+ "font",
662
+ "font-face",
663
+ "font-face-format",
664
+ "font-face-name",
665
+ "font-face-src",
666
+ "font-face-uri",
667
+ "foreignObject",
668
+ "g",
669
+ "glyph",
670
+ "glyphRef",
671
+ "hkern",
672
+ "image",
673
+ "line",
674
+ "linearGradient",
675
+ "marker",
676
+ "mask",
677
+ "metadata",
678
+ "missing-glyph",
679
+ "mpath",
680
+ "path",
681
+ "pattern",
682
+ "polygon",
683
+ "polyline",
684
+ "radialGradient",
685
+ "rect",
686
+ // "script",
687
+ "set",
688
+ "stop",
689
+ // "style",
690
+ "svg",
691
+ "switch",
692
+ "symbol",
693
+ "text",
694
+ "textPath",
695
+ // "title",
696
+ "tref",
697
+ "tspan",
698
+ "use",
699
+ "view",
700
+ "vkern"
701
+ ]);
702
+ const SVGNamespace = {
703
+ xlink: "http://www.w3.org/1999/xlink",
704
+ xml: "http://www.w3.org/XML/1998/namespace"
705
+ };
706
+ const PropAliases = Object.assign(/* @__PURE__ */ Object.create(null), {
707
+ // locked to properties
708
+ class: "className",
709
+ // booleans map
710
+ novalidate: {
711
+ $: "noValidate",
712
+ FORM: 1
713
+ },
714
+ formnovalidate: {
715
+ $: "formNoValidate",
716
+ BUTTON: 1,
717
+ INPUT: 1
718
+ },
719
+ ismap: {
720
+ $: "isMap",
721
+ IMG: 1
722
+ },
723
+ nomodule: {
724
+ $: "noModule",
725
+ SCRIPT: 1
726
+ },
727
+ playsinline: {
728
+ $: "playsInline",
729
+ VIDEO: 1
730
+ },
731
+ readonly: {
732
+ $: "readOnly",
733
+ INPUT: 1,
734
+ TEXTAREA: 1
735
+ },
736
+ adauctionheaders: {
737
+ $: "adAuctionHeaders",
738
+ IFRAME: 1
739
+ },
740
+ allowfullscreen: {
741
+ $: "allowFullscreen",
742
+ IFRAME: 1
743
+ },
744
+ browsingtopics: {
745
+ $: "browsingTopics",
746
+ IMG: 1
747
+ },
748
+ defaultchecked: {
749
+ $: "defaultChecked",
750
+ INPUT: 1
751
+ },
752
+ defaultmuted: {
753
+ $: "defaultMuted",
754
+ AUDIO: 1,
755
+ VIDEO: 1
756
+ },
757
+ defaultselected: {
758
+ $: "defaultSelected",
759
+ OPTION: 1
760
+ },
761
+ disablepictureinpicture: {
762
+ $: "disablePictureInPicture",
763
+ VIDEO: 1
764
+ },
765
+ disableremoteplayback: {
766
+ $: "disableRemotePlayback",
767
+ AUDIO: 1,
768
+ VIDEO: 1
769
+ },
770
+ preservespitch: {
771
+ $: "preservesPitch",
772
+ AUDIO: 1,
773
+ VIDEO: 1
774
+ },
775
+ shadowrootclonable: {
776
+ $: "shadowRootClonable",
777
+ TEMPLATE: 1
778
+ },
779
+ shadowrootdelegatesfocus: {
780
+ $: "shadowRootDelegatesFocus",
781
+ TEMPLATE: 1
782
+ },
783
+ shadowrootserializable: {
784
+ $: "shadowRootSerializable",
785
+ TEMPLATE: 1
786
+ },
787
+ sharedstoragewritable: {
788
+ $: "sharedStorageWritable",
789
+ IFRAME: 1,
790
+ IMG: 1
791
+ }
792
+ });
793
+ function getPropAlias(prop, tagName) {
794
+ const a = PropAliases[prop];
795
+ return typeof a === "object" ? a[tagName] ? a["$"] : void 0 : a;
796
+ }
797
+
798
+ const alwaysClose = [
799
+ "title",
800
+ "style",
801
+ "a",
802
+ "strong",
803
+ "small",
804
+ "b",
805
+ "u",
806
+ "i",
807
+ "em",
808
+ "s",
809
+ "code",
810
+ "object",
811
+ "table",
812
+ "button",
813
+ "textarea",
814
+ "select",
815
+ "iframe",
816
+ "script",
817
+ "noscript",
818
+ "template",
819
+ "fieldset"
820
+ ];
821
+ function transformElement$3(path, info) {
822
+ var _a;
823
+ let tagName = getTagName(path.node), config = getConfig(path), wrapSVG = info.topLevel && tagName != "svg" && SVGElements.has(tagName), voidTag = voidElements.indexOf(tagName) > -1, isCustomElement = tagName.indexOf("-") > -1 || path.get("openingElement").get("attributes").some(
824
+ (a) => {
825
+ var _a2, _b, _c;
826
+ return t.isJSXAttribute(a.node) && ((_b = (_a2 = a.node) == null ? void 0 : _a2.name) == null ? void 0 : _b.name) === "is" || ((_c = a.name) == null ? void 0 : _c.name) === "is";
827
+ }
828
+ ), isImportNode = (tagName === "img" || tagName === "iframe") && path.get("openingElement").get("attributes").some((a) => {
829
+ var _a2;
830
+ return t.isJSXAttribute(a.node) && ((_a2 = a.node.name) == null ? void 0 : _a2.name) === "loading";
831
+ }), results = {
832
+ template: `<${tagName}`,
833
+ templateWithClosingTags: `<${tagName}`,
834
+ declarations: [],
835
+ exprs: [],
836
+ dynamics: [],
837
+ postExprs: [],
838
+ isSVG: wrapSVG,
839
+ hasCustomElement: isCustomElement,
840
+ isImportNode,
841
+ tagName,
842
+ renderer: "dom",
843
+ skipTemplate: false
844
+ };
845
+ path.get("openingElement").get("attributes").some((a) => {
846
+ var _a2, _b, _c;
847
+ if (t.isJSXAttribute(a.node) && ((_a2 = a.node.name) == null ? void 0 : _a2.name) === "data-hk") {
848
+ a.remove();
849
+ let filename = "";
850
+ try {
851
+ filename = ((_c = (_b = path.scope.getProgramParent().path.hub.file) == null ? void 0 : _b.opts) == null ? void 0 : _c.filename) || "";
852
+ } catch (e) {
853
+ }
854
+ console.log(
855
+ "\n" + path.buildCodeFrameError(
856
+ `"data-hk" attribute found in template, which could potentially cause hydration miss-matches. Usually happens when copying and pasting Solid SSRed code into JSX. Please remove the attribute from the JSX.
857
+
858
+ ${filename}
859
+ `
860
+ ).toString()
861
+ );
862
+ }
863
+ });
864
+ if (config.hydratable && (tagName === "html" || tagName === "head" || tagName === "body")) {
865
+ results.skipTemplate = true;
866
+ if (tagName === "head" && info.topLevel) {
867
+ const createComponent = registerImportMethod(
868
+ path,
869
+ "createComponent",
870
+ getRendererConfig(path, "dom").moduleName
871
+ );
872
+ const NoHydration = registerImportMethod(
873
+ path,
874
+ "NoHydration",
875
+ getRendererConfig(path, "dom").moduleName
876
+ );
877
+ results.exprs.push(
878
+ t.expressionStatement(
879
+ t.callExpression(createComponent, [
880
+ NoHydration,
881
+ t.objectExpression([])
882
+ ])
883
+ )
884
+ );
885
+ return results;
886
+ }
887
+ }
888
+ if (wrapSVG) {
889
+ results.template = "<svg>" + results.template;
890
+ results.templateWithClosingTags = "<svg>" + results.templateWithClosingTags;
891
+ }
892
+ if (!info.skipId) {
893
+ results.id = path.scope.generateUidIdentifier("el$");
894
+ }
895
+ transformAttributes$2(path, results);
896
+ if (config.contextToCustomElements && (tagName === "slot" || isCustomElement)) {
897
+ contextToCustomElement(path, results);
898
+ }
899
+ results.template += ">";
900
+ results.templateWithClosingTags += ">";
901
+ if (!voidTag) {
902
+ const toBeClosed = !info.lastElement || !config.omitLastClosingTag || info.toBeClosed && (!config.omitNestedClosingTags || info.toBeClosed.has(tagName));
903
+ if (toBeClosed) {
904
+ results.toBeClosed = new Set(info.toBeClosed || alwaysClose);
905
+ results.toBeClosed.add(tagName);
906
+ if (InlineElements.includes(tagName))
907
+ BlockElements.forEach((i) => {
908
+ var _a2;
909
+ return (_a2 = results.toBeClosed) == null ? void 0 : _a2.add(i);
910
+ });
911
+ } else results.toBeClosed = info.toBeClosed;
912
+ if (tagName !== "noscript") transformChildren$2(path, results, config);
913
+ if (toBeClosed) results.template += `</${tagName}>`;
914
+ results.templateWithClosingTags += `</${tagName}>`;
915
+ }
916
+ if (info.topLevel && config.hydratable && results.hasHydratableEvent) {
917
+ let runHydrationEvents = registerImportMethod(
918
+ path,
919
+ "runHydrationEvents",
920
+ getRendererConfig(path, "dom").moduleName
921
+ );
922
+ (_a = results.postExprs) == null ? void 0 : _a.push(
923
+ t.expressionStatement(t.callExpression(runHydrationEvents, []))
924
+ );
925
+ }
926
+ if (wrapSVG) {
927
+ results.template += "</svg>";
928
+ results.templateWithClosingTags += "</svg>";
929
+ }
930
+ return results;
931
+ }
932
+ function setAttr$2(path, elem, name, value, {
933
+ isSVG = false,
934
+ dynamic = false,
935
+ prevId,
936
+ isCE = false,
937
+ tagName
938
+ }) {
939
+ const config = getConfig(path);
940
+ let parts, namespace;
941
+ if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
942
+ name = parts[1];
943
+ namespace = parts[0];
944
+ }
945
+ if (namespace === "style") {
946
+ const setStyleProperty = registerImportMethod(
947
+ path,
948
+ "setStyleProperty",
949
+ getRendererConfig(path, "dom").moduleName
950
+ );
951
+ return t.callExpression(setStyleProperty, [
952
+ elem,
953
+ t.stringLiteral(name),
954
+ t.isAssignmentExpression(value) && t.isIdentifier(value.left) ? value.right : value
955
+ ]);
956
+ }
957
+ if (namespace === "class") {
958
+ return t.callExpression(
959
+ t.memberExpression(
960
+ t.memberExpression(elem, t.identifier("classList")),
961
+ t.identifier("toggle")
962
+ ),
963
+ [
964
+ t.stringLiteral(name),
965
+ dynamic ? value : t.unaryExpression("!", t.unaryExpression("!", value))
966
+ ]
967
+ );
968
+ }
969
+ if (name === "style") {
970
+ return t.callExpression(
971
+ registerImportMethod(
972
+ path,
973
+ "style",
974
+ getRendererConfig(path, "dom").moduleName
975
+ ),
976
+ prevId ? [elem, value, prevId] : [elem, value]
977
+ );
978
+ }
979
+ if (!isSVG && name === "class") {
980
+ return t.callExpression(
981
+ registerImportMethod(
982
+ path,
983
+ "className",
984
+ getRendererConfig(path, "dom").moduleName
985
+ ),
986
+ [elem, value]
987
+ );
988
+ }
989
+ if (name === "classList") {
990
+ return t.callExpression(
991
+ registerImportMethod(
992
+ path,
993
+ "classList",
994
+ getRendererConfig(path, "dom").moduleName
995
+ ),
996
+ prevId ? [elem, value, prevId] : [elem, value]
997
+ );
998
+ }
999
+ if (dynamic && name === "textContent") {
1000
+ if (config.hydratable) {
1001
+ return t.callExpression(registerImportMethod(path, "setProperty"), [
1002
+ elem,
1003
+ t.stringLiteral("data"),
1004
+ value
1005
+ ]);
1006
+ }
1007
+ return t.assignmentExpression(
1008
+ "=",
1009
+ t.memberExpression(elem, t.identifier("data")),
1010
+ value
1011
+ );
1012
+ }
1013
+ if (namespace === "bool") {
1014
+ return t.callExpression(
1015
+ registerImportMethod(
1016
+ path,
1017
+ "setBoolAttribute",
1018
+ getRendererConfig(path, "dom").moduleName
1019
+ ),
1020
+ [elem, t.stringLiteral(name), value]
1021
+ );
1022
+ }
1023
+ const isChildProp = ChildProperties.has(name);
1024
+ const isProp = Properties.has(name);
1025
+ const alias = getPropAlias(name, tagName.toUpperCase());
1026
+ if (namespace !== "attr" && (isChildProp || !isSVG && isProp || isCE || namespace === "prop")) {
1027
+ if (isCE && !isChildProp && !isProp && namespace !== "prop")
1028
+ name = toPropertyName(name);
1029
+ if (config.hydratable && namespace !== "prop") {
1030
+ return t.callExpression(registerImportMethod(path, "setProperty"), [
1031
+ elem,
1032
+ t.stringLiteral(alias || name),
1033
+ value
1034
+ ]);
1035
+ }
1036
+ return t.assignmentExpression(
1037
+ "=",
1038
+ t.memberExpression(elem, t.identifier(alias || name)),
1039
+ value
1040
+ );
1041
+ }
1042
+ let isNameSpaced = name.indexOf(":") > -1;
1043
+ name = Aliases[name] || name;
1044
+ !isSVG && (name = name.toLowerCase());
1045
+ const ns = isNameSpaced && SVGNamespace[name.split(":")[0]];
1046
+ if (ns) {
1047
+ return t.callExpression(
1048
+ registerImportMethod(
1049
+ path,
1050
+ "setAttributeNS",
1051
+ getRendererConfig(path, "dom").moduleName
1052
+ ),
1053
+ [elem, t.stringLiteral(ns), t.stringLiteral(name), value]
1054
+ );
1055
+ } else {
1056
+ return t.callExpression(
1057
+ registerImportMethod(
1058
+ path,
1059
+ "setAttribute",
1060
+ getRendererConfig(path, "dom").moduleName
1061
+ ),
1062
+ [elem, t.stringLiteral(name), value]
1063
+ );
1064
+ }
1065
+ }
1066
+ function detectResolvableEventHandler(attribute, handler) {
1067
+ while (t.isIdentifier(handler)) {
1068
+ const lookup = attribute.scope.getBinding(handler.name);
1069
+ if (lookup) {
1070
+ if (t.isVariableDeclarator(lookup.path.node)) {
1071
+ handler = lookup.path.node.init;
1072
+ } else if (t.isFunctionDeclaration(lookup.path.node)) {
1073
+ return true;
1074
+ } else return false;
1075
+ } else return false;
1076
+ }
1077
+ return t.isFunction(handler);
1078
+ }
1079
+ function transformAttributes$2(path, results) {
1080
+ let elem = results.id, hasHydratableEvent = false, children, spreadExpr, attributes = path.get("openingElement").get("attributes");
1081
+ const tagName = getTagName(path.node), isSVG = SVGElements.has(tagName), isCE = tagName.includes("-") || attributes.some(
1082
+ (a) => {
1083
+ var _a;
1084
+ return t.isJSXAttribute(a.node) && ((_a = a.node.name) == null ? void 0 : _a.name) === "is";
1085
+ }
1086
+ ), hasChildren = path.node.children.length > 0, config = getConfig(path);
1087
+ if (attributes.some((attribute) => t.isJSXSpreadAttribute(attribute.node))) {
1088
+ [attributes, spreadExpr] = processSpreads$1(path, attributes, {
1089
+ elem,
1090
+ isSVG,
1091
+ hasChildren,
1092
+ wrapConditionals: config.wrapConditionals
1093
+ });
1094
+ path.get("openingElement").set(
1095
+ "attributes",
1096
+ attributes.map((a) => a.node)
1097
+ );
1098
+ hasHydratableEvent = true;
1099
+ }
1100
+ attributes = path.get("openingElement").get("attributes");
1101
+ const styleAttributes = attributes.filter(
1102
+ (a) => a.node.name && a.node.name.name === "style"
1103
+ );
1104
+ if (styleAttributes.length > 0) {
1105
+ let inlinedStyle = "";
1106
+ for (let i = 0; i < styleAttributes.length; i++) {
1107
+ const attr = styleAttributes[i];
1108
+ let value = attr.node.value;
1109
+ if (t.isJSXExpressionContainer(value)) {
1110
+ value = value.expression;
1111
+ }
1112
+ if (t.isStringLiteral(value)) {
1113
+ inlinedStyle += `${value.value.replace(/;$/, "")};`;
1114
+ attr.remove();
1115
+ } else if (t.isObjectExpression(value)) {
1116
+ const properties = value.properties;
1117
+ const toRemoveProperty = [];
1118
+ for (const property of properties) {
1119
+ if (t.isObjectProperty(property)) {
1120
+ if (t.isStringLiteral(property.key) && (t.isStringLiteral(property.value) || t.isNumericLiteral(property.value))) {
1121
+ inlinedStyle += `${property.key.value}:${property.value.value};`;
1122
+ toRemoveProperty.push(property);
1123
+ } else if (t.isIdentifier(property.value) && property.value.name === "undefined" || t.isNullLiteral(property.value)) {
1124
+ toRemoveProperty.push(property);
1125
+ }
1126
+ }
1127
+ }
1128
+ for (const remove of toRemoveProperty) {
1129
+ value.properties.splice(value.properties.indexOf(remove), 1);
1130
+ }
1131
+ if (value.properties.length === 0) {
1132
+ attr.remove();
1133
+ }
1134
+ }
1135
+ }
1136
+ if (inlinedStyle !== "") {
1137
+ const styleAttribute2 = t.jsxAttribute(
1138
+ t.jsxIdentifier("style"),
1139
+ t.stringLiteral(inlinedStyle.replace(/;$/, ""))
1140
+ );
1141
+ path.get("openingElement").node.attributes.push(styleAttribute2);
1142
+ }
1143
+ }
1144
+ const styleAttribute = path.get("openingElement").get("attributes").find(
1145
+ (a) => t.isJSXAttribute(a.node) && a.node.name.name === "style" && t.isJSXExpressionContainer(a.node.value) && t.isObjectExpression(a.node.value.expression) && !a.node.value.expression.properties.some((p) => t.isSpreadElement(p))
1146
+ );
1147
+ if (styleAttribute) {
1148
+ let i = 0, leading = styleAttribute.node.value.expression.leadingComments(styleAttribute.node).value.expression.properties.slice().forEach((p, index) => {
1149
+ if (!p.computed) {
1150
+ if (leading) p.value.leadingComments = leading;
1151
+ path.get("openingElement").node.attributes.splice(
1152
+ styleAttribute.key + ++i,
1153
+ 0,
1154
+ t.jsxAttribute(
1155
+ t.jsxNamespacedName(
1156
+ t.jsxIdentifier("style"),
1157
+ t.jsxIdentifier(
1158
+ t.isIdentifier(p.key) ? p.key.name : p.key.value
1159
+ )
1160
+ ),
1161
+ t.jsxExpressionContainer(p.value)
1162
+ )
1163
+ );
1164
+ styleAttribute.node.value.expression.properties.splice(
1165
+ index - i - 1,
1166
+ 1
1167
+ );
1168
+ }
1169
+ });
1170
+ if (!styleAttribute.node.value.expression.properties.length)
1171
+ path.get("openingElement").node.attributes.splice(styleAttribute.key, 1);
1172
+ }
1173
+ attributes = path.get("openingElement").get("attributes");
1174
+ const classListAttribute = attributes.find(
1175
+ (a) => t.isJSXAttribute(a.node) && a.node.name.name === "classList" && t.isJSXExpressionContainer(a.node.value) && t.isObjectExpression(a.node.value.expression) && !a.node.value.expression.properties.some(
1176
+ (p) => t.isSpreadElement(p) || p.computed || t.isStringLiteral(p.key) && (p.key.value.includes(" ") || p.key.value.includes(":"))
1177
+ )
1178
+ );
1179
+ if (classListAttribute) {
1180
+ let i = 0, leading = classListAttribute.node.value.expression.leadingComments, classListProperties = classListAttribute.get("value").get("expression").get("properties");
1181
+ classListProperties.slice().forEach((propPath, index) => {
1182
+ const p = propPath.node;
1183
+ const { confident, value: computed } = propPath.get("value").evaluate();
1184
+ if (leading) p.value.leadingComments = leading;
1185
+ if (!confident) {
1186
+ path.get("openingElement").node.attributes.splice(
1187
+ classListAttribute.key + ++i,
1188
+ 0,
1189
+ t.jsxAttribute(
1190
+ t.jsxNamespacedName(
1191
+ t.jsxIdentifier("class"),
1192
+ t.jsxIdentifier(
1193
+ t.isIdentifier(p.key) ? p.key.name : p.key.value
1194
+ )
1195
+ ),
1196
+ t.jsxExpressionContainer(p.value)
1197
+ )
1198
+ );
1199
+ } else if (computed) {
1200
+ path.get("openingElement").node.attributes.splice(
1201
+ classListAttribute.key + ++i,
1202
+ 0,
1203
+ t.jsxAttribute(
1204
+ t.jsxIdentifier("class"),
1205
+ t.stringLiteral(t.isIdentifier(p.key) ? p.key.name : p.key.value)
1206
+ )
1207
+ );
1208
+ }
1209
+ classListProperties.splice(index - i - 1, 1);
1210
+ });
1211
+ if (!classListProperties.length)
1212
+ path.get("openingElement").node.attributes.splice(classListAttribute.key, 1);
1213
+ }
1214
+ attributes = path.get("openingElement").get("attributes");
1215
+ const classAttributes = attributes.filter(
1216
+ (a) => t.isJSXAttribute(a.node) && (a.node.name.name === "class" || a.node.name.name === "className")
1217
+ );
1218
+ if (classAttributes.length > 1) {
1219
+ const first = classAttributes[0].node, values = [], quasis = [t.templateElement({ raw: "" })];
1220
+ for (let i = 0; i < classAttributes.length; i++) {
1221
+ const attr = classAttributes[i].node, isLast = i === classAttributes.length - 1;
1222
+ if (!t.isJSXExpressionContainer(attr.value)) {
1223
+ const prev = quasis.pop();
1224
+ quasis.push(
1225
+ t.templateElement({
1226
+ raw: (prev ? prev.value.raw : "") + `${attr.value.value}` + (isLast ? "" : " ")
1227
+ })
1228
+ );
1229
+ } else {
1230
+ values.push(
1231
+ t.logicalExpression(
1232
+ "||",
1233
+ attr.value.expression,
1234
+ t.stringLiteral("")
1235
+ )
1236
+ );
1237
+ quasis.push(t.templateElement({ raw: isLast ? "" : " " }));
1238
+ }
1239
+ i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
1240
+ }
1241
+ if (values.length)
1242
+ first.value = t.jsxExpressionContainer(
1243
+ t.templateLiteral(quasis, values)
1244
+ );
1245
+ else first.value = t.stringLiteral(quasis[0].value.raw);
1246
+ }
1247
+ path.get("openingElement").set(
1248
+ "attributes",
1249
+ attributes.map((a) => a.node)
1250
+ );
1251
+ let needsSpacing = true;
1252
+ function inlineAttributeOnTemplate(isSVG2, key, results2, value) {
1253
+ !isSVG2 && (key = key.toLowerCase());
1254
+ results2.template += `${needsSpacing ? " " : ""}${key}`;
1255
+ if (!value) {
1256
+ needsSpacing = true;
1257
+ return;
1258
+ }
1259
+ let text = value.value;
1260
+ if (typeof text === "number") text = String(text);
1261
+ let needsQuoting = !config.omitQuotes;
1262
+ if (key === "style" || key === "class") {
1263
+ text = trimWhitespace(text);
1264
+ if (key === "style") {
1265
+ text = text.replace(/; /g, ";").replace(/: /g, ":");
1266
+ }
1267
+ }
1268
+ if (!text.length) {
1269
+ needsSpacing = true;
1270
+ results2.template += ``;
1271
+ return;
1272
+ }
1273
+ for (let i = 0, len = text.length; i < len; i++) {
1274
+ let char = text[i];
1275
+ if (char === "'" || char === '"' || char === " " || char === " " || char === "\n" || char === "\r" || char === "`" || char === "=" || char === "<" || char === ">") {
1276
+ needsQuoting = true;
1277
+ }
1278
+ }
1279
+ if (needsQuoting) {
1280
+ needsSpacing = false;
1281
+ results2.template += `="${escapeHTML(text, true)}"`;
1282
+ } else {
1283
+ needsSpacing = true;
1284
+ results2.template += `=${escapeHTML(text, true)}`;
1285
+ }
1286
+ }
1287
+ path.get("openingElement").get("attributes").forEach((attribute) => {
1288
+ var _a, _b, _c;
1289
+ const node = attribute.node;
1290
+ let value = node.value, key = t.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name, reservedNameSpace = t.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
1291
+ if (t.isJSXExpressionContainer(value) && !key.startsWith("use:")) {
1292
+ const evaluated = attribute.get("value").get("expression").evaluate().value;
1293
+ let type;
1294
+ if (evaluated !== void 0 && ((type = typeof evaluated) === "string" || type === "number")) {
1295
+ if (type === "number" && (Properties.has(key) || key.startsWith("prop:"))) {
1296
+ value = t.jsxExpressionContainer(t.numericLiteral(evaluated));
1297
+ } else value = t.stringLiteral(String(evaluated));
1298
+ }
1299
+ }
1300
+ if (t.isJSXNamespacedName(node.name) && reservedNameSpace && !t.isJSXExpressionContainer(value)) {
1301
+ node.value = value = t.jsxExpressionContainer(
1302
+ value || t.jsxEmptyExpression()
1303
+ );
1304
+ }
1305
+ if (t.isJSXExpressionContainer(value) && (reservedNameSpace || !(t.isStringLiteral(value.expression) || t.isNumericLiteral(value.expression)))) {
1306
+ if (key === "ref") {
1307
+ while (t.isTSNonNullExpression(value.expression) || t.isTSAsExpression(value.expression)) {
1308
+ value.expression = value.expression.expression;
1309
+ }
1310
+ let binding, isConstant = t.isIdentifier(value.expression) && (binding = path.scope.getBinding(value.expression.name)) && (binding.kind === "const" || binding.kind === "module");
1311
+ if (!isConstant && t.isLVal(value.expression)) {
1312
+ const refIdentifier = path.scope.generateUidIdentifier("_ref$");
1313
+ results.exprs.unshift(
1314
+ t.variableDeclaration("var", [
1315
+ t.variableDeclarator(refIdentifier, value.expression)
1316
+ ]),
1317
+ t.expressionStatement(
1318
+ t.conditionalExpression(
1319
+ t.binaryExpression(
1320
+ "===",
1321
+ t.unaryExpression("typeof", refIdentifier),
1322
+ t.stringLiteral("function")
1323
+ ),
1324
+ t.callExpression(
1325
+ registerImportMethod(
1326
+ path,
1327
+ "use",
1328
+ getRendererConfig(path, "dom").moduleName
1329
+ ),
1330
+ [refIdentifier, elem]
1331
+ ),
1332
+ t.assignmentExpression("=", value.expression, elem)
1333
+ )
1334
+ )
1335
+ );
1336
+ } else if (isConstant || t.isFunction(value.expression)) {
1337
+ results.exprs.unshift(
1338
+ t.expressionStatement(
1339
+ t.callExpression(
1340
+ registerImportMethod(
1341
+ path,
1342
+ "use",
1343
+ getRendererConfig(path, "dom").moduleName
1344
+ ),
1345
+ [value.expression, elem]
1346
+ )
1347
+ )
1348
+ );
1349
+ } else {
1350
+ const refIdentifier = path.scope.generateUidIdentifier("_ref$");
1351
+ results.exprs.unshift(
1352
+ t.variableDeclaration("var", [
1353
+ t.variableDeclarator(refIdentifier, value.expression)
1354
+ ]),
1355
+ t.expressionStatement(
1356
+ t.logicalExpression(
1357
+ "&&",
1358
+ t.binaryExpression(
1359
+ "===",
1360
+ t.unaryExpression("typeof", refIdentifier),
1361
+ t.stringLiteral("function")
1362
+ ),
1363
+ t.callExpression(
1364
+ registerImportMethod(
1365
+ path,
1366
+ "use",
1367
+ getRendererConfig(path, "dom").moduleName
1368
+ ),
1369
+ [refIdentifier, elem]
1370
+ )
1371
+ )
1372
+ )
1373
+ );
1374
+ }
1375
+ } else if (key.startsWith("use:")) {
1376
+ node.name.name.type = "Identifier";
1377
+ results.exprs.unshift(
1378
+ t.expressionStatement(
1379
+ t.callExpression(
1380
+ registerImportMethod(
1381
+ path,
1382
+ "use",
1383
+ getRendererConfig(path, "dom").moduleName
1384
+ ),
1385
+ [
1386
+ node.name.name,
1387
+ elem,
1388
+ t.arrowFunctionExpression(
1389
+ [],
1390
+ t.isJSXEmptyExpression(value.expression) ? t.booleanLiteral(true) : value.expression
1391
+ )
1392
+ ]
1393
+ )
1394
+ )
1395
+ );
1396
+ } else if (key === "children") {
1397
+ children = value;
1398
+ } else if (key.startsWith("on")) {
1399
+ const ev = toEventName(key);
1400
+ if (key.startsWith("on:")) {
1401
+ const args = [
1402
+ elem,
1403
+ t.stringLiteral(key.split(":")[1]),
1404
+ value.expression
1405
+ ];
1406
+ results.exprs.unshift(
1407
+ t.expressionStatement(
1408
+ t.callExpression(
1409
+ registerImportMethod(
1410
+ path,
1411
+ "addEventListener",
1412
+ getRendererConfig(path, "dom").moduleName
1413
+ ),
1414
+ args
1415
+ )
1416
+ )
1417
+ );
1418
+ } else if (key.startsWith("oncapture:")) {
1419
+ const args = [
1420
+ t.stringLiteral(key.split(":")[1]),
1421
+ value.expression,
1422
+ t.booleanLiteral(true)
1423
+ ];
1424
+ results.exprs.push(
1425
+ t.expressionStatement(
1426
+ t.callExpression(
1427
+ t.memberExpression(elem, t.identifier("addEventListener")),
1428
+ args
1429
+ )
1430
+ )
1431
+ );
1432
+ } else if (config.delegateEvents && (DelegatedEvents.has(ev) || config.delegatedEvents.indexOf(ev) !== -1)) {
1433
+ hasHydratableEvent = true;
1434
+ const events = attribute.scope.getProgramParent().data.events || (attribute.scope.getProgramParent().data.events = /* @__PURE__ */ new Set());
1435
+ events.add(ev);
1436
+ let handler = value.expression;
1437
+ const resolveable = detectResolvableEventHandler(attribute, handler);
1438
+ if (t.isArrayExpression(handler)) {
1439
+ if (handler.elements.length > 1) {
1440
+ results.exprs.unshift(
1441
+ t.expressionStatement(
1442
+ t.assignmentExpression(
1443
+ "=",
1444
+ t.memberExpression(elem, t.identifier(`$$${ev}Data`)),
1445
+ handler.elements[1]
1446
+ )
1447
+ )
1448
+ );
1449
+ }
1450
+ handler = handler.elements[0];
1451
+ results.exprs.unshift(
1452
+ t.expressionStatement(
1453
+ t.assignmentExpression(
1454
+ "=",
1455
+ t.memberExpression(elem, t.identifier(`$$${ev}`)),
1456
+ handler
1457
+ )
1458
+ )
1459
+ );
1460
+ } else if (t.isFunction(handler) || resolveable) {
1461
+ results.exprs.unshift(
1462
+ t.expressionStatement(
1463
+ t.assignmentExpression(
1464
+ "=",
1465
+ t.memberExpression(elem, t.identifier(`$$${ev}`)),
1466
+ handler
1467
+ )
1468
+ )
1469
+ );
1470
+ } else {
1471
+ results.exprs.unshift(
1472
+ t.expressionStatement(
1473
+ t.callExpression(
1474
+ registerImportMethod(
1475
+ path,
1476
+ "addEventListener",
1477
+ getRendererConfig(path, "dom").moduleName
1478
+ ),
1479
+ [
1480
+ elem,
1481
+ t.stringLiteral(ev),
1482
+ handler,
1483
+ t.booleanLiteral(true)
1484
+ ]
1485
+ )
1486
+ )
1487
+ );
1488
+ }
1489
+ } else {
1490
+ let handler = value.expression;
1491
+ const resolveable = detectResolvableEventHandler(attribute, handler);
1492
+ if (t.isArrayExpression(handler)) {
1493
+ if (handler.elements.length > 1) {
1494
+ handler = t.arrowFunctionExpression(
1495
+ [t.identifier("e")],
1496
+ t.callExpression(handler.elements[0], [
1497
+ handler.elements[1],
1498
+ t.identifier("e")
1499
+ ])
1500
+ );
1501
+ } else handler = handler.elements[0];
1502
+ results.exprs.unshift(
1503
+ t.expressionStatement(
1504
+ t.callExpression(
1505
+ t.memberExpression(elem, t.identifier("addEventListener")),
1506
+ [t.stringLiteral(ev), handler]
1507
+ )
1508
+ )
1509
+ );
1510
+ } else if (t.isFunction(handler) || resolveable) {
1511
+ results.exprs.unshift(
1512
+ t.expressionStatement(
1513
+ t.callExpression(
1514
+ t.memberExpression(elem, t.identifier("addEventListener")),
1515
+ [t.stringLiteral(ev), handler]
1516
+ )
1517
+ )
1518
+ );
1519
+ } else {
1520
+ results.exprs.unshift(
1521
+ t.expressionStatement(
1522
+ t.callExpression(
1523
+ registerImportMethod(
1524
+ path,
1525
+ "addEventListener",
1526
+ getRendererConfig(path, "dom").moduleName
1527
+ ),
1528
+ [elem, t.stringLiteral(ev), handler]
1529
+ )
1530
+ )
1531
+ );
1532
+ }
1533
+ }
1534
+ } else if (config.effectWrapper && (isDynamic(attribute.get("value").get("expression"), {
1535
+ checkMember: true
1536
+ }) || (key === "classList" || key === "style") && !attribute.get("value").get("expression").evaluate().confident && !hasStaticMarker(value, path))) {
1537
+ let nextElem = elem;
1538
+ if (key === "value" || key === "checked") {
1539
+ const effectWrapperId = registerImportMethod(
1540
+ path,
1541
+ config.effectWrapper
1542
+ );
1543
+ (_a = results.postExprs) == null ? void 0 : _a.push(
1544
+ t.expressionStatement(
1545
+ t.callExpression(effectWrapperId, [
1546
+ t.arrowFunctionExpression(
1547
+ [],
1548
+ setAttr$2(path, elem, key, value.expression, {
1549
+ tagName,
1550
+ isSVG,
1551
+ isCE
1552
+ })
1553
+ )
1554
+ ])
1555
+ )
1556
+ );
1557
+ return;
1558
+ }
1559
+ if (key === "textContent") {
1560
+ nextElem = attribute.scope.generateUidIdentifier("el$");
1561
+ children = t.jsxText(" ");
1562
+ children.extra = { raw: " ", rawValue: " " };
1563
+ (_b = results.declarations) == null ? void 0 : _b.push(
1564
+ t.variableDeclarator(
1565
+ nextElem,
1566
+ t.memberExpression(elem, t.identifier("firstChild"))
1567
+ )
1568
+ );
1569
+ }
1570
+ (_c = results.dynamics) == null ? void 0 : _c.push({
1571
+ elem: nextElem,
1572
+ key,
1573
+ value: value.expression,
1574
+ isSVG,
1575
+ isCE,
1576
+ tagName
1577
+ });
1578
+ } else if (key.slice(0, 5) === "attr:") {
1579
+ if (t.isJSXExpressionContainer(value)) value = value.expression;
1580
+ if (t.isStringLiteral(value) || t.isNumericLiteral(value)) {
1581
+ inlineAttributeOnTemplate(isSVG, key.slice(5), results, value);
1582
+ } else {
1583
+ results.exprs.push(
1584
+ t.expressionStatement(
1585
+ setAttr$2(attribute, elem, key, value, { isSVG, isCE, tagName })
1586
+ )
1587
+ );
1588
+ }
1589
+ } else if (key.slice(0, 5) === "bool:") {
1590
+ let addBoolAttribute2 = function() {
1591
+ results.template += `${needsSpacing ? " " : ""}${key.slice(5)}`;
1592
+ needsSpacing = true;
1593
+ };
1594
+ let content = value;
1595
+ if (t.isJSXExpressionContainer(content)) content = content.expression;
1596
+ switch (content.type) {
1597
+ case "StringLiteral": {
1598
+ if (content.value.length && content.value !== "0") {
1599
+ addBoolAttribute2();
1600
+ }
1601
+ return;
1602
+ }
1603
+ case "NullLiteral": {
1604
+ return;
1605
+ }
1606
+ case "BooleanLiteral": {
1607
+ if (content.value) {
1608
+ addBoolAttribute2();
1609
+ }
1610
+ return;
1611
+ }
1612
+ case "Identifier": {
1613
+ if (content.name === "undefined") {
1614
+ return;
1615
+ }
1616
+ break;
1617
+ }
1618
+ }
1619
+ results.exprs.push(
1620
+ t.expressionStatement(
1621
+ setAttr$2(
1622
+ attribute,
1623
+ elem,
1624
+ key,
1625
+ t.isJSXExpressionContainer(value) ? value.expression : value,
1626
+ { isSVG, isCE, tagName }
1627
+ )
1628
+ )
1629
+ );
1630
+ } else {
1631
+ results.exprs.push(
1632
+ t.expressionStatement(
1633
+ setAttr$2(attribute, elem, key, value.expression, {
1634
+ isSVG,
1635
+ isCE,
1636
+ tagName
1637
+ })
1638
+ )
1639
+ );
1640
+ }
1641
+ } else {
1642
+ if (config.hydratable && key === "$ServerOnly") {
1643
+ results.skipTemplate = true;
1644
+ return;
1645
+ }
1646
+ if (t.isJSXExpressionContainer(value)) value = value.expression;
1647
+ key = Aliases[key] || key;
1648
+ if (value && ChildProperties.has(key)) {
1649
+ results.exprs.push(
1650
+ t.expressionStatement(
1651
+ setAttr$2(attribute, elem, key, value, { isSVG, isCE, tagName })
1652
+ )
1653
+ );
1654
+ } else {
1655
+ inlineAttributeOnTemplate(isSVG, key, results, value);
1656
+ }
1657
+ }
1658
+ });
1659
+ if (!hasChildren && children) {
1660
+ path.node.children.push(children);
1661
+ }
1662
+ if (spreadExpr) results.exprs.push(spreadExpr);
1663
+ results.hasHydratableEvent = results.hasHydratableEvent || hasHydratableEvent;
1664
+ }
1665
+ function findLastElement(children, hydratable) {
1666
+ let lastElement = -1, tagName;
1667
+ for (let i = children.length - 1; i >= 0; i--) {
1668
+ const node = children[i].node;
1669
+ if (hydratable || t.isJSXText(node) || getStaticExpression(children[i]) !== false || t.isJSXElement(node) && (tagName = getTagName(node)) && !isComponent(tagName)) {
1670
+ lastElement = i;
1671
+ break;
1672
+ }
1673
+ }
1674
+ return lastElement;
1675
+ }
1676
+ function transformChildren$2(path, results, config) {
1677
+ var _a;
1678
+ let tempPath = results.id && results.id.name, tagName = getTagName(path.node), nextPlaceholder, childPostExprs = [], i = 0;
1679
+ const filteredChildren = filterChildren(path.get("children")), lastElement = findLastElement(filteredChildren, config.hydratable), childNodes = filteredChildren.reduce((memo, child, index) => {
1680
+ if (child.isJSXFragment()) {
1681
+ throw new Error(
1682
+ `Fragments can only be used top level in JSX. Not used under a <${tagName}>.`
1683
+ );
1684
+ }
1685
+ const transformed = transformNode(child, {
1686
+ toBeClosed: results.toBeClosed,
1687
+ lastElement: index === lastElement,
1688
+ skipId: !results.id || !detectExpressions(filteredChildren, index, config)
1689
+ });
1690
+ if (!transformed) return memo;
1691
+ const i2 = memo.length;
1692
+ if (transformed.text && i2 && memo[i2 - 1].text) {
1693
+ memo[i2 - 1].template += transformed.template(
1694
+ memo[i2 - 1]
1695
+ ).templateWithClosingTags += transformed.templateWithClosingTags || transformed.template;
1696
+ } else memo.push(transformed);
1697
+ return memo;
1698
+ }, []);
1699
+ childNodes.forEach((child, index) => {
1700
+ var _a2, _b, _c;
1701
+ if (!child) return;
1702
+ if (child.tagName && child.renderer !== "dom") {
1703
+ throw new Error(`<${child.tagName}> is not supported in <${tagName}>.
1704
+ Wrap the usage with a component that would render this element, eg. Canvas`);
1705
+ }
1706
+ results.template += child.template;
1707
+ results.templateWithClosingTags += child.templateWithClosingTags || child.template;
1708
+ results.isImportNode = results.isImportNode || child.isImportNode;
1709
+ if (child.id) {
1710
+ if (child.tagName === "head") {
1711
+ if (config.hydratable) {
1712
+ const createComponent = registerImportMethod(
1713
+ path,
1714
+ "createComponent",
1715
+ getRendererConfig(path, "dom").moduleName
1716
+ );
1717
+ const NoHydration = registerImportMethod(
1718
+ path,
1719
+ "NoHydration",
1720
+ getRendererConfig(path, "dom").moduleName
1721
+ );
1722
+ results.exprs.push(
1723
+ t.expressionStatement(
1724
+ t.callExpression(createComponent, [
1725
+ NoHydration,
1726
+ t.objectExpression([])
1727
+ ])
1728
+ )
1729
+ );
1730
+ }
1731
+ return;
1732
+ }
1733
+ let getNextMatch;
1734
+ if (config.hydratable && tagName === "html") {
1735
+ getNextMatch = registerImportMethod(
1736
+ path,
1737
+ "getNextMatch",
1738
+ getRendererConfig(path, "dom").moduleName
1739
+ );
1740
+ }
1741
+ const walk = t.memberExpression(
1742
+ t.identifier(tempPath),
1743
+ t.identifier(i === 0 ? "firstChild" : "nextSibling")
1744
+ );
1745
+ (_a2 = results.declarations) == null ? void 0 : _a2.push(
1746
+ t.variableDeclarator(
1747
+ child.id,
1748
+ config.hydratable && tagName === "html" ? t.callExpression(getNextMatch, [
1749
+ walk,
1750
+ t.stringLiteral(child.tagName)
1751
+ ]) : walk
1752
+ )
1753
+ );
1754
+ (_b = results.declarations) == null ? void 0 : _b.push(...child.declarations);
1755
+ results.exprs.push(...child.exprs);
1756
+ (_c = results.dynamics) == null ? void 0 : _c.push(...child.dynamics);
1757
+ childPostExprs.push(...child.postExprs);
1758
+ results.hasHydratableEvent = results.hasHydratableEvent || child.hasHydratableEvent;
1759
+ results.hasCustomElement = results.hasCustomElement || child.hasCustomElement;
1760
+ results.isImportNode = results.isImportNode || child.isImportNode;
1761
+ tempPath = child.id.name;
1762
+ nextPlaceholder = null;
1763
+ i++;
1764
+ } else if (child.exprs.length) {
1765
+ let insert = registerImportMethod(
1766
+ path,
1767
+ "insert",
1768
+ getRendererConfig(path, "dom").moduleName
1769
+ );
1770
+ const multi = checkLength(filteredChildren), markers = config.hydratable && multi;
1771
+ if (markers || wrappedByText(childNodes, index)) {
1772
+ let exprId, contentId;
1773
+ if (markers)
1774
+ tempPath = createPlaceholder(path, results, tempPath, i++, "$")[0].name;
1775
+ if (nextPlaceholder) {
1776
+ exprId = nextPlaceholder;
1777
+ } else {
1778
+ [exprId, contentId] = createPlaceholder(
1779
+ path,
1780
+ results,
1781
+ tempPath,
1782
+ i++,
1783
+ markers ? "/" : ""
1784
+ );
1785
+ }
1786
+ if (!markers) nextPlaceholder = exprId;
1787
+ results.exprs.push(
1788
+ t.expressionStatement(
1789
+ t.callExpression(
1790
+ insert,
1791
+ contentId ? [results.id, child.exprs[0], exprId, contentId] : [results.id, child.exprs[0], exprId]
1792
+ )
1793
+ )
1794
+ );
1795
+ tempPath = exprId.name;
1796
+ } else if (multi) {
1797
+ results.exprs.push(
1798
+ t.expressionStatement(
1799
+ t.callExpression(insert, [
1800
+ results.id,
1801
+ child.exprs[0],
1802
+ nextChild$1(childNodes, index) || t.nullLiteral()
1803
+ ])
1804
+ )
1805
+ );
1806
+ } else {
1807
+ results.exprs.push(
1808
+ t.expressionStatement(
1809
+ t.callExpression(insert, [results.id, child.exprs[0]])
1810
+ )
1811
+ );
1812
+ }
1813
+ } else nextPlaceholder = null;
1814
+ });
1815
+ (_a = results.postExprs) == null ? void 0 : _a.unshift(...childPostExprs);
1816
+ }
1817
+ function createPlaceholder(path, results, tempPath, i, char) {
1818
+ var _a, _b;
1819
+ const exprId = path.scope.generateUidIdentifier("el$"), config = getConfig(path);
1820
+ let contentId;
1821
+ results.template += `<!${char}>`;
1822
+ results.templateWithClosingTags += `<!${char}>`;
1823
+ if (config.hydratable && char === "/") {
1824
+ contentId = path.scope.generateUidIdentifier("co$");
1825
+ (_a = results.declarations) == null ? void 0 : _a.push(
1826
+ t.variableDeclarator(
1827
+ t.arrayPattern([exprId, contentId]),
1828
+ t.callExpression(
1829
+ registerImportMethod(
1830
+ path,
1831
+ "getNextMarker",
1832
+ getRendererConfig(path, "dom").moduleName
1833
+ ),
1834
+ [
1835
+ t.memberExpression(
1836
+ t.identifier(tempPath),
1837
+ t.identifier("nextSibling")
1838
+ )
1839
+ ]
1840
+ )
1841
+ )
1842
+ );
1843
+ } else
1844
+ (_b = results.declarations) == null ? void 0 : _b.push(
1845
+ t.variableDeclarator(
1846
+ exprId,
1847
+ t.memberExpression(
1848
+ t.identifier(tempPath),
1849
+ t.identifier(i === 0 ? "firstChild" : "nextSibling")
1850
+ )
1851
+ )
1852
+ );
1853
+ return [exprId, contentId];
1854
+ }
1855
+ function nextChild$1(children, index) {
1856
+ return children[index + 1] && (children[index + 1].id || nextChild$1(children, index + 1));
1857
+ }
1858
+ function detectExpressions(children, index, config) {
1859
+ if (children[index - 1]) {
1860
+ const node = children[index - 1].node;
1861
+ if (t.isJSXExpressionContainer(node) && !t.isJSXEmptyExpression(node.expression) && getStaticExpression(children[index - 1]) === false)
1862
+ return true;
1863
+ let tagName;
1864
+ if (t.isJSXElement(node) && (tagName = getTagName(node)) && isComponent(tagName))
1865
+ return true;
1866
+ }
1867
+ for (let i = index; i < children.length; i++) {
1868
+ const child = children[i].node;
1869
+ if (t.isJSXExpressionContainer(child)) {
1870
+ if (!t.isJSXEmptyExpression(child.expression) && getStaticExpression(children[i]) === false)
1871
+ return true;
1872
+ } else if (t.isJSXElement(child)) {
1873
+ const tagName = getTagName(child);
1874
+ if (isComponent(tagName)) return true;
1875
+ if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1 || child.openingElement.attributes.some(
1876
+ (a) => {
1877
+ var _a;
1878
+ return ((_a = a.name) == null ? void 0 : _a.name) === "is";
1879
+ }
1880
+ )))
1881
+ return true;
1882
+ if (child.openingElement.attributes.some(
1883
+ (attr) => t.isJSXSpreadAttribute(attr) || ["textContent", "innerHTML", "innerText"].includes(
1884
+ attr.name.name
1885
+ ) || attr.name.namespace && (attr.name.namespace.name === "use" || attr.name.namespace.name === "prop") || t.isJSXExpressionContainer(attr.value) && !(t.isStringLiteral(attr.value.expression) || t.isNumericLiteral(attr.value.expression))
1886
+ ))
1887
+ return true;
1888
+ const nextChildren = filterChildren(children[i].get("children"));
1889
+ if (nextChildren.length) {
1890
+ if (detectExpressions(nextChildren, 0, config)) return true;
1891
+ }
1892
+ }
1893
+ }
1894
+ }
1895
+ function contextToCustomElement(path, results) {
1896
+ results.exprs.push(
1897
+ t.expressionStatement(
1898
+ t.assignmentExpression(
1899
+ "=",
1900
+ t.memberExpression(results.id, t.identifier("_$owner")),
1901
+ t.callExpression(
1902
+ registerImportMethod(
1903
+ path,
1904
+ "getOwner",
1905
+ getRendererConfig(path, "dom").moduleName
1906
+ ),
1907
+ []
1908
+ )
1909
+ )
1910
+ )
1911
+ );
1912
+ }
1913
+ function processSpreads$1(path, attributes, { elem, isSVG, hasChildren, wrapConditionals }) {
1914
+ const config = getConfig(path);
1915
+ const filteredAttributes = [];
1916
+ const spreadArgs = [];
1917
+ let runningObject = [];
1918
+ let dynamicSpread = false;
1919
+ let firstSpread = false;
1920
+ attributes.forEach((attribute) => {
1921
+ const node = attribute.node;
1922
+ const key = !t.isJSXSpreadAttribute(node) && (t.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name);
1923
+ if (t.isJSXSpreadAttribute(node)) {
1924
+ const isStatic = node.innerComments && node.innerComments[0] && node.innerComments[0].value.trim() === config.staticMarker;
1925
+ firstSpread = true;
1926
+ if (runningObject.length) {
1927
+ spreadArgs.push(t.objectExpression(runningObject));
1928
+ runningObject = [];
1929
+ }
1930
+ const s = isDynamic(attribute.get("argument"), {
1931
+ checkMember: true
1932
+ }) && (dynamicSpread = true) ? t.isCallExpression(node.argument) && !node.argument.arguments.length && !t.isCallExpression(node.argument.callee) && !t.isMemberExpression(node.argument.callee) ? node.argument.callee : t.arrowFunctionExpression([], node.argument) : node.argument;
1933
+ spreadArgs.push(
1934
+ isStatic ? t.objectExpression([t.spreadElement(s)]) : s
1935
+ );
1936
+ } else if ((firstSpread || t.isJSXExpressionContainer(node.value) && isDynamic(attribute.get("value").get("expression"), {
1937
+ checkMember: true
1938
+ })) && canNativeSpread(key, { checkNameSpaces: true })) {
1939
+ const isContainer = t.isJSXExpressionContainer(node.value);
1940
+ const dynamic = isContainer && isDynamic(attribute.get("value").get("expression"), {
1941
+ checkMember: true
1942
+ });
1943
+ if (dynamic) {
1944
+ const id = convertJSXIdentifier(node.name);
1945
+ let expr = wrapConditionals && (t.isLogicalExpression(node.value.expression) || t.isConditionalExpression(node.value.expression)) ? transformCondition(attribute.get("value").get("expression"), true) : t.arrowFunctionExpression([], node.value.expression);
1946
+ runningObject.push(
1947
+ t.objectMethod(
1948
+ "get",
1949
+ id,
1950
+ [],
1951
+ t.blockStatement([t.returnStatement(expr.body)]),
1952
+ !t.isValidIdentifier(key)
1953
+ )
1954
+ );
1955
+ } else {
1956
+ runningObject.push(
1957
+ t.objectProperty(
1958
+ t.stringLiteral(key),
1959
+ isContainer ? node.value.expression : node.value || (Properties.has(key) ? t.booleanLiteral(true) : t.stringLiteral(""))
1960
+ )
1961
+ );
1962
+ }
1963
+ } else filteredAttributes.push(attribute);
1964
+ });
1965
+ if (runningObject.length) {
1966
+ spreadArgs.push(t.objectExpression(runningObject));
1967
+ }
1968
+ const props = spreadArgs.length === 1 && !dynamicSpread ? spreadArgs[0] : t.callExpression(registerImportMethod(path, "mergeProps"), spreadArgs);
1969
+ return [
1970
+ filteredAttributes,
1971
+ t.expressionStatement(
1972
+ t.callExpression(
1973
+ registerImportMethod(
1974
+ path,
1975
+ "spread",
1976
+ getRendererConfig(path, "dom").moduleName
1977
+ ),
1978
+ [
1979
+ elem,
1980
+ props,
1981
+ t.booleanLiteral(isSVG),
1982
+ t.booleanLiteral(hasChildren)
1983
+ ]
1984
+ )
1985
+ )
1986
+ ];
1987
+ }
1988
+
1989
+ function createTemplate$2(path, result, wrap) {
1990
+ var _a, _b, _c;
1991
+ const config = getConfig(path);
1992
+ if (result.id) {
1993
+ registerTemplate(path, result);
1994
+ if (!(result.exprs.length || ((_a = result.dynamics) == null ? void 0 : _a.length) || ((_b = result.postExprs) == null ? void 0 : _b.length)) && ((_c = result.decl) == null ? void 0 : _c.declarations.length) === 1) {
1995
+ return result.decl.declarations[0].init;
1996
+ } else {
1997
+ return t.callExpression(
1998
+ t.arrowFunctionExpression(
1999
+ [],
2000
+ t.blockStatement([
2001
+ result.decl,
2002
+ ...result.exprs.concat(
2003
+ wrapDynamics$1(path, result.dynamics) || [],
2004
+ result.postExprs || []
2005
+ ),
2006
+ t.returnStatement(result.id)
2007
+ ])
2008
+ ),
2009
+ []
2010
+ );
2011
+ }
2012
+ }
2013
+ if (wrap && result.dynamic && config.memoWrapper) {
2014
+ return t.callExpression(registerImportMethod(path, config.memoWrapper), [
2015
+ result.exprs[0]
2016
+ ]);
2017
+ }
2018
+ return result.exprs[0];
2019
+ }
2020
+ function appendTemplates$1(path, templates) {
2021
+ const declarators = templates.map((template) => {
2022
+ const tmpl = {
2023
+ cooked: template.template,
2024
+ raw: escapeStringForTemplate(template.template)
2025
+ };
2026
+ const shouldUseImportNode = template.isCE || template.isImportNode;
2027
+ const isMathML = /^<(math|annotation|annotation-xml|maction|math|merror|mfrac|mi|mmultiscripts|mn|mo|mover|mpadded|mphantom|mprescripts|mroot|mrow|ms|mspace|msqrt|mstyle|msub|msubsup|msup|mtable|mtd|mtext|mtr|munder|munderover|semantics|menclose|mfenced)(\s|>)/.test(
2028
+ template.template
2029
+ );
2030
+ return t.variableDeclarator(
2031
+ template.id,
2032
+ t.addComment(
2033
+ t.callExpression(
2034
+ registerImportMethod(
2035
+ path,
2036
+ "template",
2037
+ getRendererConfig(path, "dom").moduleName
2038
+ ),
2039
+ [t.templateLiteral([t.templateElement(tmpl, true)], [])].concat(
2040
+ template.isSVG || shouldUseImportNode || isMathML ? [
2041
+ t.booleanLiteral(!!shouldUseImportNode),
2042
+ t.booleanLiteral(template.isSVG),
2043
+ t.booleanLiteral(isMathML)
2044
+ ] : []
2045
+ )
2046
+ ),
2047
+ "leading",
2048
+ "#__PURE__"
2049
+ )
2050
+ );
2051
+ });
2052
+ path.node.body.unshift(t.variableDeclaration("var", declarators));
2053
+ }
2054
+ function registerTemplate(path, results) {
2055
+ var _a;
2056
+ const { hydratable } = getConfig(path);
2057
+ let decl;
2058
+ if (results.template.length) {
2059
+ let templateDef, templateId;
2060
+ if (!results.skipTemplate) {
2061
+ const templates = path.scope.getProgramParent().data.templates || (path.scope.getProgramParent().data.templates = []);
2062
+ if (templateDef = templates.find((t2) => t2.template === results.template)) {
2063
+ templateId = templateDef.id;
2064
+ } else {
2065
+ templateId = path.scope.generateUidIdentifier("tmpl$");
2066
+ templates.push({
2067
+ id: templateId,
2068
+ template: results.template,
2069
+ templateWithClosingTags: results.templateWithClosingTags,
2070
+ isSVG: results.isSVG,
2071
+ isCE: results.hasCustomElement,
2072
+ isImportNode: results.isImportNode,
2073
+ renderer: "dom"
2074
+ });
2075
+ }
2076
+ }
2077
+ decl = t.variableDeclarator(
2078
+ results.id,
2079
+ hydratable ? t.callExpression(
2080
+ registerImportMethod(
2081
+ path,
2082
+ "getNextElement",
2083
+ getRendererConfig(path, "dom").moduleName
2084
+ ),
2085
+ templateId ? [templateId] : []
2086
+ ) : t.callExpression(templateId, [])
2087
+ );
2088
+ }
2089
+ (_a = results.declarations) == null ? void 0 : _a.unshift(decl);
2090
+ results.decl = t.variableDeclaration("var", results.declarations);
2091
+ }
2092
+ function wrapDynamics$1(path, dynamics) {
2093
+ if (!(dynamics == null ? void 0 : dynamics.length)) return;
2094
+ const config = getConfig(path);
2095
+ const effectWrapperId = registerImportMethod(path, config.effectWrapper);
2096
+ if (dynamics.length === 1) {
2097
+ let dynamicStyle;
2098
+ const prevValue = dynamics[0].key === "classList" || dynamics[0].key === "style" || (dynamicStyle = dynamics[0].key.startsWith("style:")) ? t.identifier("_$p") : void 0;
2099
+ if (dynamicStyle) {
2100
+ dynamics[0].value = t.assignmentExpression(
2101
+ "=",
2102
+ prevValue,
2103
+ dynamics[0].value
2104
+ );
2105
+ } else if (dynamics[0].key.startsWith("class:") && !t.isBooleanLiteral(dynamics[0].value) && !t.isUnaryExpression(dynamics[0].value)) {
2106
+ dynamics[0].value = t.unaryExpression(
2107
+ "!",
2108
+ t.unaryExpression("!", dynamics[0].value)
2109
+ );
2110
+ }
2111
+ return t.expressionStatement(
2112
+ t.callExpression(effectWrapperId, [
2113
+ t.arrowFunctionExpression(
2114
+ prevValue ? [prevValue] : [],
2115
+ setAttr$2(path, dynamics[0].elem, dynamics[0].key, dynamics[0].value, {
2116
+ isSVG: dynamics[0].isSVG,
2117
+ isCE: dynamics[0].isCE,
2118
+ tagName: dynamics[0].tagName,
2119
+ dynamic: true,
2120
+ prevId: prevValue
2121
+ })
2122
+ )
2123
+ ])
2124
+ );
2125
+ }
2126
+ const prevId = t.identifier("_p$");
2127
+ const declarations = [];
2128
+ const statements = [];
2129
+ const properties = [];
2130
+ dynamics.forEach(({ elem, key, value, isSVG, isCE, tagName }, index) => {
2131
+ const varIdent = path.scope.generateUidIdentifier("v$");
2132
+ const propIdent = t.identifier(getNumberedId(index));
2133
+ const propMember = t.memberExpression(prevId, propIdent);
2134
+ if (key.startsWith("class:") && !t.isBooleanLiteral(value) && !t.isUnaryExpression(value)) {
2135
+ value = t.unaryExpression("!", t.unaryExpression("!", value));
2136
+ }
2137
+ properties.push(propIdent);
2138
+ declarations.push(t.variableDeclarator(varIdent, value));
2139
+ if (key === "classList" || key === "style") {
2140
+ statements.push(
2141
+ t.expressionStatement(
2142
+ t.assignmentExpression(
2143
+ "=",
2144
+ propMember,
2145
+ setAttr$2(path, elem, key, varIdent, {
2146
+ isSVG,
2147
+ isCE,
2148
+ tagName,
2149
+ dynamic: true,
2150
+ prevId: propMember
2151
+ })
2152
+ )
2153
+ )
2154
+ );
2155
+ } else {
2156
+ const prev = key.startsWith("style:") ? varIdent : void 0;
2157
+ statements.push(
2158
+ t.expressionStatement(
2159
+ t.logicalExpression(
2160
+ "&&",
2161
+ t.binaryExpression("!==", varIdent, propMember),
2162
+ setAttr$2(
2163
+ path,
2164
+ elem,
2165
+ key,
2166
+ t.assignmentExpression("=", propMember, varIdent),
2167
+ {
2168
+ isSVG,
2169
+ isCE,
2170
+ tagName,
2171
+ dynamic: true,
2172
+ prevId: prev
2173
+ }
2174
+ )
2175
+ )
2176
+ )
2177
+ );
2178
+ }
2179
+ });
2180
+ return t.expressionStatement(
2181
+ t.callExpression(effectWrapperId, [
2182
+ t.arrowFunctionExpression(
2183
+ [prevId],
2184
+ t.blockStatement([
2185
+ t.variableDeclaration("var", declarations),
2186
+ ...statements,
2187
+ t.returnStatement(prevId)
2188
+ ])
2189
+ ),
2190
+ t.objectExpression(
2191
+ properties.map((id) => t.objectProperty(id, t.identifier("undefined")))
2192
+ )
2193
+ ])
2194
+ );
2195
+ }
2196
+
2197
+ function createTemplate$1(path, result) {
2198
+ var _a, _b, _c, _d, _e, _f;
2199
+ if (!result.template) {
2200
+ return result.exprs[0];
2201
+ }
2202
+ let template, id;
2203
+ if (!Array.isArray(result.template)) {
2204
+ template = t.stringLiteral(result.template);
2205
+ } else if (result.template.length === 1) {
2206
+ template = t.stringLiteral(result.template[0]);
2207
+ } else {
2208
+ const strings = result.template.map((tmpl) => t.stringLiteral(tmpl));
2209
+ template = t.arrayExpression(strings);
2210
+ }
2211
+ const templates = path.scope.getProgramParent().data.templates || (path.scope.getProgramParent().data.templates = []);
2212
+ const found = templates.find((tmp) => {
2213
+ if (t.isArrayExpression(tmp.template) && t.isArrayExpression(template)) {
2214
+ return tmp.template.elements.every(
2215
+ (el, i) => template.elements[i] && el.value === template.elements[i].value
2216
+ );
2217
+ }
2218
+ return tmp.template.value === template.value;
2219
+ });
2220
+ if (!found) {
2221
+ id = path.scope.generateUidIdentifier("tmpl$");
2222
+ templates.push({
2223
+ id,
2224
+ template,
2225
+ templateWithClosingTags: template,
2226
+ renderer: "ssr"
2227
+ });
2228
+ } else id = found.id;
2229
+ if (result.wontEscape) {
2230
+ if (!Array.isArray(result.template) || result.template.length === 1)
2231
+ return id;
2232
+ else if (Array.isArray(result.template) && result.template.length === 2 && ((_b = (_a = result.templateValues) == null ? void 0 : _a[0]) == null ? void 0 : _b.type) === "CallExpression" && ((_e = (_d = (_c = result.templateValues) == null ? void 0 : _c[0]) == null ? void 0 : _d.callee) == null ? void 0 : _e.name) === "_$ssrHydrationKey") {
2233
+ return t.binaryExpression(
2234
+ "+",
2235
+ t.binaryExpression(
2236
+ "+",
2237
+ t.memberExpression(id, t.numericLiteral(0), true),
2238
+ result.templateValues[0]
2239
+ ),
2240
+ t.memberExpression(id, t.numericLiteral(1), true)
2241
+ );
2242
+ }
2243
+ }
2244
+ return t.callExpression(
2245
+ registerImportMethod(path, "ssr"),
2246
+ Array.isArray(result.template) && result.template.length > 1 ? [id, ...(_f = result.templateValues) != null ? _f : []] : [id]
2247
+ );
2248
+ }
2249
+ function appendTemplates(path, templates) {
2250
+ const declarators = templates.map((template) => {
2251
+ return t.variableDeclarator(template.id, template.template);
2252
+ });
2253
+ path.node.body.unshift(t.variableDeclaration("var", declarators));
2254
+ }
2255
+
2256
+ var __defProp = Object.defineProperty;
2257
+ var __defProps = Object.defineProperties;
2258
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2259
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
2260
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
2261
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
2262
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2263
+ var __spreadValues = (a, b) => {
2264
+ for (var prop in b || (b = {}))
2265
+ if (__hasOwnProp.call(b, prop))
2266
+ __defNormalProp(a, prop, b[prop]);
2267
+ if (__getOwnPropSymbols)
2268
+ for (var prop of __getOwnPropSymbols(b)) {
2269
+ if (__propIsEnum.call(b, prop))
2270
+ __defNormalProp(a, prop, b[prop]);
2271
+ }
2272
+ return a;
2273
+ };
2274
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
2275
+ function appendToTemplate(template, value) {
2276
+ let array;
2277
+ if (Array.isArray(value)) {
2278
+ [value, ...array] = value;
2279
+ }
2280
+ template[template.length - 1] += value;
2281
+ if (array && array.length) template.push.apply(template, array);
2282
+ }
2283
+ function transformElement$2(path, info) {
2284
+ var _a, _b;
2285
+ const config = getConfig(path);
2286
+ const tagName = getTagName(path.node);
2287
+ if (tagName === "script" || tagName === "style")
2288
+ path.doNotEscape = true;
2289
+ if (path.node.openingElement.attributes.some(
2290
+ (a) => t.isJSXSpreadAttribute(a)
2291
+ ))
2292
+ return createElement(path, __spreadValues(__spreadValues({}, info), config));
2293
+ const voidTag = voidElements.indexOf(tagName) > -1, results = {
2294
+ template: [`<${tagName}`],
2295
+ templateValues: [],
2296
+ declarations: [],
2297
+ exprs: [],
2298
+ dynamics: [],
2299
+ tagName,
2300
+ wontEscape: path.node.wontEscape,
2301
+ renderer: "ssr"
2302
+ };
2303
+ if (info.topLevel && config.hydratable) {
2304
+ if (tagName === "head") {
2305
+ registerImportMethod(path, "NoHydration");
2306
+ registerImportMethod(path, "createComponent");
2307
+ const child = transformElement$2(path, __spreadProps(__spreadValues({}, info), { topLevel: false }));
2308
+ results.template = "";
2309
+ results.templateWithClosingTags = "";
2310
+ results.exprs.push(
2311
+ t.callExpression(t.identifier("_$createComponent"), [
2312
+ t.identifier("_$NoHydration"),
2313
+ t.objectExpression([
2314
+ t.objectMethod(
2315
+ "get",
2316
+ t.identifier("children"),
2317
+ [],
2318
+ t.blockStatement([
2319
+ t.returnStatement(createTemplate$1(path, child))
2320
+ ])
2321
+ )
2322
+ ])
2323
+ ])
2324
+ );
2325
+ return results;
2326
+ }
2327
+ (_a = results.template) == null ? void 0 : _a.push("");
2328
+ (_b = results.templateValues) == null ? void 0 : _b.push(
2329
+ t.callExpression(registerImportMethod(path, "ssrHydrationKey"), [])
2330
+ );
2331
+ }
2332
+ transformAttributes$1(path, results, __spreadValues(__spreadValues({}, config), info));
2333
+ appendToTemplate(results.template, ">");
2334
+ if (!voidTag) {
2335
+ transformChildren$1(path, results, __spreadValues(__spreadValues({}, config), info));
2336
+ appendToTemplate(results.template, `</${tagName}>`);
2337
+ }
2338
+ return results;
2339
+ }
2340
+ function toAttribute(key, isSVG) {
2341
+ key = Aliases[key] || key;
2342
+ !isSVG && (key = key.toLowerCase());
2343
+ return key;
2344
+ }
2345
+ function setAttr$1(attribute, results, name, value, isSVG) {
2346
+ var _a, _b, _c;
2347
+ let parts;
2348
+ if ((parts = name.split(":")) && parts[1] && reservedNameSpaces.has(parts[0])) {
2349
+ name = parts[1];
2350
+ }
2351
+ name = toAttribute(name, isSVG);
2352
+ const attr = t.callExpression(
2353
+ registerImportMethod(attribute, "ssrAttribute"),
2354
+ [t.stringLiteral(name), value, t.booleanLiteral(false)]
2355
+ );
2356
+ if (results.template[results.template.length - 1].length) {
2357
+ (_a = results.template) == null ? void 0 : _a.push("");
2358
+ (_b = results.templateValues) == null ? void 0 : _b.push(attr);
2359
+ } else {
2360
+ const last = results.templateValues.length - 1;
2361
+ results.templateValues[last] = t.binaryExpression(
2362
+ "+",
2363
+ (_c = results.templateValues) == null ? void 0 : _c[last],
2364
+ attr
2365
+ );
2366
+ }
2367
+ }
2368
+ function escapeExpression(path, expression, attr, escapeLiterals) {
2369
+ if (t.isStringLiteral(expression) || t.isNumericLiteral(expression) || t.isTemplateLiteral(expression) && expression.expressions.length === 0) {
2370
+ if (escapeLiterals) {
2371
+ if (t.isStringLiteral(expression))
2372
+ return t.stringLiteral(escapeHTML(expression.value, attr));
2373
+ else if (t.isTemplateLiteral(expression))
2374
+ return t.stringLiteral(escapeHTML(expression.quasis[0].value.raw, attr));
2375
+ }
2376
+ return expression;
2377
+ } else if (t.isFunction(expression)) {
2378
+ if (t.isBlockStatement(expression.body)) {
2379
+ expression.body.body = expression.body.body.map((e) => {
2380
+ if (t.isReturnStatement(e))
2381
+ e.argument = escapeExpression(
2382
+ path,
2383
+ e.argument,
2384
+ attr,
2385
+ escapeLiterals
2386
+ );
2387
+ return e;
2388
+ });
2389
+ } else
2390
+ expression.body = escapeExpression(
2391
+ path,
2392
+ expression.body,
2393
+ attr,
2394
+ escapeLiterals
2395
+ );
2396
+ return expression;
2397
+ } else if (t.isTemplateLiteral(expression)) {
2398
+ expression.expressions = expression.expressions.map(
2399
+ (e) => escapeExpression(path, e, attr, escapeLiterals)
2400
+ );
2401
+ return expression;
2402
+ } else if (t.isUnaryExpression(expression)) {
2403
+ return expression;
2404
+ } else if (t.isBinaryExpression(expression)) {
2405
+ expression.left = escapeExpression(
2406
+ path,
2407
+ expression.left,
2408
+ attr,
2409
+ escapeLiterals
2410
+ );
2411
+ expression.right = escapeExpression(
2412
+ path,
2413
+ expression.right,
2414
+ attr,
2415
+ escapeLiterals
2416
+ );
2417
+ return expression;
2418
+ } else if (t.isConditionalExpression(expression)) {
2419
+ expression.consequent = escapeExpression(
2420
+ path,
2421
+ expression.consequent,
2422
+ attr,
2423
+ escapeLiterals
2424
+ );
2425
+ expression.alternate = escapeExpression(
2426
+ path,
2427
+ expression.alternate,
2428
+ attr,
2429
+ escapeLiterals
2430
+ );
2431
+ return expression;
2432
+ } else if (t.isLogicalExpression(expression)) {
2433
+ expression.right = escapeExpression(
2434
+ path,
2435
+ expression.right,
2436
+ attr,
2437
+ escapeLiterals
2438
+ );
2439
+ if (expression.operator !== "&&") {
2440
+ expression.left = escapeExpression(
2441
+ path,
2442
+ expression.left,
2443
+ attr,
2444
+ escapeLiterals
2445
+ );
2446
+ }
2447
+ return expression;
2448
+ } else if (t.isCallExpression(expression) && t.isFunction(expression.callee)) {
2449
+ if (t.isBlockStatement(expression.callee.body)) {
2450
+ expression.callee.body.body = expression.callee.body.body.map((e) => {
2451
+ if (t.isReturnStatement(e))
2452
+ e.argument = escapeExpression(
2453
+ path,
2454
+ e.argument,
2455
+ attr,
2456
+ escapeLiterals
2457
+ );
2458
+ return e;
2459
+ });
2460
+ } else
2461
+ expression.callee.body = escapeExpression(
2462
+ path,
2463
+ expression.callee.body,
2464
+ attr,
2465
+ escapeLiterals
2466
+ );
2467
+ return expression;
2468
+ } else if (t.isJSXElement(expression) && !isComponent(getTagName(expression))) {
2469
+ expression.wontEscape = true;
2470
+ return expression;
2471
+ }
2472
+ return t.callExpression(
2473
+ registerImportMethod(path, "escape"),
2474
+ [expression].concat(attr ? [t.booleanLiteral(true)] : [])
2475
+ );
2476
+ }
2477
+ function transformToObject(attrName, attributes, selectedAttributes) {
2478
+ const properties = [];
2479
+ const existingAttribute = attributes.find((a) => a.node.name.name === attrName);
2480
+ for (let i = 0; i < selectedAttributes.length; i++) {
2481
+ const attr = selectedAttributes[i].node;
2482
+ const computed = !t.isValidIdentifier(attr.name.name.name);
2483
+ if (!computed) {
2484
+ attr.name.name.type = "Identifier";
2485
+ }
2486
+ properties.push(
2487
+ t.objectProperty(
2488
+ computed ? t.stringLiteral(attr.name.name.name) : attr.name.name,
2489
+ t.isJSXExpressionContainer(attr.value) ? attr.value.expression : attr.value
2490
+ )
2491
+ );
2492
+ (existingAttribute || i) && attributes.splice(selectedAttributes[i].key, 1);
2493
+ }
2494
+ if (existingAttribute && t.isJSXExpressionContainer(existingAttribute.node.value) && t.isObjectExpression(existingAttribute.node.value.expression)) {
2495
+ existingAttribute.node.value.expression.properties.push(...properties);
2496
+ } else {
2497
+ selectedAttributes[0].node = t.jsxAttribute(
2498
+ t.jsxIdentifier(attrName),
2499
+ t.jsxExpressionContainer(t.objectExpression(properties))
2500
+ );
2501
+ }
2502
+ }
2503
+ function normalizeAttributes(path) {
2504
+ const attributes = path.get("openingElement").get("attributes"), styleAttributes = attributes.filter(
2505
+ (a) => t.isJSXNamespacedName(a.node.name) && a.node.name.namespace.name === "style"
2506
+ ), classNamespaceAttributes = attributes.filter(
2507
+ (a) => t.isJSXNamespacedName(a.node.name) && a.node.name.namespace.name === "class"
2508
+ );
2509
+ if (classNamespaceAttributes.length)
2510
+ transformToObject("classList", attributes, classNamespaceAttributes);
2511
+ const classAttributes = attributes.filter(
2512
+ (a) => a.node.name && (a.node.name.name === "class" || a.node.name.name === "className" || a.node.name.name === "classList")
2513
+ );
2514
+ if (classAttributes.length > 1) {
2515
+ const first = classAttributes[0].node, values = [], quasis = [t.templateElement({ raw: "" })];
2516
+ for (let i = 0; i < classAttributes.length; i++) {
2517
+ const attr = classAttributes[i].node, isLast = i === classAttributes.length - 1;
2518
+ if (!t.isJSXExpressionContainer(attr.value)) {
2519
+ const prev = quasis.pop();
2520
+ quasis.push(
2521
+ t.templateElement({
2522
+ raw: (prev ? prev.value.raw : "") + `${attr.value.value}` + (isLast ? "" : " ")
2523
+ })
2524
+ );
2525
+ } else {
2526
+ let expr = attr.value.expression;
2527
+ if (attr.name.name === "classList") {
2528
+ if (t.isObjectExpression(expr) && !expr.properties.some((p) => t.isSpreadElement(p))) {
2529
+ transformClasslistObject(path, expr, values, quasis);
2530
+ if (!isLast) quasis[quasis.length - 1].value.raw += " ";
2531
+ i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
2532
+ continue;
2533
+ }
2534
+ expr = t.callExpression(registerImportMethod(path, "ssrClassList"), [
2535
+ expr
2536
+ ]);
2537
+ }
2538
+ values.push(t.logicalExpression("||", expr, t.stringLiteral("")));
2539
+ quasis.push(t.templateElement({ raw: isLast ? "" : " " }));
2540
+ }
2541
+ i && attributes.splice(attributes.indexOf(classAttributes[i]), 1);
2542
+ }
2543
+ first.name = t.jsxIdentifier("class");
2544
+ first.value = t.jsxExpressionContainer(t.templateLiteral(quasis, values));
2545
+ }
2546
+ if (styleAttributes.length)
2547
+ transformToObject("style", attributes, styleAttributes);
2548
+ return attributes;
2549
+ }
2550
+ function transformAttributes$1(path, results, info) {
2551
+ const tagName = getTagName(path.node), isSVG = SVGElements.has(tagName), hasChildren = path.node.children.length > 0, attributes = normalizeAttributes(path);
2552
+ let children;
2553
+ attributes.forEach((attribute) => {
2554
+ var _a, _b;
2555
+ const node = attribute.node;
2556
+ let value = node.value, key = t.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name, reservedNameSpace = t.isJSXNamespacedName(node.name) && reservedNameSpaces.has(node.name.namespace.name);
2557
+ if ((t.isJSXNamespacedName(node.name) && reservedNameSpace || ChildProperties.has(key)) && !t.isJSXExpressionContainer(value)) {
2558
+ node.value = value = t.jsxExpressionContainer(
2559
+ value || t.jsxEmptyExpression()
2560
+ );
2561
+ }
2562
+ if (t.isJSXExpressionContainer(value) && (reservedNameSpace || ChildProperties.has(key) || !(t.isStringLiteral(value.expression) || t.isNumericLiteral(value.expression) || t.isBooleanLiteral(value.expression)))) {
2563
+ if (key === "ref" || key.startsWith("use:") || key.startsWith("prop:") || key.startsWith("on"))
2564
+ return;
2565
+ else if (ChildProperties.has(key)) {
2566
+ if (info.hydratable && key === "textContent" && value && value.expression) {
2567
+ value.expression = t.logicalExpression(
2568
+ "||",
2569
+ value.expression,
2570
+ t.stringLiteral(" ")
2571
+ );
2572
+ }
2573
+ if (key === "innerHTML") path.doNotEscape = true;
2574
+ children = value;
2575
+ } else {
2576
+ let doEscape = true;
2577
+ if (key.startsWith("attr:")) key = key.replace("attr:", "");
2578
+ if (BooleanAttributes.has(key)) {
2579
+ results.template.push("");
2580
+ const fn = t.callExpression(
2581
+ registerImportMethod(attribute, "ssrAttribute"),
2582
+ [
2583
+ t.stringLiteral(key),
2584
+ value.expression,
2585
+ t.booleanLiteral(true)
2586
+ ]
2587
+ );
2588
+ (_a = results.templateValues) == null ? void 0 : _a.push(fn);
2589
+ return;
2590
+ }
2591
+ if (key === "style") {
2592
+ if (t.isJSXExpressionContainer(value) && t.isObjectExpression(value.expression) && !value.expression.properties.some((p) => t.isSpreadElement(p))) {
2593
+ const props = value.expression.properties.map(
2594
+ (p, i) => t.callExpression(registerImportMethod(path, "ssrStyleProperty"), [
2595
+ t.stringLiteral(
2596
+ (i ? ";" : "") + (t.isIdentifier(p.key) ? p.key.name : p.key.value) + ":"
2597
+ ),
2598
+ escapeExpression(path, p.value, true, true)
2599
+ ])
2600
+ );
2601
+ let res = props[0];
2602
+ for (let i = 1; i < props.length; i++) {
2603
+ res = t.binaryExpression("+", res, props[i]);
2604
+ }
2605
+ value.expression = res;
2606
+ } else {
2607
+ value.expression = t.callExpression(
2608
+ registerImportMethod(path, "ssrStyle"),
2609
+ [value.expression]
2610
+ );
2611
+ }
2612
+ doEscape = false;
2613
+ }
2614
+ if (key === "classList") {
2615
+ if (t.isObjectExpression(value.expression) && !value.expression.properties.some((p) => t.isSpreadElement(p))) {
2616
+ const values = [], quasis = [t.templateElement({ raw: "" })];
2617
+ transformClasslistObject(path, value.expression, values, quasis);
2618
+ if (!values.length)
2619
+ value.expression = t.stringLiteral(quasis[0].value.raw);
2620
+ else if (values.length === 1 && !quasis[0].value.raw && !quasis[1].value.raw) {
2621
+ value.expression = values[0];
2622
+ } else value.expression = t.templateLiteral(quasis, values);
2623
+ } else {
2624
+ value.expression = t.callExpression(
2625
+ registerImportMethod(path, "ssrClassList"),
2626
+ [value.expression]
2627
+ );
2628
+ }
2629
+ key = "class";
2630
+ doEscape = false;
2631
+ }
2632
+ if (doEscape)
2633
+ value.expression = escapeExpression(
2634
+ path,
2635
+ value.expression,
2636
+ true
2637
+ );
2638
+ if (!doEscape || t.isLiteral(value.expression)) {
2639
+ key = toAttribute(key, isSVG);
2640
+ appendToTemplate(results.template, ` ${key}="`);
2641
+ results.template.push(`"`);
2642
+ (_b = results.templateValues) == null ? void 0 : _b.push(value.expression);
2643
+ } else setAttr$1(attribute, results, key, value.expression, isSVG);
2644
+ }
2645
+ } else {
2646
+ if (key === "$ServerOnly") return;
2647
+ if (t.isJSXExpressionContainer(value)) value = value.expression;
2648
+ key = toAttribute(key, isSVG);
2649
+ const isBoolean = BooleanAttributes.has(key);
2650
+ if (isBoolean && value && value.value !== "" && !value.value) return;
2651
+ appendToTemplate(results.template, ` ${key}`);
2652
+ if (!value) return;
2653
+ let text = isBoolean ? "" : value.value;
2654
+ if (key === "style" || key === "class") {
2655
+ text = trimWhitespace(String(text));
2656
+ if (key === "style") {
2657
+ text = text.replace(/; /g, ";").replace(/: /g, ":");
2658
+ }
2659
+ }
2660
+ appendToTemplate(
2661
+ results.template,
2662
+ // `String(text)` is needed, as text.length will mess up `attr=10>` becomes `attr>` without it
2663
+ String(text) === "" ? `` : `="${escapeHTML(text, true)}"`
2664
+ );
2665
+ }
2666
+ });
2667
+ if (!hasChildren && children) {
2668
+ path.node.children.push(children);
2669
+ }
2670
+ }
2671
+ function transformClasslistObject(path, expr, values, quasis) {
2672
+ expr.properties.forEach((prop, i) => {
2673
+ const isLast = expr.properties.length - 1 === i;
2674
+ let key = prop.key;
2675
+ if (t.isIdentifier(prop.key) && !prop.computed)
2676
+ key = t.stringLiteral(key.name);
2677
+ else if (prop.computed) {
2678
+ key = t.callExpression(registerImportMethod(path, "escape"), [
2679
+ prop.key,
2680
+ t.booleanLiteral(true)
2681
+ ]);
2682
+ } else key = t.stringLiteral(escapeHTML(prop.key.value));
2683
+ if (t.isBooleanLiteral(prop.value)) {
2684
+ if (prop.value.value === true) {
2685
+ if (!prop.computed) {
2686
+ const prev = quasis.pop();
2687
+ quasis.push(
2688
+ t.templateElement({
2689
+ raw: (prev ? prev.value.raw : "") + (i ? " " : "") + `${key.value}` + (isLast ? "" : " ")
2690
+ })
2691
+ );
2692
+ } else {
2693
+ values.push(key);
2694
+ quasis.push(t.templateElement({ raw: isLast ? "" : " " }));
2695
+ }
2696
+ }
2697
+ } else {
2698
+ values.push(t.conditionalExpression(prop.value, key, t.stringLiteral("")));
2699
+ quasis.push(t.templateElement({ raw: isLast ? "" : " " }));
2700
+ }
2701
+ });
2702
+ }
2703
+ function transformChildren$1(path, results, { hydratable }) {
2704
+ const doNotEscape = path.doNotEscape;
2705
+ const filteredChildren = filterChildren(path.get("children"));
2706
+ const multi = checkLength(filteredChildren), markers = hydratable && multi;
2707
+ filteredChildren.forEach((node) => {
2708
+ var _a, _b, _c, _d;
2709
+ if (t.isJSXElement(node.node) && getTagName(node.node) === "head") {
2710
+ const child2 = transformNode(node, {
2711
+ doNotEscape,
2712
+ hydratable: false
2713
+ });
2714
+ registerImportMethod(path, "NoHydration");
2715
+ registerImportMethod(path, "createComponent");
2716
+ results.template.push("");
2717
+ (_a = results.templateValues) == null ? void 0 : _a.push(
2718
+ t.callExpression(t.identifier("_$createComponent"), [
2719
+ t.identifier("_$NoHydration"),
2720
+ t.objectExpression([
2721
+ t.objectMethod(
2722
+ "get",
2723
+ t.identifier("children"),
2724
+ [],
2725
+ t.blockStatement([
2726
+ t.returnStatement(createTemplate$1(path, child2))
2727
+ ])
2728
+ )
2729
+ ])
2730
+ ])
2731
+ );
2732
+ return;
2733
+ }
2734
+ const child = transformNode(node, { doNotEscape });
2735
+ if (!child) return;
2736
+ appendToTemplate(results.template, child.template);
2737
+ (_b = results.templateValues) == null ? void 0 : _b.push.apply(
2738
+ results.templateValues,
2739
+ child.templateValues || []
2740
+ );
2741
+ if (child.exprs.length) {
2742
+ if (!doNotEscape && !child.spreadElement)
2743
+ child.exprs[0] = escapeExpression(path, child.exprs[0]);
2744
+ if (markers && !child.spreadElement) {
2745
+ appendToTemplate(results.template, `<!--$-->`);
2746
+ results.template.push("");
2747
+ (_c = results.templateValues) == null ? void 0 : _c.push(child.exprs[0]);
2748
+ appendToTemplate(results.template, `<!--/-->`);
2749
+ } else {
2750
+ results.template.push("");
2751
+ (_d = results.templateValues) == null ? void 0 : _d.push(child.exprs[0]);
2752
+ }
2753
+ }
2754
+ });
2755
+ }
2756
+ function createElement(path, { topLevel, hydratable }) {
2757
+ const tagName = getTagName(path.node), config = getConfig(path), attributes = normalizeAttributes(path), doNotEscape = path.doNotEscape;
2758
+ const filteredChildren = filterChildren(path.get("children")), multi = checkLength(filteredChildren), markers = hydratable && multi, childNodes = filteredChildren.reduce((memo, path2) => {
2759
+ var _a;
2760
+ if (t.isJSXText(path2.node)) {
2761
+ const v = decode(trimWhitespace((_a = path2.node.extra) == null ? void 0 : _a.raw));
2762
+ if (v.length) memo.push(t.stringLiteral(v));
2763
+ } else {
2764
+ const child = transformNode(path2);
2765
+ if (markers && child.exprs.length && !child.spreadElement)
2766
+ memo.push(t.stringLiteral("<!--$-->"));
2767
+ if (child.exprs.length && !doNotEscape && !child.spreadElement)
2768
+ child.exprs[0] = escapeExpression(path2, child.exprs[0]);
2769
+ memo.push(getCreateTemplate(config, path2, child)(path2, child, true));
2770
+ if (markers && child.exprs.length && !child.spreadElement)
2771
+ memo.push(t.stringLiteral("<!--/-->"));
2772
+ }
2773
+ return memo;
2774
+ }, []);
2775
+ let props;
2776
+ if (attributes.length === 1) {
2777
+ props = [attributes[0].node.argument];
2778
+ } else {
2779
+ props = [];
2780
+ let runningObject = [], dynamicSpread = false, hasChildren = path.node.children.length > 0;
2781
+ attributes.forEach((attribute) => {
2782
+ const node = attribute.node;
2783
+ if (t.isJSXSpreadAttribute(node)) {
2784
+ if (runningObject.length) {
2785
+ props.push(t.objectExpression(runningObject));
2786
+ runningObject = [];
2787
+ }
2788
+ props.push(
2789
+ isDynamic(attribute.get("argument"), {
2790
+ checkMember: true
2791
+ }) && (dynamicSpread = true) ? t.isCallExpression(node.argument) && !node.argument.arguments.length && !t.isCallExpression(node.argument.callee) && !t.isMemberExpression(node.argument.callee) ? node.argument.callee : t.arrowFunctionExpression([], node.argument) : node.argument
2792
+ );
2793
+ } else {
2794
+ const value = node.value || t.booleanLiteral(true), id = convertJSXIdentifier(node.name), key = t.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name;
2795
+ if (hasChildren && key === "children") return;
2796
+ if (key === "ref" || key.startsWith("use:") || key.startsWith("prop:") || key.startsWith("on"))
2797
+ return;
2798
+ if (t.isJSXExpressionContainer(value))
2799
+ if (isDynamic(attribute.get("value").get("expression"), {
2800
+ checkMember: true,
2801
+ checkTags: true
2802
+ })) {
2803
+ let expr = t.arrowFunctionExpression([], value.expression);
2804
+ runningObject.push(
2805
+ t.objectMethod(
2806
+ "get",
2807
+ id,
2808
+ [],
2809
+ t.blockStatement([t.returnStatement(expr.body)]),
2810
+ !t.isValidIdentifier(key)
2811
+ )
2812
+ );
2813
+ } else
2814
+ runningObject.push(t.objectProperty(id, value.expression));
2815
+ else runningObject.push(t.objectProperty(id, value));
2816
+ }
2817
+ });
2818
+ if (runningObject.length || !props.length)
2819
+ props.push(t.objectExpression(runningObject));
2820
+ if (props.length > 1 || dynamicSpread) {
2821
+ props = [
2822
+ t.callExpression(registerImportMethod(path, "mergeProps"), props)
2823
+ ];
2824
+ }
2825
+ }
2826
+ const exprs = [
2827
+ t.callExpression(registerImportMethod(path, "ssrElement"), [
2828
+ t.stringLiteral(tagName),
2829
+ props[0],
2830
+ childNodes.length ? hydratable ? t.arrowFunctionExpression(
2831
+ [],
2832
+ childNodes.length === 1 ? childNodes[0] : t.arrayExpression(childNodes)
2833
+ ) : childNodes.length === 1 ? childNodes[0] : t.arrayExpression(childNodes) : t.identifier("undefined"),
2834
+ t.booleanLiteral(Boolean(topLevel && config.hydratable))
2835
+ ])
2836
+ ];
2837
+ return { exprs, template: "", spreadElement: true };
2838
+ }
2839
+
2840
+ function transformElement$1(path, _info) {
2841
+ var _a;
2842
+ let tagName = getTagName(path.node), results = {
2843
+ id: path.scope.generateUidIdentifier("el$"),
2844
+ declarations: [],
2845
+ exprs: [],
2846
+ dynamics: [],
2847
+ postExprs: [],
2848
+ tagName,
2849
+ renderer: "universal",
2850
+ template: ""
2851
+ };
2852
+ (_a = results.declarations) == null ? void 0 : _a.push(
2853
+ t.variableDeclarator(
2854
+ results.id,
2855
+ t.callExpression(
2856
+ registerImportMethod(
2857
+ path,
2858
+ "createElement",
2859
+ getRendererConfig(path, "universal").moduleName
2860
+ ),
2861
+ [t.stringLiteral(tagName)]
2862
+ )
2863
+ )
2864
+ );
2865
+ transformAttributes(path, results);
2866
+ transformChildren(path, results);
2867
+ return results;
2868
+ }
2869
+ function transformAttributes(path, results) {
2870
+ let children, spreadExpr;
2871
+ let attributes = path.get("openingElement").get("attributes");
2872
+ const elem = results.id, hasChildren = path.node.children.length > 0, config = getConfig(path);
2873
+ if (attributes.some((attribute) => t.isJSXSpreadAttribute(attribute.node))) {
2874
+ [attributes, spreadExpr] = processSpreads(path, attributes, {
2875
+ elem,
2876
+ hasChildren,
2877
+ wrapConditionals: config.wrapConditionals
2878
+ });
2879
+ path.get("openingElement").set(
2880
+ "attributes",
2881
+ attributes.map((a) => a.node)
2882
+ );
2883
+ }
2884
+ path.get("openingElement").get("attributes").forEach((attribute) => {
2885
+ var _a;
2886
+ const node = attribute.node;
2887
+ let value = node.value, key = t.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name, reservedNameSpace = t.isJSXNamespacedName(node.name) && node.name.namespace.name === "use";
2888
+ if (t.isJSXNamespacedName(node.name) && reservedNameSpace && !t.isJSXExpressionContainer(value)) {
2889
+ node.value = value = t.jsxExpressionContainer(
2890
+ value || t.jsxEmptyExpression()
2891
+ );
2892
+ }
2893
+ if (t.isJSXExpressionContainer(value)) {
2894
+ if (key === "ref") {
2895
+ while (t.isTSNonNullExpression(value.expression) || t.isTSAsExpression(value.expression)) {
2896
+ value.expression = value.expression.expression;
2897
+ }
2898
+ let binding, isConstant = t.isIdentifier(value.expression) && (binding = path.scope.getBinding(value.expression.name)) && (binding.kind === "const" || binding.kind === "module");
2899
+ if (!isConstant && t.isLVal(value.expression)) {
2900
+ const refIdentifier = path.scope.generateUidIdentifier("_ref$");
2901
+ results.exprs.unshift(
2902
+ t.variableDeclaration("var", [
2903
+ t.variableDeclarator(refIdentifier, value.expression)
2904
+ ]),
2905
+ t.expressionStatement(
2906
+ t.conditionalExpression(
2907
+ t.binaryExpression(
2908
+ "===",
2909
+ t.unaryExpression("typeof", refIdentifier),
2910
+ t.stringLiteral("function")
2911
+ ),
2912
+ t.callExpression(
2913
+ registerImportMethod(
2914
+ path,
2915
+ "use",
2916
+ getRendererConfig(path, "universal").moduleName
2917
+ ),
2918
+ [refIdentifier, elem]
2919
+ ),
2920
+ t.assignmentExpression("=", value.expression, elem)
2921
+ )
2922
+ )
2923
+ );
2924
+ } else if (isConstant || t.isFunction(value.expression)) {
2925
+ results.exprs.unshift(
2926
+ t.expressionStatement(
2927
+ t.callExpression(
2928
+ registerImportMethod(
2929
+ path,
2930
+ "use",
2931
+ getRendererConfig(path, "universal").moduleName
2932
+ ),
2933
+ [value.expression, elem]
2934
+ )
2935
+ )
2936
+ );
2937
+ } else {
2938
+ const refIdentifier = path.scope.generateUidIdentifier("_ref$");
2939
+ results.exprs.unshift(
2940
+ t.variableDeclaration("var", [
2941
+ t.variableDeclarator(refIdentifier, value.expression)
2942
+ ]),
2943
+ t.expressionStatement(
2944
+ t.logicalExpression(
2945
+ "&&",
2946
+ t.binaryExpression(
2947
+ "===",
2948
+ t.unaryExpression("typeof", refIdentifier),
2949
+ t.stringLiteral("function")
2950
+ ),
2951
+ t.callExpression(
2952
+ registerImportMethod(
2953
+ path,
2954
+ "use",
2955
+ getRendererConfig(path, "universal").moduleName
2956
+ ),
2957
+ [refIdentifier, elem]
2958
+ )
2959
+ )
2960
+ )
2961
+ );
2962
+ }
2963
+ } else if (key.startsWith("use:")) {
2964
+ node.name.name.type = "Identifier";
2965
+ results.exprs.unshift(
2966
+ t.expressionStatement(
2967
+ t.callExpression(
2968
+ registerImportMethod(
2969
+ path,
2970
+ "use",
2971
+ getRendererConfig(path, "universal").moduleName
2972
+ ),
2973
+ [
2974
+ node.name.name,
2975
+ elem,
2976
+ t.arrowFunctionExpression(
2977
+ [],
2978
+ t.isJSXEmptyExpression(value.expression) ? t.booleanLiteral(true) : value.expression
2979
+ )
2980
+ ]
2981
+ )
2982
+ )
2983
+ );
2984
+ } else if (key === "children") {
2985
+ children = value;
2986
+ } else if (config.effectWrapper && isDynamic(attribute.get("value").get("expression"), {
2987
+ checkMember: true
2988
+ })) {
2989
+ (_a = results.dynamics) == null ? void 0 : _a.push({
2990
+ elem,
2991
+ key,
2992
+ value: value.expression
2993
+ });
2994
+ } else {
2995
+ results.exprs.push(
2996
+ t.expressionStatement(
2997
+ setAttr(attribute, elem, key, value.expression)
2998
+ )
2999
+ );
3000
+ }
3001
+ } else {
3002
+ results.exprs.push(
3003
+ t.expressionStatement(setAttr(attribute, elem, key, value))
3004
+ );
3005
+ }
3006
+ });
3007
+ if (spreadExpr) results.exprs.push(spreadExpr);
3008
+ if (!hasChildren && children) {
3009
+ path.node.children.push(children);
3010
+ }
3011
+ }
3012
+ function setAttr(path, elem, name, value, { prevId } = {}) {
3013
+ if (!value) value = t.booleanLiteral(true);
3014
+ return t.callExpression(
3015
+ registerImportMethod(
3016
+ path,
3017
+ "setProp",
3018
+ getRendererConfig(path, "universal").moduleName
3019
+ ),
3020
+ prevId ? [elem, t.stringLiteral(name), value, prevId] : [elem, t.stringLiteral(name), value]
3021
+ );
3022
+ }
3023
+ function transformChildren(path, results) {
3024
+ const filteredChildren = filterChildren(path.get("children")), multi = checkLength(filteredChildren), childNodes = filteredChildren.map(transformNode).reduce((memo, child) => {
3025
+ if (!child) return memo;
3026
+ const i = memo.length;
3027
+ if (child.text && i && memo[i - 1].text) {
3028
+ memo[i - 1].template += child.template;
3029
+ memo[i - 1].templateWithClosingTags += child.templateWithClosingTags || child.template;
3030
+ } else memo.push(child);
3031
+ return memo;
3032
+ }, []);
3033
+ const appends = [];
3034
+ childNodes.forEach((child, index) => {
3035
+ var _a, _b, _c;
3036
+ if (!child) return;
3037
+ if (child.tagName && child.renderer !== "universal") {
3038
+ throw new Error(`<${child.tagName}> is not supported in <${getTagName(path.node)}>.
3039
+ Wrap the usage with a component that would render this element, eg. Canvas`);
3040
+ }
3041
+ if (child.id) {
3042
+ let insertNode = registerImportMethod(
3043
+ path,
3044
+ "insertNode",
3045
+ getRendererConfig(path, "universal").moduleName
3046
+ );
3047
+ let insert = child.id;
3048
+ if (child.text) {
3049
+ let createTextNode = registerImportMethod(
3050
+ path,
3051
+ "createTextNode",
3052
+ getRendererConfig(path, "universal").moduleName
3053
+ );
3054
+ if (multi) {
3055
+ (_a = results.declarations) == null ? void 0 : _a.push(
3056
+ t.variableDeclarator(
3057
+ child.id,
3058
+ t.callExpression(createTextNode, [
3059
+ t.templateLiteral(
3060
+ [
3061
+ t.templateElement({
3062
+ raw: escapeStringForTemplate(child.template)
3063
+ })
3064
+ ],
3065
+ []
3066
+ )
3067
+ ])
3068
+ )
3069
+ );
3070
+ } else
3071
+ insert = t.callExpression(createTextNode, [
3072
+ t.templateLiteral(
3073
+ [
3074
+ t.templateElement({
3075
+ raw: escapeStringForTemplate(child.template)
3076
+ })
3077
+ ],
3078
+ []
3079
+ )
3080
+ ]);
3081
+ }
3082
+ appends.push(
3083
+ t.expressionStatement(
3084
+ t.callExpression(insertNode, [results.id, insert])
3085
+ )
3086
+ );
3087
+ (_b = results.declarations) == null ? void 0 : _b.push(...child.declarations);
3088
+ results.exprs.push(...child.exprs);
3089
+ (_c = results.dynamics) == null ? void 0 : _c.push(...child.dynamics);
3090
+ } else if (child.exprs.length) {
3091
+ let insert = registerImportMethod(
3092
+ path,
3093
+ "insert",
3094
+ getRendererConfig(path, "universal").moduleName
3095
+ );
3096
+ if (multi) {
3097
+ results.exprs.push(
3098
+ t.expressionStatement(
3099
+ t.callExpression(insert, [
3100
+ results.id,
3101
+ child.exprs[0],
3102
+ nextChild(childNodes, index) || t.nullLiteral()
3103
+ ])
3104
+ )
3105
+ );
3106
+ } else {
3107
+ results.exprs.push(
3108
+ t.expressionStatement(
3109
+ t.callExpression(insert, [results.id, child.exprs[0]])
3110
+ )
3111
+ );
3112
+ }
3113
+ }
3114
+ });
3115
+ results.exprs.unshift(...appends);
3116
+ }
3117
+ function nextChild(children, index) {
3118
+ return children[index + 1] && (children[index + 1].id || nextChild(children, index + 1));
3119
+ }
3120
+ function processSpreads(path, attributes, { elem, hasChildren, wrapConditionals }) {
3121
+ const filteredAttributes = [];
3122
+ const spreadArgs = [];
3123
+ let runningObject = [];
3124
+ let dynamicSpread = false;
3125
+ let firstSpread = false;
3126
+ attributes.forEach((attribute) => {
3127
+ const node = attribute.node;
3128
+ const key = !t.isJSXSpreadAttribute(node) && (t.isJSXNamespacedName(node.name) ? `${node.name.namespace.name}:${node.name.name.name}` : node.name.name);
3129
+ if (t.isJSXSpreadAttribute(node)) {
3130
+ firstSpread = true;
3131
+ if (runningObject.length) {
3132
+ spreadArgs.push(t.objectExpression(runningObject));
3133
+ runningObject = [];
3134
+ }
3135
+ spreadArgs.push(
3136
+ isDynamic(attribute.get("argument"), {
3137
+ checkMember: true
3138
+ }) && (dynamicSpread = true) ? t.isCallExpression(node.argument) && !node.argument.arguments.length && !t.isCallExpression(node.argument.callee) && !t.isMemberExpression(node.argument.callee) ? node.argument.callee : t.arrowFunctionExpression([], node.argument) : node.argument
3139
+ );
3140
+ } else if ((firstSpread || t.isJSXExpressionContainer(node.value) && isDynamic(attribute.get("value").get("expression"), {
3141
+ checkMember: true
3142
+ })) && canNativeSpread(key, { checkNameSpaces: true })) {
3143
+ const isContainer = t.isJSXExpressionContainer(node.value);
3144
+ const dynamic = isContainer && isDynamic(attribute.get("value").get("expression"), {
3145
+ checkMember: true
3146
+ });
3147
+ if (dynamic) {
3148
+ const id = convertJSXIdentifier(node.name);
3149
+ let expr = wrapConditionals && (t.isLogicalExpression(node.value.expression) || t.isConditionalExpression(node.value.expression)) ? transformCondition(attribute.get("value").get("expression"), true) : t.arrowFunctionExpression([], node.value.expression);
3150
+ runningObject.push(
3151
+ t.objectMethod(
3152
+ "get",
3153
+ id,
3154
+ [],
3155
+ t.blockStatement([t.returnStatement(expr.body)]),
3156
+ !t.isValidIdentifier(key)
3157
+ )
3158
+ );
3159
+ } else {
3160
+ runningObject.push(
3161
+ t.objectProperty(
3162
+ t.stringLiteral(key),
3163
+ isContainer ? node.value.expression : node.value || t.booleanLiteral(true)
3164
+ )
3165
+ );
3166
+ }
3167
+ } else filteredAttributes.push(attribute);
3168
+ });
3169
+ if (runningObject.length) {
3170
+ spreadArgs.push(t.objectExpression(runningObject));
3171
+ }
3172
+ const props = spreadArgs.length === 1 && !dynamicSpread ? spreadArgs[0] : t.callExpression(registerImportMethod(path, "mergeProps"), spreadArgs);
3173
+ return [
3174
+ filteredAttributes,
3175
+ t.expressionStatement(
3176
+ t.callExpression(
3177
+ registerImportMethod(
3178
+ path,
3179
+ "spread",
3180
+ getRendererConfig(path, "universal").moduleName
3181
+ ),
3182
+ [elem, props, t.booleanLiteral(hasChildren)]
3183
+ )
3184
+ )
3185
+ ];
3186
+ }
3187
+
3188
+ function createTemplate(path, result, wrap) {
3189
+ var _a, _b;
3190
+ const config = getConfig(path);
3191
+ if (result.id) {
3192
+ result.decl = t.variableDeclaration("var", result.declarations);
3193
+ if (!(result.exprs.length || ((_a = result.dynamics) == null ? void 0 : _a.length) || ((_b = result.postExprs) == null ? void 0 : _b.length)) && result.decl.declarations.length === 1) {
3194
+ return result.decl.declarations[0].init;
3195
+ } else {
3196
+ return t.callExpression(
3197
+ t.arrowFunctionExpression(
3198
+ [],
3199
+ t.blockStatement([
3200
+ result.decl,
3201
+ ...result.exprs.concat(
3202
+ wrapDynamics(path, result.dynamics) || [],
3203
+ result.postExprs || []
3204
+ ),
3205
+ t.returnStatement(result.id)
3206
+ ])
3207
+ ),
3208
+ []
3209
+ );
3210
+ }
3211
+ }
3212
+ if (wrap && result.dynamic && config.memoWrapper) {
3213
+ return t.callExpression(registerImportMethod(path, config.memoWrapper), [
3214
+ result.exprs[0]
3215
+ ]);
3216
+ }
3217
+ return result.exprs[0];
3218
+ }
3219
+ function wrapDynamics(path, dynamics) {
3220
+ if (!dynamics.length) return;
3221
+ const config = getConfig(path);
3222
+ const effectWrapperId = registerImportMethod(path, config.effectWrapper);
3223
+ if (dynamics.length === 1) {
3224
+ const prevValue = t.identifier("_$p");
3225
+ const firstDynamic = dynamics[0];
3226
+ return t.expressionStatement(
3227
+ t.callExpression(effectWrapperId, [
3228
+ t.arrowFunctionExpression(
3229
+ [prevValue],
3230
+ setAttr(
3231
+ path,
3232
+ firstDynamic.elem,
3233
+ firstDynamic.key,
3234
+ firstDynamic.value,
3235
+ {
3236
+ prevId: prevValue
3237
+ }
3238
+ )
3239
+ )
3240
+ ])
3241
+ );
3242
+ }
3243
+ const prevId = t.identifier("_p$");
3244
+ const declarations = [];
3245
+ const statements = [];
3246
+ const properties = [];
3247
+ dynamics.forEach(({ elem, key, value }, index) => {
3248
+ const varIdent = path.scope.generateUidIdentifier("v$");
3249
+ const propIdent = t.identifier(getNumberedId(index));
3250
+ const propMember = t.memberExpression(prevId, propIdent);
3251
+ properties.push(propIdent);
3252
+ declarations.push(t.variableDeclarator(varIdent, value));
3253
+ statements.push(
3254
+ t.expressionStatement(
3255
+ t.logicalExpression(
3256
+ "&&",
3257
+ t.binaryExpression("!==", varIdent, propMember),
3258
+ t.assignmentExpression(
3259
+ "=",
3260
+ propMember,
3261
+ setAttr(path, elem, key, varIdent, {
3262
+ prevId: propMember
3263
+ })
3264
+ )
3265
+ )
3266
+ )
3267
+ );
3268
+ });
3269
+ return t.expressionStatement(
3270
+ t.callExpression(effectWrapperId, [
3271
+ t.arrowFunctionExpression(
3272
+ [prevId],
3273
+ t.blockStatement([
3274
+ t.variableDeclaration("var", declarations),
3275
+ ...statements,
3276
+ t.returnStatement(prevId)
3277
+ ])
3278
+ ),
3279
+ t.objectExpression(
3280
+ properties.map((id) => t.objectProperty(id, t.identifier("undefined")))
3281
+ )
3282
+ ])
3283
+ );
3284
+ }
3285
+
3286
+ function convertComponentIdentifier(node) {
3287
+ if (t.isJSXIdentifier(node)) {
3288
+ if (node.name === "this") return t.thisExpression();
3289
+ if (t.isValidIdentifier(node.name)) {
3290
+ node.type = "Identifier";
3291
+ } else return t.stringLiteral(node.name);
3292
+ } else if (t.isJSXMemberExpression(node)) {
3293
+ const prop = convertComponentIdentifier(node.property);
3294
+ const computed = t.isStringLiteral(prop);
3295
+ return t.memberExpression(
3296
+ convertComponentIdentifier(node.object),
3297
+ prop,
3298
+ computed
3299
+ );
3300
+ }
3301
+ return node;
3302
+ }
3303
+ function transformComponent(path) {
3304
+ let exprs = [], config = getConfig(path), tagId = convertComponentIdentifier(path.node.openingElement.name), props = [], runningObject = [], dynamicSpread = false, hasChildren = path.node.children.length > 0;
3305
+ if (config.builtIns.indexOf(tagId.name) > -1 && !path.scope.hasBinding(tagId.name)) {
3306
+ const newTagId = registerImportMethod(path, tagId.name);
3307
+ tagId.name = newTagId.name;
3308
+ }
3309
+ path.get("openingElement").get("attributes").forEach((attribute) => {
3310
+ const node = attribute.node;
3311
+ if (t.isJSXSpreadAttribute(node)) {
3312
+ if (runningObject.length) {
3313
+ props.push(t.objectExpression(runningObject));
3314
+ runningObject = [];
3315
+ }
3316
+ props.push(
3317
+ isDynamic(attribute.get("argument"), {
3318
+ checkMember: true
3319
+ }) && (dynamicSpread = true) ? t.isCallExpression(node.argument) && !node.argument.arguments.length && !t.isCallExpression(node.argument.callee) && !t.isMemberExpression(node.argument.callee) ? node.argument.callee : t.arrowFunctionExpression([], node.argument) : node.argument
3320
+ );
3321
+ } else {
3322
+ const value = (t.isStringLiteral(node.value) ? t.stringLiteral(node.value.value) : node.value) || t.booleanLiteral(true), id = convertJSXIdentifier(node.name), key = id.name;
3323
+ if (hasChildren && key === "children") return;
3324
+ if (t.isJSXExpressionContainer(value))
3325
+ if (key === "ref") {
3326
+ if (config.generate === "ssr") return;
3327
+ while (t.isTSNonNullExpression(value.expression) || t.isTSAsExpression(value.expression) || t.isTSSatisfiesExpression(value.expression)) {
3328
+ value.expression = value.expression.expression;
3329
+ }
3330
+ let binding, isConstant = t.isIdentifier(value.expression) && (binding = path.scope.getBinding(value.expression.name)) && (binding.kind === "const" || binding.kind === "module");
3331
+ if (!isConstant && t.isLVal(value.expression)) {
3332
+ const refIdentifier = path.scope.generateUidIdentifier("_ref$");
3333
+ runningObject.push(
3334
+ t.objectMethod(
3335
+ "method",
3336
+ t.identifier("ref"),
3337
+ [t.identifier("r$")],
3338
+ t.blockStatement([
3339
+ t.variableDeclaration("var", [
3340
+ t.variableDeclarator(refIdentifier, value.expression)
3341
+ ]),
3342
+ t.expressionStatement(
3343
+ t.conditionalExpression(
3344
+ t.binaryExpression(
3345
+ "===",
3346
+ t.unaryExpression("typeof", refIdentifier),
3347
+ t.stringLiteral("function")
3348
+ ),
3349
+ t.callExpression(refIdentifier, [t.identifier("r$")]),
3350
+ t.assignmentExpression(
3351
+ "=",
3352
+ value.expression,
3353
+ t.identifier("r$")
3354
+ )
3355
+ )
3356
+ )
3357
+ ])
3358
+ )
3359
+ );
3360
+ } else if (!isConstant && t.isOptionalMemberExpression(value.expression) && t.isIdentifier(value.expression.object) && t.isIdentifier(value.expression.property)) {
3361
+ const refIdentifier = path.scope.generateUidIdentifier("_ref$");
3362
+ runningObject.push(
3363
+ t.objectMethod(
3364
+ "method",
3365
+ t.identifier("ref"),
3366
+ [t.identifier("r$")],
3367
+ t.blockStatement([
3368
+ t.variableDeclaration("var", [
3369
+ t.variableDeclarator(refIdentifier, value.expression)
3370
+ ]),
3371
+ t.expressionStatement(
3372
+ t.conditionalExpression(
3373
+ t.binaryExpression(
3374
+ "===",
3375
+ t.unaryExpression("typeof", refIdentifier),
3376
+ t.stringLiteral("function")
3377
+ ),
3378
+ t.callExpression(refIdentifier, [t.identifier("r$")]),
3379
+ t.logicalExpression(
3380
+ "&&",
3381
+ t.unaryExpression(
3382
+ "!",
3383
+ t.unaryExpression(
3384
+ "!",
3385
+ t.identifier(value.expression.object.name)
3386
+ )
3387
+ ),
3388
+ t.assignmentExpression(
3389
+ "=",
3390
+ t.memberExpression(
3391
+ t.identifier(value.expression.object.name),
3392
+ t.identifier(value.expression.property.name)
3393
+ ),
3394
+ t.identifier("r$")
3395
+ )
3396
+ )
3397
+ )
3398
+ )
3399
+ ])
3400
+ )
3401
+ );
3402
+ } else if (isConstant || t.isFunction(value.expression)) {
3403
+ runningObject.push(
3404
+ t.objectProperty(
3405
+ t.identifier("ref"),
3406
+ value.expression
3407
+ )
3408
+ );
3409
+ } else if (t.isCallExpression(value.expression)) {
3410
+ const refIdentifier = path.scope.generateUidIdentifier("_ref$");
3411
+ runningObject.push(
3412
+ t.objectMethod(
3413
+ "method",
3414
+ t.identifier("ref"),
3415
+ [t.identifier("r$")],
3416
+ t.blockStatement([
3417
+ t.variableDeclaration("var", [
3418
+ t.variableDeclarator(refIdentifier, value.expression)
3419
+ ]),
3420
+ t.expressionStatement(
3421
+ t.logicalExpression(
3422
+ "&&",
3423
+ t.binaryExpression(
3424
+ "===",
3425
+ t.unaryExpression("typeof", refIdentifier),
3426
+ t.stringLiteral("function")
3427
+ ),
3428
+ t.callExpression(refIdentifier, [t.identifier("r$")])
3429
+ )
3430
+ )
3431
+ ])
3432
+ )
3433
+ );
3434
+ }
3435
+ } else if (isDynamic(attribute.get("value").get("expression"), {
3436
+ checkMember: true,
3437
+ checkTags: true
3438
+ })) {
3439
+ if (config.wrapConditionals && config.generate !== "ssr" && (t.isLogicalExpression(value.expression) || t.isConditionalExpression(value.expression))) {
3440
+ const expr = transformCondition(
3441
+ attribute.get("value").get("expression"),
3442
+ true
3443
+ );
3444
+ runningObject.push(
3445
+ t.objectMethod(
3446
+ "get",
3447
+ id,
3448
+ [],
3449
+ t.blockStatement([t.returnStatement(expr.body)]),
3450
+ !t.isValidIdentifier(key)
3451
+ )
3452
+ );
3453
+ } else if (t.isCallExpression(value.expression) && t.isArrowFunctionExpression(value.expression.callee) && value.expression.callee.params.length === 0) {
3454
+ const callee = value.expression.callee;
3455
+ const body = t.isBlockStatement(callee.body) ? callee.body : t.blockStatement([t.returnStatement(callee.body)]);
3456
+ runningObject.push(
3457
+ t.objectMethod("get", id, [], body, !t.isValidIdentifier(key))
3458
+ );
3459
+ } else {
3460
+ runningObject.push(
3461
+ t.objectMethod(
3462
+ "get",
3463
+ id,
3464
+ [],
3465
+ t.blockStatement([
3466
+ t.returnStatement(value.expression)
3467
+ ]),
3468
+ !t.isValidIdentifier(key)
3469
+ )
3470
+ );
3471
+ }
3472
+ } else
3473
+ runningObject.push(t.objectProperty(id, value.expression));
3474
+ else runningObject.push(t.objectProperty(id, value));
3475
+ }
3476
+ });
3477
+ const childResult = transformComponentChildren(path.get("children"), config);
3478
+ if (childResult && childResult[0]) {
3479
+ if (childResult[1]) {
3480
+ const body = t.isCallExpression(childResult[0]) && t.isFunction(childResult[0].arguments[0]) ? childResult[0].arguments[0].body : childResult[0].body ? childResult[0].body : childResult[0];
3481
+ runningObject.push(
3482
+ t.objectMethod(
3483
+ "get",
3484
+ t.identifier("children"),
3485
+ [],
3486
+ t.isExpression(body) ? t.blockStatement([t.returnStatement(body)]) : body
3487
+ )
3488
+ );
3489
+ } else
3490
+ runningObject.push(
3491
+ t.objectProperty(t.identifier("children"), childResult[0])
3492
+ );
3493
+ }
3494
+ if (runningObject.length || !props.length)
3495
+ props.push(t.objectExpression(runningObject));
3496
+ if (props.length > 1 || dynamicSpread) {
3497
+ props = [t.callExpression(registerImportMethod(path, "mergeProps"), props)];
3498
+ }
3499
+ const componentArgs = [tagId, props[0]];
3500
+ exprs.push(
3501
+ t.callExpression(
3502
+ registerImportMethod(path, "createComponent"),
3503
+ componentArgs
3504
+ )
3505
+ );
3506
+ if (exprs.length > 1) {
3507
+ const ret = exprs.pop();
3508
+ exprs = [
3509
+ t.callExpression(
3510
+ t.arrowFunctionExpression(
3511
+ [],
3512
+ t.blockStatement([...exprs, t.returnStatement(ret)])
3513
+ ),
3514
+ []
3515
+ )
3516
+ ];
3517
+ }
3518
+ return { exprs, template: "", component: true };
3519
+ }
3520
+ function transformComponentChildren(children, config) {
3521
+ const filteredChildren = filterChildren(children);
3522
+ if (!filteredChildren.length) return;
3523
+ let dynamic = false;
3524
+ let pathNodes = [];
3525
+ let transformedChildren = filteredChildren.reduce((memo, path) => {
3526
+ if (t.isJSXText(path.node)) {
3527
+ const v = decode(trimWhitespace(path.node.extra.raw));
3528
+ if (v.length) {
3529
+ pathNodes.push(path.node);
3530
+ memo.push(t.stringLiteral(v));
3531
+ }
3532
+ } else {
3533
+ const child = transformNode(path, {
3534
+ topLevel: true,
3535
+ componentChild: true,
3536
+ lastElement: true
3537
+ });
3538
+ dynamic = dynamic || (child == null ? void 0 : child.dynamic) || false;
3539
+ if (config.generate === "ssr" && filteredChildren.length > 1 && (child == null ? void 0 : child.dynamic) && t.isFunction(child == null ? void 0 : child.exprs[0])) {
3540
+ child.exprs[0] = child.exprs[0].body;
3541
+ }
3542
+ pathNodes.push(path.node);
3543
+ memo.push(
3544
+ getCreateTemplate(config, path, child)(
3545
+ path,
3546
+ child,
3547
+ filteredChildren.length > 1
3548
+ )
3549
+ );
3550
+ }
3551
+ return memo;
3552
+ }, []);
3553
+ if (transformedChildren.length === 1) {
3554
+ transformedChildren = transformedChildren[0];
3555
+ if (!t.isJSXExpressionContainer(pathNodes[0]) && !t.isJSXSpreadChild(pathNodes[0]) && !t.isJSXText(pathNodes[0])) {
3556
+ transformedChildren = t.isCallExpression(transformedChildren) && !transformedChildren.arguments.length && !t.isIdentifier(transformedChildren.callee) ? transformedChildren.callee : t.arrowFunctionExpression([], transformedChildren);
3557
+ dynamic = true;
3558
+ }
3559
+ } else {
3560
+ transformedChildren = t.arrowFunctionExpression(
3561
+ [],
3562
+ t.arrayExpression(transformedChildren)
3563
+ );
3564
+ dynamic = true;
3565
+ }
3566
+ return [transformedChildren, dynamic];
3567
+ }
3568
+
3569
+ function transformFragmentChildren(children, results, config) {
3570
+ const filteredChildren = filterChildren(children), childNodes = filteredChildren.reduce((memo, path) => {
3571
+ if (t.isJSXText(path.node)) {
3572
+ const v = decode(trimWhitespace(path.node.extra.raw));
3573
+ if (v.length) memo.push(t.stringLiteral(v));
3574
+ } else {
3575
+ const child = transformNode(path, {
3576
+ topLevel: true,
3577
+ fragmentChild: true,
3578
+ lastElement: true
3579
+ });
3580
+ memo.push(
3581
+ getCreateTemplate(config, path, child)(
3582
+ path,
3583
+ child,
3584
+ true
3585
+ )
3586
+ );
3587
+ }
3588
+ return memo;
3589
+ }, []);
3590
+ results.exprs.push(
3591
+ childNodes.length === 1 ? childNodes[0] : t.arrayExpression(childNodes)
3592
+ );
3593
+ }
3594
+
3595
+ function transformJSX(path, state) {
3596
+ const s = state;
3597
+ if (s.skip) return;
3598
+ const config = getConfig(path);
3599
+ const replace = transformThis(path);
3600
+ const result = transformNode(
3601
+ path,
3602
+ t.isJSXFragment(path.node) ? {} : {
3603
+ topLevel: true,
3604
+ lastElement: true
3605
+ }
3606
+ );
3607
+ const template = getCreateTemplate(config, path, result);
3608
+ path.replaceWith(replace(template(path, result, false)));
3609
+ path.traverse({
3610
+ enter(path2) {
3611
+ if (path2.node.leadingComments && path2.node.leadingComments[0] && path2.node.leadingComments[0].value.trim() === config.staticMarker) {
3612
+ path2.node.leadingComments.shift();
3613
+ }
3614
+ }
3615
+ });
3616
+ }
3617
+ function getTargetFunctionParent(path, parent) {
3618
+ let current = path.scope.getFunctionParent();
3619
+ while (current !== parent && (current == null ? void 0 : current.path.isArrowFunctionExpression())) {
3620
+ current = current.path.parentPath.scope.getFunctionParent();
3621
+ }
3622
+ return current;
3623
+ }
3624
+ function transformThis(path) {
3625
+ const parent = path.scope.getFunctionParent();
3626
+ let thisId;
3627
+ path.traverse({
3628
+ ThisExpression(path2) {
3629
+ const current = getTargetFunctionParent(path2, parent);
3630
+ if (current === parent) {
3631
+ thisId || (thisId = path2.scope.generateUidIdentifier("self$"));
3632
+ path2.replaceWith(thisId);
3633
+ }
3634
+ },
3635
+ JSXElement(path2) {
3636
+ let source = path2.get("openingElement").get("name");
3637
+ while (source.isJSXMemberExpression()) {
3638
+ source = source.get("object");
3639
+ }
3640
+ if (source.isJSXIdentifier() && source.node.name === "this") {
3641
+ const current = getTargetFunctionParent(path2, parent);
3642
+ if (current === parent) {
3643
+ thisId || (thisId = path2.scope.generateUidIdentifier("self$"));
3644
+ source.replaceWith(t.jsxIdentifier(thisId.name));
3645
+ if (path2.node.closingElement) {
3646
+ path2.node.closingElement.name = path2.node.openingElement.name;
3647
+ }
3648
+ }
3649
+ }
3650
+ }
3651
+ });
3652
+ return (node) => {
3653
+ if (thisId) {
3654
+ if (!parent || parent.block.type === "ClassMethod") {
3655
+ const decl = t.variableDeclaration("const", [
3656
+ t.variableDeclarator(thisId, t.thisExpression())
3657
+ ]);
3658
+ if (parent) {
3659
+ const stmt = path.getStatementParent();
3660
+ stmt == null ? void 0 : stmt.insertBefore(decl);
3661
+ } else {
3662
+ return t.callExpression(
3663
+ t.arrowFunctionExpression(
3664
+ [],
3665
+ t.blockStatement([decl, t.returnStatement(node)])
3666
+ ),
3667
+ []
3668
+ );
3669
+ }
3670
+ } else {
3671
+ parent.push({
3672
+ id: thisId,
3673
+ init: t.thisExpression(),
3674
+ kind: "const"
3675
+ });
3676
+ }
3677
+ }
3678
+ return node;
3679
+ };
3680
+ }
3681
+ function transformNode(path, info = {}) {
3682
+ const config = getConfig(path);
3683
+ const node = path.node;
3684
+ let staticValue;
3685
+ if (t.isJSXElement(node) && isJSXElementPath(path)) {
3686
+ return transformElement(config, path, info);
3687
+ } else if (t.isJSXFragment(node)) {
3688
+ let results = { template: "", declarations: [], exprs: [], dynamics: [] };
3689
+ transformFragmentChildren(path.get("children"), results, config);
3690
+ return results;
3691
+ } else if (t.isJSXText(node) || (staticValue = getStaticExpression(path)) !== false) {
3692
+ const text = staticValue !== void 0 ? info.doNotEscape ? staticValue.toString() : escapeHTML(staticValue.toString()) : trimWhitespace(node.extra.raw);
3693
+ if (!text.length) return null;
3694
+ const results = {
3695
+ template: text,
3696
+ declarations: [],
3697
+ exprs: [],
3698
+ dynamics: [],
3699
+ postExprs: [],
3700
+ text: true
3701
+ };
3702
+ if (!info.skipId && config.generate !== "ssr")
3703
+ results.id = path.scope.generateUidIdentifier("el$");
3704
+ return results;
3705
+ } else if (t.isJSXExpressionContainer(node)) {
3706
+ if (t.isJSXEmptyExpression(node.expression)) return null;
3707
+ if (!isDynamic(path.get("expression"), {
3708
+ checkMember: true,
3709
+ checkTags: !!info.componentChild,
3710
+ native: !info.componentChild
3711
+ })) {
3712
+ return { exprs: [node.expression], template: "" };
3713
+ }
3714
+ const expr = config.wrapConditionals && config.generate !== "ssr" && (t.isLogicalExpression(node.expression) || t.isConditionalExpression(node.expression)) ? transformCondition(
3715
+ path.get("expression"),
3716
+ info.componentChild || info.fragmentChild
3717
+ ) : !info.componentChild && (config.generate !== "ssr" || info.fragmentChild) && t.isCallExpression(node.expression) && !t.isCallExpression(node.expression.callee) && !t.isMemberExpression(node.expression.callee) && node.expression.arguments.length === 0 ? node.expression.callee : t.arrowFunctionExpression([], node.expression);
3718
+ return {
3719
+ exprs: Array.isArray(expr) ? [
3720
+ t.callExpression(
3721
+ t.arrowFunctionExpression(
3722
+ [],
3723
+ t.blockStatement([expr[0], t.returnStatement(expr[1])])
3724
+ ),
3725
+ []
3726
+ )
3727
+ ] : [expr],
3728
+ template: "",
3729
+ dynamic: true
3730
+ };
3731
+ } else if (t.isJSXSpreadChild(node)) {
3732
+ if (!isDynamic(path.get("expression"), {
3733
+ checkMember: true,
3734
+ native: !info.componentChild
3735
+ }))
3736
+ return { exprs: [node.expression], template: "" };
3737
+ const expr = t.arrowFunctionExpression([], node.expression);
3738
+ return {
3739
+ exprs: [expr],
3740
+ template: "",
3741
+ dynamic: true
3742
+ };
3743
+ }
3744
+ }
3745
+ function getCreateTemplate(config, _path, result) {
3746
+ if (result.tagName && result.renderer === "dom" || config.generate === "dom") {
3747
+ return createTemplate$2;
3748
+ }
3749
+ if (result.renderer === "ssr" || config.generate === "ssr") {
3750
+ return createTemplate$1;
3751
+ }
3752
+ return createTemplate;
3753
+ }
3754
+ function transformElement(config, path, info = {}) {
3755
+ var _a;
3756
+ const node = path.node;
3757
+ let tagName = getTagName(node);
3758
+ if (isComponent(tagName)) return transformComponent(path);
3759
+ const tagRenderer = ((_a = config.renderers) != null ? _a : []).find(
3760
+ (renderer) => renderer.elements.includes(tagName)
3761
+ );
3762
+ if ((tagRenderer == null ? void 0 : tagRenderer.name) === "dom" || getConfig(path).generate === "dom") {
3763
+ return transformElement$3(path, info);
3764
+ }
3765
+ if (getConfig(path).generate === "ssr") {
3766
+ return transformElement$2(path, info);
3767
+ }
3768
+ return transformElement$1(path);
3769
+ }
3770
+
3771
+ const bodyElement = parse(`<!DOCTYPE html><html><head></head><body></body></html>`).childNodes[1].childNodes[1];
3772
+ function innerHTML(htmlFragment) {
3773
+ const parsedFragment = parseFragment(bodyElement, htmlFragment);
3774
+ return serialize(parsedFragment);
3775
+ }
3776
+ function isInvalidMarkup(html) {
3777
+ html = html.replace(/<!>/g, "<!---->").replace(/<!\$>/g, "<!--$-->").replace(/<!\/>/g, "<!--/-->").replace(/^[^<]+/, "#text").replace(/[^>]+$/, "#text").replace(/>[^<]+</gi, ">#text<").replace(/&lt;([^>]+)>/gi, "&lt;$1&gt;");
3778
+ if (/^<(td|th)>/.test(html)) {
3779
+ html = `<table><tbody><tr>${html}</tr></tbody></table>`;
3780
+ }
3781
+ if (/^<tr>/.test(html)) {
3782
+ html = `<table><tbody>${html}</tbody></table>`;
3783
+ }
3784
+ if (/^<col>/.test(html)) {
3785
+ html = `<table><colgroup>${html}</colgroup></table>`;
3786
+ }
3787
+ if (/^<(thead|tbody|tfoot|colgroup|caption)>/.test(html)) {
3788
+ html = `<table>${html}</table>`;
3789
+ }
3790
+ switch (html) {
3791
+ // empty table components
3792
+ case "<table></table>":
3793
+ case "<table><thead></thead></table>":
3794
+ case "<table><tbody></tbody></table>":
3795
+ case "<table><thead></thead><tbody></tbody></table>": {
3796
+ return;
3797
+ }
3798
+ }
3799
+ const browser = innerHTML(html);
3800
+ if (html.toLowerCase() !== browser.toLowerCase()) {
3801
+ return {
3802
+ html,
3803
+ browser
3804
+ };
3805
+ }
3806
+ }
3807
+
3808
+ var postprocess = (path, state) => {
3809
+ var _a, _b;
3810
+ const s = state;
3811
+ if (s.skip) return;
3812
+ if (path.scope.data.events && t.isProgram(path.node)) {
3813
+ path.node.body.push(
3814
+ t.expressionStatement(
3815
+ t.callExpression(
3816
+ registerImportMethod(
3817
+ path,
3818
+ "delegateEvents",
3819
+ getRendererConfig(path, "dom").moduleName
3820
+ ),
3821
+ [
3822
+ t.arrayExpression(
3823
+ Array.from(path.scope.data.events).map(
3824
+ (e) => t.stringLiteral(e)
3825
+ )
3826
+ )
3827
+ ]
3828
+ )
3829
+ )
3830
+ );
3831
+ }
3832
+ if ((_a = path.scope.data.templates) == null ? void 0 : _a.length) {
3833
+ if ((_b = path.hub.file) == null ? void 0 : _b.metadata.config.validate) {
3834
+ for (const template of path.scope.data.templates) {
3835
+ const html = template.templateWithClosingTags;
3836
+ if (typeof html === "string") {
3837
+ const result = isInvalidMarkup(html);
3838
+ if (result) {
3839
+ const message = "\nThe HTML provided is malformed and will yield unexpected output when evaluated by a browser.\n";
3840
+ console.warn(message);
3841
+ console.warn("User HTML:\n", result.html);
3842
+ console.warn("Browser HTML:\n", result.browser);
3843
+ console.warn("Original HTML:\n", html);
3844
+ }
3845
+ }
3846
+ }
3847
+ }
3848
+ let domTemplates = path.scope.data.templates.filter(
3849
+ (temp) => temp.renderer === "dom"
3850
+ );
3851
+ let ssrTemplates = path.scope.data.templates.filter(
3852
+ (temp) => temp.renderer === "ssr"
3853
+ );
3854
+ domTemplates.length > 0 && appendTemplates$1(path, domTemplates);
3855
+ ssrTemplates.length > 0 && appendTemplates(path, ssrTemplates);
3856
+ }
3857
+ };
3858
+
3859
+ const defaultConfig = {
3860
+ moduleName: "dom",
3861
+ generate: "dom",
3862
+ hydratable: false,
3863
+ delegateEvents: true,
3864
+ delegatedEvents: [],
3865
+ builtIns: [],
3866
+ requireImportSource: false,
3867
+ wrapConditionals: true,
3868
+ omitNestedClosingTags: false,
3869
+ omitLastClosingTag: true,
3870
+ omitQuotes: true,
3871
+ contextToCustomElements: false,
3872
+ staticMarker: "@once",
3873
+ effectWrapper: "effect",
3874
+ memoWrapper: "memo",
3875
+ validate: true
3876
+ };
3877
+
3878
+ var preprocess = (path, state) => {
3879
+ var _a, _b;
3880
+ const s = state;
3881
+ const merged = path.hub.file.metadata.config = Object.assign(
3882
+ {},
3883
+ defaultConfig,
3884
+ s.opts
3885
+ );
3886
+ const lib = merged.requireImportSource;
3887
+ if (lib) {
3888
+ const comments = (_b = (_a = path.hub.file) == null ? void 0 : _a.ast.comments) != null ? _b : [];
3889
+ let process = false;
3890
+ for (let i = 0; i < comments.length; i++) {
3891
+ const comment = comments[i];
3892
+ const pieces = comment.value.split("@jsxImportSource");
3893
+ if (pieces.length === 2 && pieces[1].trim() === lib) {
3894
+ process = true;
3895
+ break;
3896
+ }
3897
+ }
3898
+ if (!process) {
3899
+ s.skip = true;
3900
+ return;
3901
+ }
3902
+ }
3903
+ };
3904
+
3905
+ var index = () => {
3906
+ return {
3907
+ name: "@zeus-js/compiler",
3908
+ inherits: SyntaxJSX.default,
3909
+ visitor: {
3910
+ JSXElement: transformJSX,
3911
+ JSXFragment: transformJSX,
3912
+ Program: {
3913
+ enter: preprocess,
3914
+ exit: postprocess
3915
+ }
3916
+ }
3917
+ };
3918
+ };
3919
+
3920
+ export { index as default };