what-compiler 0.13.11 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +181 -2
- package/babel.d.ts +78 -2
- package/dist/babel/auto-selector.min.js +94 -0
- package/dist/babel/common.min.js +2053 -0
- package/dist/babel/dev-metadata.min.js +106 -0
- package/dist/babel/dom.min.js +1669 -0
- package/dist/babel/jsx-root.min.js +13 -0
- package/dist/babel/lists.min.js +492 -0
- package/dist/babel/nesting.min.js +328 -0
- package/dist/babel/reactivity.min.js +1218 -0
- package/dist/babel/server-actions.min.js +85 -0
- package/dist/babel/ssr.min.js +496 -0
- package/dist/babel/types.min.js +9 -0
- package/dist/babel-plugin.min.js +101 -1
- package/dist/file-router.min.js +368 -12
- package/dist/framework-files.min.js +62 -0
- package/dist/hot.min.js +315 -0
- package/dist/index.min.js +13 -414
- package/dist/release.min.js +78 -0
- package/dist/runtime.min.js +9 -1
- package/dist/tables/import-changes.min.js +272 -0
- package/dist/tables/markup-rules.min.js +213 -0
- package/dist/vite-plugin.min.js +432 -399
- package/file-router.d.ts +3 -1
- package/index.d.ts +1 -1
- package/package.json +11 -2
- package/runtime.d.ts +2 -1
- package/src/babel/auto-selector.js +248 -0
- package/src/babel/common.js +3800 -0
- package/src/babel/dev-metadata.js +167 -0
- package/src/babel/dom.js +3386 -0
- package/src/babel/jsx-root.js +27 -0
- package/src/babel/lists.js +704 -0
- package/src/babel/nesting.js +260 -0
- package/src/babel/reactivity.js +1998 -0
- package/src/babel/server-actions.js +144 -0
- package/src/babel/ssr.js +870 -0
- package/src/babel/types.js +10 -0
- package/src/babel-plugin.js +185 -3598
- package/src/file-router.js +58 -38
- package/src/framework-files.js +106 -0
- package/src/hot.js +523 -0
- package/src/release.js +127 -0
- package/src/runtime.js +7 -7
- package/src/tables/import-changes.js +157 -0
- package/src/tables/markup-rules.js +388 -0
- package/src/vite-plugin.js +460 -175
- package/vite.d.ts +47 -3
- package/src/error-overlay.js +0 -428
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// src/babel/server-actions.js
|
|
2
|
+
import { t as i } from "./types.min.js";
|
|
3
|
+
var A = /* @__PURE__ */ new Set([
|
|
4
|
+
"what-framework/server",
|
|
5
|
+
"what-server",
|
|
6
|
+
"what-server/actions"
|
|
7
|
+
]);
|
|
8
|
+
function f(r) {
|
|
9
|
+
let e = 0xcbf29ce484222325n;
|
|
10
|
+
for (let n = 0; n < r.length; n++)
|
|
11
|
+
e ^= BigInt(r.charCodeAt(n)), e = BigInt.asUintN(64, e * 0x100000001b3n);
|
|
12
|
+
return e.toString(36);
|
|
13
|
+
}
|
|
14
|
+
function I(r, e) {
|
|
15
|
+
let n = String(r || "<unknown>").replace(/\\/g, "/").replace(/[?#].*$/, ""), t = String(e || "").replace(/\\/g, "/").replace(/\/+$/, "");
|
|
16
|
+
return t && n.startsWith(`${t}/`) ? n.slice(t.length + 1) : n.replace(/^\.\//, "");
|
|
17
|
+
}
|
|
18
|
+
function m(r) {
|
|
19
|
+
let e = r.parentPath;
|
|
20
|
+
if (e?.isVariableDeclarator() && i.isIdentifier(e.node.id))
|
|
21
|
+
return e.node.id.name;
|
|
22
|
+
if (e?.isAssignmentExpression() && i.isIdentifier(e.node.left))
|
|
23
|
+
return e.node.left.name;
|
|
24
|
+
if (e?.isExportDefaultDeclaration()) return "default";
|
|
25
|
+
if (e?.isObjectProperty() && !e.node.computed) {
|
|
26
|
+
if (i.isIdentifier(e.node.key)) return e.node.key.name;
|
|
27
|
+
if (i.isStringLiteral(e.node.key)) return e.node.key.value;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
function v(r, e) {
|
|
32
|
+
let n = r.node.callee;
|
|
33
|
+
return i.isIdentifier(n) ? e.serverActionBindings.has(n.name) : i.isMemberExpression(n) && !n.computed && i.isIdentifier(n.object) && i.isIdentifier(n.property, { name: "action" }) && e.serverActionNamespaces.has(n.object.name);
|
|
34
|
+
}
|
|
35
|
+
function g(r) {
|
|
36
|
+
if (!i.isObjectExpression(r)) return { property: null, value: null };
|
|
37
|
+
for (let e of r.properties)
|
|
38
|
+
if (!(!i.isObjectProperty(e) || (i.isIdentifier(e.key) && !e.computed ? e.key.name : i.isStringLiteral(e.key) ? e.key.value : null) !== "id"))
|
|
39
|
+
return i.isStringLiteral(e.value) ? { property: e, value: e.value.value } : i.isTemplateLiteral(e.value) && e.value.expressions.length === 0 ? { property: e, value: e.value.quasis[0]?.value.cooked || "" } : { property: e, value: null };
|
|
40
|
+
return { property: null, value: null };
|
|
41
|
+
}
|
|
42
|
+
function a(r, e, n, t, o) {
|
|
43
|
+
let s = r.node.loc?.start || { line: 0, column: 0 }, c = `${o}:${s.line}:${s.column + 1}`, d = `${o}#${t}`, l = e.serverActionIds.get(n);
|
|
44
|
+
if (l)
|
|
45
|
+
throw Object.assign(r.buildCodeFrameError(
|
|
46
|
+
`Duplicate server action ID "${n}". First declared by "${l.bindingName}" at ${l.source}; conflicts with "${t}" at ${c}.`
|
|
47
|
+
), { code: "ERR_DUPLICATE_ACTION_ID", loc: s });
|
|
48
|
+
let p = { id: n, key: d, bindingName: t, filename: o, source: c, loc: s };
|
|
49
|
+
if (e.serverActionIds.set(n, p), typeof e.opts?.onActionId == "function")
|
|
50
|
+
try {
|
|
51
|
+
e.opts.onActionId(p);
|
|
52
|
+
} catch (u) {
|
|
53
|
+
throw Object.assign(r.buildCodeFrameError(u instanceof Error ? u.message : String(u)), { code: u?.code, loc: s });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function b(r, e) {
|
|
57
|
+
if (!v(r, e)) return;
|
|
58
|
+
let n = r.node.arguments[1], t = g(n), o = m(r);
|
|
59
|
+
if (!o && t.property) {
|
|
60
|
+
t.value !== null && a(r, e, t.value, t.value, e.serverActionFilename);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!o) {
|
|
64
|
+
e.opts?.production || console.warn(
|
|
65
|
+
`[what-compiler] Could not derive a stable server action ID at ${e.serverActionFilename}:${r.node.loc?.start.line || 0}. Assign action(...) to a named local or export, or pass { id } explicitly.`
|
|
66
|
+
);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (t.property) {
|
|
70
|
+
t.value !== null && a(r, e, t.value, o, e.serverActionFilename);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
let s = `wa1_${f(`${e.serverActionFilename}#${o}`)}`;
|
|
74
|
+
a(r, e, s, o, e.serverActionFilename);
|
|
75
|
+
let c = i.objectProperty(i.identifier("id"), i.stringLiteral(s));
|
|
76
|
+
n ? i.isObjectExpression(n) ? n.properties.unshift(c) : r.node.arguments[1] = i.objectExpression([
|
|
77
|
+
c,
|
|
78
|
+
i.spreadElement(n)
|
|
79
|
+
]) : r.node.arguments.push(i.objectExpression([c]));
|
|
80
|
+
}
|
|
81
|
+
export {
|
|
82
|
+
A as SERVER_ACTION_SOURCES,
|
|
83
|
+
I as normalizeActionFilename,
|
|
84
|
+
b as transformServerAction
|
|
85
|
+
};
|
|
@@ -0,0 +1,496 @@
|
|
|
1
|
+
// src/babel/ssr.js
|
|
2
|
+
import {
|
|
3
|
+
RAW_TEXT_ELEMENTS as H,
|
|
4
|
+
TEXT_ONLY_ELEMENTS as ne,
|
|
5
|
+
LEADING_NEWLINE_ELEMENTS as te,
|
|
6
|
+
SAFE_ATTR_NAME as ie,
|
|
7
|
+
SAFE_TAG_NAME as re,
|
|
8
|
+
VOID_ELEMENTS as C,
|
|
9
|
+
escapeHtml as T,
|
|
10
|
+
FIELD_PROPS as se,
|
|
11
|
+
FIELD_TAGS as oe,
|
|
12
|
+
isEnumeratedAttr as le,
|
|
13
|
+
isNamespaceNeutralText as ae,
|
|
14
|
+
isRefusedAttr as ue,
|
|
15
|
+
isUrlAttr as ce,
|
|
16
|
+
markupName as fe
|
|
17
|
+
} from "../tables/markup-rules.min.js";
|
|
18
|
+
import { t as n } from "./types.min.js";
|
|
19
|
+
import {
|
|
20
|
+
addImports as pe,
|
|
21
|
+
checkElementName as me,
|
|
22
|
+
checkStaticAttribute as he,
|
|
23
|
+
checkStaticRawText as de,
|
|
24
|
+
compileError as D,
|
|
25
|
+
componentCallee as Ee,
|
|
26
|
+
createEventHandler as ge,
|
|
27
|
+
getAttrName as x,
|
|
28
|
+
getAttributeValue as v,
|
|
29
|
+
getBindingProperty as q,
|
|
30
|
+
hasEventModifiers as xe,
|
|
31
|
+
controlFlowTag as Se,
|
|
32
|
+
helper as we,
|
|
33
|
+
helperLocals as be,
|
|
34
|
+
isBindingAttribute as B,
|
|
35
|
+
isComponentElement as J,
|
|
36
|
+
isEventAttrName as ye,
|
|
37
|
+
isSlotAttribute as _e,
|
|
38
|
+
normalizeJsxText as I,
|
|
39
|
+
parseEventModifiers as Le,
|
|
40
|
+
propKey as W,
|
|
41
|
+
readSwitch as Te,
|
|
42
|
+
uniqueName as X,
|
|
43
|
+
unsafeMarkup as K,
|
|
44
|
+
checkIslandProp as M,
|
|
45
|
+
directiveValue as ve,
|
|
46
|
+
islandOptions as Fe,
|
|
47
|
+
renderFunctionChild as Ne,
|
|
48
|
+
hostSpreadArgument as Ae
|
|
49
|
+
} from "./common.min.js";
|
|
50
|
+
import { buildWhenCondition as k, isPotentiallyReactive as G } from "./reactivity.min.js";
|
|
51
|
+
import { findMappedJsx as $e, isKeyedRow as Re, islandKey as Je, keyIndex as Ie, listSlot as O, liveKey as P, markRowItemReads as Xe, readsRowItem as Oe, rowField as Pe } from "./lists.min.js";
|
|
52
|
+
import { enterJsxRoot as Ce } from "./jsx-root.min.js";
|
|
53
|
+
import { componentMetadata as Me } from "./dev-metadata.min.js";
|
|
54
|
+
var je = /* @__PURE__ */ new Set(["classList", "innerHTML", "dangerouslySetInnerHTML"]);
|
|
55
|
+
function xn(e) {
|
|
56
|
+
e.ssrTemplates = [], e.ssrTemplateMap = /* @__PURE__ */ new Map();
|
|
57
|
+
}
|
|
58
|
+
function d(e, t, r) {
|
|
59
|
+
return n.callExpression(we(e, t), r);
|
|
60
|
+
}
|
|
61
|
+
function g(e) {
|
|
62
|
+
return n.arrowFunctionExpression([], e);
|
|
63
|
+
}
|
|
64
|
+
function Ve(e) {
|
|
65
|
+
let t = e;
|
|
66
|
+
for (; n.isMemberExpression(t) && !t.computed; ) t = t.object;
|
|
67
|
+
return n.isIdentifier(t) || n.isThisExpression(t);
|
|
68
|
+
}
|
|
69
|
+
function N(e, t) {
|
|
70
|
+
return Oe(e) || !Ve(e) && G(e, t.signalNames, t.importedIdentifiers);
|
|
71
|
+
}
|
|
72
|
+
function A(e, t) {
|
|
73
|
+
return N(e, t) ? g(e) : e;
|
|
74
|
+
}
|
|
75
|
+
function U(e = !1) {
|
|
76
|
+
return { strings: [""], holes: [], slots: [], foreign: e, row: null };
|
|
77
|
+
}
|
|
78
|
+
function E(e, t) {
|
|
79
|
+
e.strings[e.strings.length - 1] += t;
|
|
80
|
+
}
|
|
81
|
+
function S(e, t, r = null) {
|
|
82
|
+
e.holes.push(t), e.slots.push(r), e.strings.push("");
|
|
83
|
+
}
|
|
84
|
+
function j(e, t, r, i = []) {
|
|
85
|
+
let s = (r ? "static:" : "") + JSON.stringify([t, i]), o = e.ssrTemplateMap.get(s);
|
|
86
|
+
return o === void 0 && (o = X(e, "_tmpl$"), e.ssrTemplateMap.set(s, o), e.ssrTemplates.push({ id: o, strings: t, isStatic: r, slots: i })), o;
|
|
87
|
+
}
|
|
88
|
+
function Y(e, t, r = !1) {
|
|
89
|
+
if (e.holes.length === 0) return n.identifier(j(t, e.strings, !0));
|
|
90
|
+
if (e.holes.length === 1 && e.strings[0] === "" && e.strings[1] === "" && e.holes[0]._whatHtml)
|
|
91
|
+
return e.holes[0];
|
|
92
|
+
let i = e.foreign ? "_$ssrForeign" : r ? "_$ssrRow" : "_$ssr", s = e.slots.some(Boolean) ? e.slots : [], o = e.row !== null && e.row.fns.length > 0 ? [n.identifier(e.row.param)] : [];
|
|
93
|
+
return d(t, i, [n.identifier(j(t, e.strings, !1, s)), ...o, ...e.holes]);
|
|
94
|
+
}
|
|
95
|
+
function Sn(e, t) {
|
|
96
|
+
Ce(e, t), e.replaceWith($(e.node, e, t));
|
|
97
|
+
}
|
|
98
|
+
function $(e, t, r) {
|
|
99
|
+
if (n.isJSXFragment(e)) return tn(e, r);
|
|
100
|
+
let i = Se(e, r);
|
|
101
|
+
if (i === "For") return un(e, t, r);
|
|
102
|
+
if (i === "Show") return ln(e, t, r);
|
|
103
|
+
if (i === "Switch") {
|
|
104
|
+
let l = an(e, t, r);
|
|
105
|
+
if (l) return l;
|
|
106
|
+
}
|
|
107
|
+
if (J(e)) return rn(e, r);
|
|
108
|
+
let s = U();
|
|
109
|
+
e._whatRowList && (s.row = Be(e, t, r)), z(e, s, r);
|
|
110
|
+
let o = Y(s, r, e._whatRow === !0);
|
|
111
|
+
return s.row !== null && Ke(s.row), P(e, r) !== null ? g(o) : o;
|
|
112
|
+
}
|
|
113
|
+
var He = /* @__PURE__ */ new Set(["ThisExpression", "Super", "AwaitExpression", "YieldExpression", "MetaProperty"]), De = /* @__PURE__ */ new Set(["arguments", "eval"]);
|
|
114
|
+
function F(e, t) {
|
|
115
|
+
if (!e || typeof e != "object") return !1;
|
|
116
|
+
if (Array.isArray(e)) return e.some((r) => F(r, t));
|
|
117
|
+
if (typeof e.type != "string") return !1;
|
|
118
|
+
if (t(e)) return !0;
|
|
119
|
+
for (let r of n.VISITOR_KEYS[e.type] || [])
|
|
120
|
+
if (F(e[r], t)) return !0;
|
|
121
|
+
return !1;
|
|
122
|
+
}
|
|
123
|
+
function qe(e) {
|
|
124
|
+
return e.type === "Identifier" || e.type === "JSXIdentifier";
|
|
125
|
+
}
|
|
126
|
+
function Be(e, t, r) {
|
|
127
|
+
let { call: i, mapFn: s } = e._whatRowList, o = s.params[0];
|
|
128
|
+
if (!t || typeof t.traverse != "function" || !t.scope || t.scope.block !== s) return null;
|
|
129
|
+
let l = t.parentPath;
|
|
130
|
+
if (!l || l.node !== s || s.body !== e || l.listKey !== "arguments") return null;
|
|
131
|
+
let a = l.parentPath;
|
|
132
|
+
if (!a || a.node !== i || i.arguments[1] !== s) return null;
|
|
133
|
+
let c = t.scope.getOwnBinding(o.name);
|
|
134
|
+
if (!c || c.identifier !== o || !c.constant || F(s, (f) => f.type === "Identifier" && f.name === "eval")) return null;
|
|
135
|
+
let u = /* @__PURE__ */ new Set([...Object.keys(n.getBindingIdentifiers(s.params)), ...Object.keys(t.scope.bindings)]);
|
|
136
|
+
u.delete(o.name);
|
|
137
|
+
let m = (f) => He.has(f.type) || qe(f) && (u.has(f.name) || De.has(f.name)), p = /* @__PURE__ */ new Set();
|
|
138
|
+
return t.traverse({
|
|
139
|
+
Function(f) {
|
|
140
|
+
f.skip();
|
|
141
|
+
},
|
|
142
|
+
JSXAttribute(f) {
|
|
143
|
+
let h = f.node.value;
|
|
144
|
+
n.isJSXExpressionContainer(h) && !F(h.expression, m) && p.add(h.expression);
|
|
145
|
+
}
|
|
146
|
+
}), p.size === 0 ? null : { fnPath: l, listPath: a, item: o.name, hoistable: p, fns: [], param: null, state: r };
|
|
147
|
+
}
|
|
148
|
+
function We(e, t) {
|
|
149
|
+
return e.param === null && (e.param = X(e.state, "_f$")), e.fns.push(n.arrowFunctionExpression([n.identifier(e.item)], t)), e.fns.length - 1;
|
|
150
|
+
}
|
|
151
|
+
function Ke(e) {
|
|
152
|
+
if (e.fns.length === 0) return;
|
|
153
|
+
let { fnPath: t, listPath: r } = e, [i] = t.unshiftContainer("params", n.identifier(e.param));
|
|
154
|
+
t.scope.registerBinding("param", i);
|
|
155
|
+
let s = [], o = r.node.arguments.length;
|
|
156
|
+
o < 4 && s.push(n.nullLiteral()), o < 5 && s.push(n.unaryExpression("void", n.numericLiteral(0))), s.push(n.arrayExpression(e.fns)), r.pushContainer("arguments", s);
|
|
157
|
+
}
|
|
158
|
+
function b(e) {
|
|
159
|
+
return e._whatNs === "svg" || e._whatNs === "math";
|
|
160
|
+
}
|
|
161
|
+
function z(e, t, r) {
|
|
162
|
+
me(e, r);
|
|
163
|
+
let i = e.openingElement.name.name;
|
|
164
|
+
if (!re.test(i))
|
|
165
|
+
throw K(e, r, `<${i}> is not a tag name what-server can emit.`);
|
|
166
|
+
b(e) && (t.foreign = !0);
|
|
167
|
+
let s = i === "option" && !b(e), o = r._whatOptionText === !0 || s && !Ye(e, "value"), l = Ue(e, r, s || o);
|
|
168
|
+
if (l.runtime) {
|
|
169
|
+
let a = n.nullLiteral();
|
|
170
|
+
if (e.children.length > 0 && !C.has(i))
|
|
171
|
+
if (o) {
|
|
172
|
+
let u = r._whatOptionText;
|
|
173
|
+
r._whatOptionText = !0;
|
|
174
|
+
try {
|
|
175
|
+
a = n.arrayExpression(_(e.children, r));
|
|
176
|
+
} finally {
|
|
177
|
+
r._whatOptionText = u;
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
let u = U(b(e));
|
|
181
|
+
V(e, u, r), a = Y(u, r);
|
|
182
|
+
}
|
|
183
|
+
let c = d(r, "_$ssrElement", [n.stringLiteral(i), l.props, a]);
|
|
184
|
+
c._whatHtml = !0, S(t, c);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
E(t, `<${i}`);
|
|
188
|
+
for (let a of l.list) Ze(a, t, r);
|
|
189
|
+
E(t, ">"), !C.has(i) && (!b(e) && te.has(i) && E(t, `
|
|
190
|
+
`), V(e, t, r), E(t, `</${i}>`));
|
|
191
|
+
}
|
|
192
|
+
function ke(e) {
|
|
193
|
+
if (!e.value) return !0;
|
|
194
|
+
if (n.isStringLiteral(e.value)) return e.value.value;
|
|
195
|
+
let t = n.isJSXExpressionContainer(e.value) ? e.value.expression : null;
|
|
196
|
+
if (n.isStringLiteral(t) || n.isNumericLiteral(t) || n.isBooleanLiteral(t)) return t.value;
|
|
197
|
+
if (n.isNullLiteral(t)) return null;
|
|
198
|
+
if (n.isTemplateLiteral(t) && t.expressions.length === 0) return t.quasis[0].value.cooked;
|
|
199
|
+
}
|
|
200
|
+
function Ge(e, t) {
|
|
201
|
+
return e !== "input" ? [...se].some((r) => t.has(r)) : t.has("value") && t.has("defaultValue") || t.has("checked") && t.has("defaultChecked");
|
|
202
|
+
}
|
|
203
|
+
function Ue(e, t, r = !1) {
|
|
204
|
+
let i = e.openingElement.attributes, s = e.openingElement.name, o = n.isJSXIdentifier(s) && oe.has(s.name), l = [], a = r;
|
|
205
|
+
for (let u of i) {
|
|
206
|
+
if (n.isJSXSpreadAttribute(u)) {
|
|
207
|
+
a = !0, l.push({ spread: Ae(u) });
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
let m = x(u);
|
|
211
|
+
if (m === "key" || m === "ref" || m === "children" || ye(m)) continue;
|
|
212
|
+
let p = null;
|
|
213
|
+
if (B(m)) {
|
|
214
|
+
let w = q(m);
|
|
215
|
+
if (w !== "value" && w !== "checked") continue;
|
|
216
|
+
m = w, p = n.callExpression(n.cloneNode(u.value.expression), []);
|
|
217
|
+
}
|
|
218
|
+
je.has(m) && (a = !0);
|
|
219
|
+
let f = fe(m);
|
|
220
|
+
if (!ie.test(f))
|
|
221
|
+
throw K(u, t, `"${f}" is not an attribute name what-server can emit.`);
|
|
222
|
+
let h = p ? void 0 : ke(u);
|
|
223
|
+
he(u, f, m, h, t), l.push({ name: m, key: f, attr: u, fixed: h, expr: p || (h === void 0 ? v(u.value) : null) });
|
|
224
|
+
}
|
|
225
|
+
if (o && !a && (a = Ge(s.name, new Set(l.map((u) => u.name)))), a) {
|
|
226
|
+
let u = l.map((m) => m.spread ? n.spreadElement(m.spread) : n.objectProperty(W(m.name), m.fixed !== void 0 ? ze(m.fixed) : A(m.expr, t)));
|
|
227
|
+
return { runtime: !0, props: n.objectExpression(u), list: [] };
|
|
228
|
+
}
|
|
229
|
+
let c = /* @__PURE__ */ new Map();
|
|
230
|
+
for (let u of l) {
|
|
231
|
+
let m = c.get(u.name);
|
|
232
|
+
m ? Object.assign(m, { fixed: u.fixed, expr: u.expr, attr: u.attr }) : c.set(u.name, u);
|
|
233
|
+
}
|
|
234
|
+
return { runtime: !1, props: null, list: [...c.values()] };
|
|
235
|
+
}
|
|
236
|
+
function Ye(e, t) {
|
|
237
|
+
return e.openingElement.attributes.some((r) => n.isJSXAttribute(r) && x(r) === t);
|
|
238
|
+
}
|
|
239
|
+
function ze(e) {
|
|
240
|
+
return e === !0 || e === !1 ? n.booleanLiteral(e) : e === null ? n.nullLiteral() : typeof e == "number" ? n.numericLiteral(e) : n.stringLiteral(e);
|
|
241
|
+
}
|
|
242
|
+
function Qe(e) {
|
|
243
|
+
return ue(e) ? "refused" : e === "class" ? "class" : e === "style" ? "style" : le(e) ? "enum" : ce(e) ? "url" : "plain";
|
|
244
|
+
}
|
|
245
|
+
function Ze({ key: e, fixed: t, expr: r }, i, s) {
|
|
246
|
+
let o = Qe(e);
|
|
247
|
+
if (t === void 0) {
|
|
248
|
+
let l = i.row;
|
|
249
|
+
if (l !== null && l.hoistable.has(r) && N(r, s)) {
|
|
250
|
+
S(i, n.identifier(l.item), [o, e, We(l, r)]);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
S(i, A(r, s), [o, e]);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
if (!(t === null || o === "refused")) {
|
|
257
|
+
if (t === !1) {
|
|
258
|
+
o === "enum" && E(i, ` ${e}="false"`);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (t === !0 && o !== "class" && o !== "enum") {
|
|
262
|
+
E(i, ` ${e}`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
E(i, ` ${e}="${T(String(t))}"`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function V(e, t, r) {
|
|
269
|
+
let i = e.openingElement.name.name;
|
|
270
|
+
if (H.has(i) || ne.has(i) && !b(e)) {
|
|
271
|
+
en(e, i, t, r);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
Q(e.children, t, r);
|
|
275
|
+
}
|
|
276
|
+
function Q(e, t, r) {
|
|
277
|
+
for (let i of e)
|
|
278
|
+
if (n.isJSXText(i)) {
|
|
279
|
+
let s = I(i.value);
|
|
280
|
+
s && E(t, T(s));
|
|
281
|
+
} else if (n.isJSXExpressionContainer(i)) {
|
|
282
|
+
let s = i.expression;
|
|
283
|
+
if (n.isJSXEmptyExpression(s)) continue;
|
|
284
|
+
if (n.isStringLiteral(s) || n.isNumericLiteral(s)) {
|
|
285
|
+
E(t, T(String(s.value)));
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
S(t, nn(s, r));
|
|
289
|
+
} else n.isJSXElement(i) && !J(i) && P(i, r) === null ? z(i, t, r) : n.isJSXFragment(i) ? Q(i.children, t, r) : n.isJSXElement(i) && S(t, $(i, { node: i }, r));
|
|
290
|
+
}
|
|
291
|
+
function en(e, t, r, i) {
|
|
292
|
+
let s = !H.has(t), o = [], l = !0;
|
|
293
|
+
for (let a of e.children) {
|
|
294
|
+
let c;
|
|
295
|
+
if (n.isJSXText(a)) c = I(a.value);
|
|
296
|
+
else if (n.isJSXExpressionContainer(a)) {
|
|
297
|
+
let u = a.expression;
|
|
298
|
+
if (n.isJSXEmptyExpression(u)) continue;
|
|
299
|
+
if (n.isStringLiteral(u) || n.isNumericLiteral(u)) c = String(u.value);
|
|
300
|
+
else if (n.isTemplateLiteral(u) && u.expressions.length === 0) c = u.quasis[0].value.cooked;
|
|
301
|
+
else {
|
|
302
|
+
l = !1, o.push(A(u, i));
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
} else {
|
|
306
|
+
l = !1, o.push($(a, { node: a }, i));
|
|
307
|
+
continue;
|
|
308
|
+
}
|
|
309
|
+
c && (s || (de(a, t, c, i), ae(c) || (l = !1)), o.push(n.stringLiteral(c)));
|
|
310
|
+
}
|
|
311
|
+
if (o.length !== 0) {
|
|
312
|
+
if (l) {
|
|
313
|
+
for (let a of o) E(r, s ? T(a.value) : a.value);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
S(r, d(i, "_$ssrRawText", [n.stringLiteral(t), n.arrayExpression(o)]));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
function nn(e, t) {
|
|
320
|
+
let r = Z(e, t);
|
|
321
|
+
return r || (Pe(e) !== null ? d(t, "_$ssrText", [e]) : N(e, t) ? g(e) : d(t, "_$ssrText", [e]));
|
|
322
|
+
}
|
|
323
|
+
function Z(e, t, r = !1) {
|
|
324
|
+
let i = e, s;
|
|
325
|
+
n.isArrowFunctionExpression(e) && e.params.length === 0 && n.isExpression(e.body) ? (i = e.body, s = !0) : s = N(e, t);
|
|
326
|
+
let o = s || r, l;
|
|
327
|
+
if (n.isConditionalExpression(i)) {
|
|
328
|
+
let a = L(i.consequent, t, o), c = L(i.alternate, t, o);
|
|
329
|
+
l = a || c ? n.conditionalExpression(i.test, a || i.consequent, c || i.alternate) : null;
|
|
330
|
+
} else if (n.isLogicalExpression(i) && (i.operator === "&&" || i.operator === "||")) {
|
|
331
|
+
let a = L(i.right, t, o);
|
|
332
|
+
l = a && n.logicalExpression(i.operator, i.left, a);
|
|
333
|
+
} else
|
|
334
|
+
l = L(i, t, o);
|
|
335
|
+
return l ? s ? g(l) : l : null;
|
|
336
|
+
}
|
|
337
|
+
function L(e, t, r) {
|
|
338
|
+
let i = $e(e, t, !1);
|
|
339
|
+
if (!i) return null;
|
|
340
|
+
let s = Re(i);
|
|
341
|
+
s && Xe(i.mapFn, i.keyValue), i.mapFn.body === i.returnExpr && !J(i.returnExpr) && (i.returnExpr._whatRow = !0);
|
|
342
|
+
let o = [e.callee.object, i.mapFn, n.booleanLiteral(r || s)];
|
|
343
|
+
if (s) {
|
|
344
|
+
let a = i.mapFn.params[0] ? n.cloneNode(i.mapFn.params[0], !0) : n.identifier("_item"), c = Ie(i);
|
|
345
|
+
o.push(n.arrowFunctionExpression(c === null ? [a] : [a, n.identifier(c)], n.cloneNode(i.keyValue, !0)));
|
|
346
|
+
let u = O(e);
|
|
347
|
+
u !== null && o.push(u);
|
|
348
|
+
}
|
|
349
|
+
let l = d(t, "_$ssrList", o);
|
|
350
|
+
return i.returnExpr._whatRow === !0 && n.isArrowFunctionExpression(i.mapFn) && !i.mapFn.async && n.isIdentifier(i.mapFn.params[0]) && (i.returnExpr._whatRowList = { call: l, mapFn: i.mapFn }), l;
|
|
351
|
+
}
|
|
352
|
+
function _(e, t, r = !1) {
|
|
353
|
+
let i = [];
|
|
354
|
+
for (let s of e)
|
|
355
|
+
if (n.isJSXText(s)) {
|
|
356
|
+
let o = I(s.value);
|
|
357
|
+
o && i.push(n.stringLiteral(o));
|
|
358
|
+
} else if (n.isJSXExpressionContainer(s)) {
|
|
359
|
+
let o = s.expression;
|
|
360
|
+
if (n.isJSXEmptyExpression(o)) continue;
|
|
361
|
+
i.push(Z(o, t, r) || A(o, t));
|
|
362
|
+
} else (n.isJSXElement(s) || n.isJSXFragment(s)) && i.push($(s, { node: s }, t));
|
|
363
|
+
return i;
|
|
364
|
+
}
|
|
365
|
+
function tn(e, t) {
|
|
366
|
+
return d(t, "_$ssrFragment", [n.arrayExpression(_(e.children, t))]);
|
|
367
|
+
}
|
|
368
|
+
function rn(e, t) {
|
|
369
|
+
let r = e.openingElement, i = null;
|
|
370
|
+
for (let p of r.attributes)
|
|
371
|
+
n.isJSXAttribute(p) && x(p).startsWith("client:") && (i = { mode: x(p).slice(7), mediaQuery: ve(p) });
|
|
372
|
+
let s = [];
|
|
373
|
+
for (let p of r.attributes) {
|
|
374
|
+
if (n.isJSXSpreadAttribute(p)) {
|
|
375
|
+
if (i && n.isObjectExpression(p.argument))
|
|
376
|
+
for (let h of p.argument.properties)
|
|
377
|
+
n.isObjectProperty(h) && M(n.isIdentifier(h.key) ? h.key.name : String(h.key.value), h.value, e, t);
|
|
378
|
+
s.push(n.spreadElement(p.argument));
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
let f = x(p);
|
|
382
|
+
if (!(f.startsWith("client:") || f === "key")) {
|
|
383
|
+
if (B(f)) {
|
|
384
|
+
s.push(...on(q(f), p.value.expression));
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
if (f.startsWith("on") && (f.includes("|") || xe(f, t))) {
|
|
388
|
+
let { eventName: h, modifiers: w } = Le(f);
|
|
389
|
+
s.push(n.objectProperty(n.identifier(h), ge(v(p.value), w)));
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
i && M(f, p.value, e, t), s.push(n.objectProperty(W(f), sn(e, p, v(p.value), t)));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
let o = n.arrayExpression(_(e.children, t)), l = Me(e, t);
|
|
396
|
+
if (i) {
|
|
397
|
+
let p = s.length ? n.objectExpression(s) : null, f = [Fe(r.name, i.mode, i.mediaQuery, p), o];
|
|
398
|
+
l && f.push(l);
|
|
399
|
+
let h = d(t, "_$ssrIsland", f);
|
|
400
|
+
return Je(e, i.mode, t) !== null ? g(h) : h;
|
|
401
|
+
}
|
|
402
|
+
let a = o.elements.length === 0 && s.every((p) => n.isObjectProperty(p)), c = [Ee(r.name), s.length ? n.objectExpression(s) : n.nullLiteral()];
|
|
403
|
+
a || c.push(o);
|
|
404
|
+
let u = O(e);
|
|
405
|
+
(u !== null || l) && c.push(u ?? n.unaryExpression("void", n.numericLiteral(0))), l && c.push(l);
|
|
406
|
+
let m = d(t, a ? "_$ssrLeaf" : "_$ssrComponent", c);
|
|
407
|
+
return P(e, t) !== null ? g(m) : m;
|
|
408
|
+
}
|
|
409
|
+
function sn(e, t, r, i) {
|
|
410
|
+
if (!n.isConditionalExpression(r) || !_e(e, t, i) || !R(r)) return r;
|
|
411
|
+
let s = [], o = [];
|
|
412
|
+
return (function l(a) {
|
|
413
|
+
n.isConditionalExpression(a) ? (s.push(a.test), l(a.consequent), l(a.alternate)) : o.push(a);
|
|
414
|
+
})(r), s.some((l) => G(l, i.signalNames, i.importedIdentifiers)) ? n.arrowFunctionExpression([], r) : r;
|
|
415
|
+
}
|
|
416
|
+
function R(e) {
|
|
417
|
+
return n.isConditionalExpression(e) ? R(e.consequent) && R(e.alternate) : n.isJSXElement(e) || n.isJSXFragment(e);
|
|
418
|
+
}
|
|
419
|
+
function on(e, t) {
|
|
420
|
+
let r = (s) => n.memberExpression(n.memberExpression(n.identifier("e"), n.identifier("target")), n.identifier(s)), i = (s) => n.arrowFunctionExpression(
|
|
421
|
+
[n.identifier("e")],
|
|
422
|
+
n.callExpression(n.memberExpression(n.cloneNode(t), n.identifier("set")), [r(s)])
|
|
423
|
+
);
|
|
424
|
+
return e === "value" ? [
|
|
425
|
+
n.objectProperty(n.identifier("value"), n.callExpression(n.cloneNode(t), [])),
|
|
426
|
+
n.objectProperty(n.identifier("onInput"), i("value"))
|
|
427
|
+
] : e === "checked" ? [
|
|
428
|
+
n.objectProperty(n.identifier("checked"), n.callExpression(n.cloneNode(t), [])),
|
|
429
|
+
n.objectProperty(n.identifier("onChange"), i("checked"))
|
|
430
|
+
] : [];
|
|
431
|
+
}
|
|
432
|
+
function y(e, t) {
|
|
433
|
+
for (let r of e.openingElement.attributes)
|
|
434
|
+
if (n.isJSXAttribute(r) && x(r) === t) return v(r.value);
|
|
435
|
+
return null;
|
|
436
|
+
}
|
|
437
|
+
function ee(e) {
|
|
438
|
+
return e.length === 0 ? n.nullLiteral() : e.length === 1 ? e[0] : n.arrayExpression(e);
|
|
439
|
+
}
|
|
440
|
+
function ln(e, t, r) {
|
|
441
|
+
let i = y(e, "when");
|
|
442
|
+
if (!i)
|
|
443
|
+
throw D(t, r, '<Show> requires a "when" prop. Example: <Show when={isOpen} fallback={null}>...</Show>');
|
|
444
|
+
let s = y(e, "fallback") || n.nullLiteral(), o = Ne(e.children), l = n.identifier(X(r, "_v$")), a = o ? n.callExpression(o, [n.cloneNode(l)]) : ee(_(e.children, r, !0));
|
|
445
|
+
return g(n.blockStatement([
|
|
446
|
+
n.variableDeclaration("const", [n.variableDeclarator(l, k(i, r))]),
|
|
447
|
+
n.returnStatement(n.conditionalExpression(n.cloneNode(l), a, s))
|
|
448
|
+
]));
|
|
449
|
+
}
|
|
450
|
+
function an(e, t, r) {
|
|
451
|
+
let i = Te(t, r);
|
|
452
|
+
if (i === null) return null;
|
|
453
|
+
let s = i.fallback || n.nullLiteral();
|
|
454
|
+
for (let o = i.arms.length - 1; o >= 0; o--)
|
|
455
|
+
s = n.conditionalExpression(k(i.arms[o].when, r), ee(_(i.arms[o].children, r, !0)), s);
|
|
456
|
+
return g(s);
|
|
457
|
+
}
|
|
458
|
+
function un(e, t, r) {
|
|
459
|
+
let i = y(e, "each"), s = y(e, "key"), o = y(e, "fallback"), l = e.children.find((u) => n.isJSXExpressionContainer(u) && !n.isJSXEmptyExpression(u.expression));
|
|
460
|
+
if (!i || !l)
|
|
461
|
+
throw D(t, r, '<For> needs an "each" prop and a render function child: <For each={items}>{(item) => <li>{item}</li>}</For>');
|
|
462
|
+
let a = [i, l.expression, s || n.booleanLiteral(!1), o || n.nullLiteral()], c = s ? O(e) : null;
|
|
463
|
+
return c !== null && a.push(c), d(r, "_$ssrFor", a);
|
|
464
|
+
}
|
|
465
|
+
var cn = [
|
|
466
|
+
["_$ssr", "ssr"],
|
|
467
|
+
["_$ssrForeign", "ssrForeign"],
|
|
468
|
+
["_$ssrRow", "ssrRow"],
|
|
469
|
+
["_$ssrText", "ssrText"],
|
|
470
|
+
["_$ssrList", "ssrList"],
|
|
471
|
+
["_$ssrFor", "ssrFor"],
|
|
472
|
+
["_$ssrTemplate", "ssrTemplate"],
|
|
473
|
+
["_$ssrElement", "ssrElement"],
|
|
474
|
+
["_$ssrRawText", "ssrRawText"],
|
|
475
|
+
["_$ssrComponent", "ssrComponent"],
|
|
476
|
+
["_$ssrLeaf", "ssrLeaf"],
|
|
477
|
+
["_$ssrFragment", "ssrFragment"],
|
|
478
|
+
["_$ssrIsland", "ssrIsland"]
|
|
479
|
+
];
|
|
480
|
+
function wn(e, t) {
|
|
481
|
+
for (let s of t.ssrTemplates.reverse()) {
|
|
482
|
+
let o = n.arrayExpression(s.strings.map((a) => n.stringLiteral(a))), l = o;
|
|
483
|
+
s.isStatic ? l = d(t, "_$ssr", [o]) : s.slots.length > 0 && (l = d(t, "_$ssrTemplate", [o, n.arrayExpression(s.slots.map((a) => a === null ? n.nullLiteral() : n.arrayExpression(a.map((c) => typeof c == "number" ? n.numericLiteral(c) : n.stringLiteral(c)))))])), l !== o && n.addComment(l, "leading", " @__PURE__ "), e.unshiftContainer("body", n.variableDeclaration("const", [n.variableDeclarator(n.identifier(s.id), l)]));
|
|
484
|
+
}
|
|
485
|
+
let r = be(t), i = [];
|
|
486
|
+
for (let [s, o] of cn) {
|
|
487
|
+
let l = r.get(s);
|
|
488
|
+
l !== void 0 && i.push(n.importSpecifier(n.identifier(l), n.identifier(o)));
|
|
489
|
+
}
|
|
490
|
+
pe(e, i, ["what-framework/ssr-runtime"], "what-framework/ssr-runtime");
|
|
491
|
+
}
|
|
492
|
+
export {
|
|
493
|
+
wn as finishSsrProgram,
|
|
494
|
+
xn as initSsrState,
|
|
495
|
+
Sn as transformSsrRoot
|
|
496
|
+
};
|