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