@fluixi/compiler 1.0.0-alpha.83 → 1.0.0-alpha.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyze/expr-shape.cjs +62 -1
- package/dist/analyze/expr-shape.d.cts +14 -0
- package/dist/analyze/expr-shape.d.ts +2 -2
- package/dist/analyze/expr-shape.js +1 -1
- package/dist/analyze/expr-shape.mjs +41 -1
- package/dist/analyze/intrinsics.cjs +80 -1
- package/dist/analyze/intrinsics.d.cts +66 -0
- package/dist/analyze/intrinsics.d.ts +7 -7
- package/dist/analyze/intrinsics.d.ts.map +1 -1
- package/dist/analyze/intrinsics.js +3 -3
- package/dist/analyze/intrinsics.mjs +59 -1
- package/dist/analyze/paren.cjs +134 -0
- package/dist/analyze/paren.d.cts +23 -0
- package/dist/analyze/paren.d.ts +24 -0
- package/dist/analyze/paren.d.ts.map +1 -0
- package/dist/analyze/paren.js +168 -0
- package/dist/analyze/paren.mjs +113 -0
- package/dist/analyze/props-destructure.cjs +226 -1
- package/dist/analyze/props-destructure.d.cts +83 -0
- package/dist/analyze/props-destructure.d.ts +3 -3
- package/dist/analyze/props-destructure.d.ts.map +1 -1
- package/dist/analyze/props-destructure.js +4 -4
- package/dist/analyze/props-destructure.mjs +205 -1
- package/dist/analyze/reactive-bindings.cjs +190 -1
- package/dist/analyze/reactive-bindings.d.cts +42 -0
- package/dist/analyze/reactive-bindings.d.ts +1 -1
- package/dist/analyze/reactive-bindings.js +2 -2
- package/dist/analyze/reactive-bindings.mjs +167 -1
- package/dist/analyze/reactive-expr.cjs +38 -1
- package/dist/analyze/reactive-expr.d.cts +38 -0
- package/dist/analyze/reactive-expr.d.ts +4 -4
- package/dist/analyze/reactive-expr.d.ts.map +1 -1
- package/dist/analyze/reactive-expr.js +2 -2
- package/dist/analyze/reactive-expr.mjs +17 -1
- package/dist/analyze/static-graph.cjs +811 -1
- package/dist/analyze/static-graph.d.cts +102 -0
- package/dist/analyze/static-graph.d.ts +1 -1
- package/dist/analyze/static-graph.d.ts.map +1 -1
- package/dist/analyze/static-graph.js +11 -11
- package/dist/analyze/static-graph.mjs +793 -1
- package/dist/babel-TGY76XJ7.mjs +636 -0
- package/dist/chunk-4PLHS2FP.mjs +158 -0
- package/dist/chunk-6DB5FXS4.mjs +1718 -0
- package/dist/chunk-F74GFKSL.mjs +16 -0
- package/dist/chunk-G6QC2WRJ.mjs +11 -0
- package/dist/chunk-RUDJDZAA.mjs +1078 -0
- package/dist/codegen/backend.cjs +18 -1
- package/dist/codegen/backend.d.cts +35 -0
- package/dist/codegen/backends/imperative.cjs +542 -1
- package/dist/codegen/backends/imperative.d.cts +11 -0
- package/dist/codegen/backends/imperative.d.ts +1 -1
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +24 -20
- package/dist/codegen/backends/imperative.mjs +519 -1
- package/dist/codegen/contract.cjs +52 -1
- package/dist/codegen/contract.d.cts +24 -0
- package/dist/codegen/contract.d.ts +2 -2
- package/dist/codegen/contract.js +2 -2
- package/dist/codegen/contract.mjs +31 -1
- package/dist/codegen/partial-template.cjs +176 -1
- package/dist/codegen/partial-template.d.cts +61 -0
- package/dist/codegen/partial-template.d.ts +4 -4
- package/dist/codegen/partial-template.js +0 -0
- package/dist/codegen/partial-template.mjs +153 -1
- package/dist/codegen/serialize-static.cjs +125 -1
- package/dist/codegen/serialize-static.d.cts +38 -0
- package/dist/codegen/serialize-static.d.ts +3 -3
- package/dist/codegen/serialize-static.js +6 -6
- package/dist/codegen/serialize-static.mjs +104 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
- package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
- package/dist/frontend/babel/build-ir-lit.d.ts +2 -2
- package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
- package/dist/frontend/babel/build-ir.cjs +1524 -1
- package/dist/frontend/babel/build-ir.d.cts +35 -0
- package/dist/frontend/babel/build-ir.d.ts +2 -2
- package/dist/frontend/babel/build-ir.js +2 -2
- package/dist/frontend/babel/build-ir.mjs +1495 -1
- package/dist/frontend/babel/index.cjs +2186 -1
- package/dist/frontend/babel/index.d.cts +33 -0
- package/dist/frontend/babel/index.d.ts +1 -1
- package/dist/frontend/babel/index.js +1 -1
- package/dist/frontend/babel/index.mjs +2156 -1
- package/dist/frontend/babel/lower-template.cjs +1507 -1
- package/dist/frontend/babel/lower-template.d.cts +23 -0
- package/dist/frontend/babel/lower-template.d.ts +1 -1
- package/dist/frontend/babel/lower-template.js +2 -2
- package/dist/frontend/babel/lower-template.mjs +1478 -1
- package/dist/frontend/babel/plugin.cjs +2132 -1
- package/dist/frontend/babel/plugin.d.cts +95 -0
- package/dist/frontend/babel/plugin.d.ts +5 -5
- package/dist/frontend/babel/plugin.d.ts.map +1 -1
- package/dist/frontend/babel/plugin.js +14 -14
- package/dist/frontend/babel/plugin.mjs +2103 -1
- package/dist/frontend/babel/server-functions.cjs +110 -1
- package/dist/frontend/babel/server-functions.d.cts +10 -0
- package/dist/frontend/babel/server-functions.mjs +89 -1
- package/dist/frontend/babel/types.cjs +18 -1
- package/dist/frontend/babel/types.d.cts +33 -0
- package/dist/frontend/types.cjs +18 -1
- package/dist/frontend/types.d.cts +25 -0
- package/dist/frontend/vocabulary.cjs +98 -0
- package/dist/frontend/vocabulary.d.cts +79 -0
- package/dist/frontend/vocabulary.d.ts +80 -0
- package/dist/frontend/vocabulary.d.ts.map +1 -0
- package/dist/frontend/vocabulary.js +124 -0
- package/dist/frontend/vocabulary.mjs +77 -0
- package/dist/index.cjs +1595 -14
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +1575 -14
- package/dist/integrations.cjs +4312 -26
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.d.ts +9 -9
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +29 -8
- package/dist/integrations.mjs +536 -18
- package/dist/ir/nodes.cjs +18 -1
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/ir/nodes.d.ts +6 -6
- package/dist/lower/compile-template.cjs +1356 -1
- package/dist/lower/compile-template.d.cts +69 -0
- package/dist/lower/compile-template.d.ts +3 -3
- package/dist/lower/compile-template.js +1 -1
- package/dist/lower/compile-template.mjs +1336 -1
- package/dist/lower/jsx.cjs +529 -1
- package/dist/lower/jsx.d.cts +25 -0
- package/dist/lower/jsx.d.ts +1 -1
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +6 -5
- package/dist/lower/jsx.mjs +506 -1
- package/dist/lower/template.cjs +1061 -1
- package/dist/lower/template.d.cts +53 -0
- package/dist/lower/template.d.ts +3 -3
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +12 -11
- package/dist/lower/template.mjs +1042 -1
- package/dist/lower/text.cjs +42 -1
- package/dist/lower/text.d.cts +10 -0
- package/dist/lower/text.d.ts +2 -2
- package/dist/lower/text.d.ts.map +1 -1
- package/dist/lower/text.js +2 -2
- package/dist/lower/text.mjs +21 -1
- package/dist/optimize/analyze-static.cjs +112 -1
- package/dist/optimize/analyze-static.d.cts +39 -0
- package/dist/optimize/analyze-static.d.ts +2 -2
- package/dist/optimize/analyze-static.js +2 -2
- package/dist/optimize/analyze-static.mjs +91 -1
- package/dist/optimize/collapse-strategies.cjs +90 -1
- package/dist/optimize/collapse-strategies.d.cts +30 -0
- package/dist/optimize/collapse-strategies.d.ts +3 -3
- package/dist/optimize/collapse-strategies.mjs +67 -1
- package/dist/options.cjs +33 -1
- package/dist/options.d.cts +39 -0
- package/dist/options.d.ts +2 -2
- package/dist/options.mjs +12 -1
- package/dist/resolve/builtins.cjs +73 -1
- package/dist/resolve/builtins.d.cts +68 -0
- package/dist/resolve/builtins.d.ts +8 -8
- package/dist/resolve/builtins.d.ts.map +1 -1
- package/dist/resolve/builtins.js +4 -4
- package/dist/resolve/builtins.mjs +53 -1
- package/dist/resolve/component-globals.cjs +234 -14
- package/dist/resolve/component-globals.d.cts +80 -0
- package/dist/resolve/component-globals.d.ts +5 -5
- package/dist/resolve/component-globals.js +10 -10
- package/dist/resolve/component-globals.mjs +211 -14
- package/dist/resolve/component-resolver.cjs +80 -1
- package/dist/resolve/component-resolver.d.cts +68 -0
- package/dist/resolve/component-resolver.d.ts +3 -3
- package/dist/resolve/component-resolver.d.ts.map +1 -1
- package/dist/resolve/component-resolver.js +3 -3
- package/dist/resolve/component-resolver.mjs +59 -1
- package/dist/resolve/load-directive.cjs +93 -1
- package/dist/resolve/load-directive.d.cts +53 -0
- package/dist/resolve/load-directive.d.ts +5 -5
- package/dist/resolve/load-directive.js +6 -6
- package/dist/resolve/load-directive.mjs +72 -1
- package/dist/resolve/resolve-ir.cjs +108 -1
- package/dist/resolve/resolve-ir.d.cts +53 -0
- package/dist/resolve/resolve-ir.d.ts +6 -6
- package/dist/resolve/resolve-ir.d.ts.map +1 -1
- package/dist/resolve/resolve-ir.js +1 -1
- package/dist/resolve/resolve-ir.mjs +85 -1
- package/dist/resolve/write-globals.cjs +319 -14
- package/dist/resolve/write-globals.d.cts +30 -0
- package/dist/resolve/write-globals.js +2 -2
- package/dist/resolve/write-globals.mjs +298 -14
- package/dist/server-fns-ZYWQTSZU.mjs +78 -0
- package/dist/server-functions-PCERFA7A.mjs +82 -0
- package/dist/transform/bindings.cjs +71 -1
- package/dist/transform/bindings.d.cts +16 -0
- package/dist/transform/bindings.d.ts +1 -1
- package/dist/transform/bindings.js +1 -1
- package/dist/transform/bindings.mjs +50 -1
- package/dist/transform/index.cjs +2732 -8
- package/dist/transform/index.d.cts +15 -0
- package/dist/transform/index.mjs +3773 -17
- package/dist/transform/intrinsics.cjs +216 -3
- package/dist/transform/intrinsics.d.cts +21 -0
- package/dist/transform/intrinsics.js +1 -1
- package/dist/transform/intrinsics.mjs +193 -3
- package/dist/transform/props.cjs +441 -3
- package/dist/transform/props.d.cts +45 -0
- package/dist/transform/props.d.ts +1 -1
- package/dist/transform/props.d.ts.map +1 -1
- package/dist/transform/props.js +4 -4
- package/dist/transform/props.mjs +1482 -12
- package/dist/transform/server-fn-id.cjs +35 -1
- package/dist/transform/server-fn-id.d.cts +9 -0
- package/dist/transform/server-fn-id.d.ts +1 -1
- package/dist/transform/server-fn-id.js +2 -2
- package/dist/transform/server-fn-id.mjs +14 -1
- package/dist/transform/server-fns.cjs +114 -2
- package/dist/transform/server-fns.d.cts +12 -0
- package/dist/transform/server-fns.js +3 -3
- package/dist/transform/server-fns.mjs +1155 -11
- package/dist/transform/source-locations.cjs +330 -1
- package/dist/transform/source-locations.d.cts +43 -0
- package/dist/transform/source-locations.d.ts +1 -1
- package/dist/transform/source-locations.js +5 -5
- package/dist/transform/source-locations.mjs +307 -1
- package/dist/transform/templates.cjs +2701 -7
- package/dist/transform/templates.d.cts +69 -0
- package/dist/transform/templates.d.ts +2 -2
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +7 -7
- package/dist/transform/templates.mjs +3743 -16
- package/dist/transform-RWDTQUF5.mjs +893 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/dist/babel-VXKH6MRQ.mjs +0 -1
- package/dist/chunk-3SAEGOMQ.mjs +0 -1
- package/dist/chunk-5KMMN5QP.mjs +0 -1
- package/dist/chunk-IBRM4W7I.mjs +0 -10
- package/dist/chunk-OHHZCYIQ.mjs +0 -1
- package/dist/chunk-YKZ54NVE.mjs +0 -1
- package/dist/server-fns-6QM243HC.mjs +0 -2
- package/dist/server-functions-E3LKCZ4R.mjs +0 -1
- package/dist/transform-C4ZXRVGP.mjs +0 -8
package/dist/lower/jsx.mjs
CHANGED
|
@@ -1 +1,506 @@
|
|
|
1
|
-
|
|
1
|
+
// src/resolve/load-directive.ts
|
|
2
|
+
var EAGER = { kind: "eager" };
|
|
3
|
+
var DEFAULT_INTERACTION_EVENTS = ["pointerdown", "focusin", "keydown"];
|
|
4
|
+
var STRATEGIES = /* @__PURE__ */ new Set(["eager", "idle", "visible", "interaction", "media", "never"]);
|
|
5
|
+
var LoadDirectiveError = class extends Error {
|
|
6
|
+
};
|
|
7
|
+
function isLoadDirective(name) {
|
|
8
|
+
return name.startsWith("load:");
|
|
9
|
+
}
|
|
10
|
+
function parseLoadDirective(name, value) {
|
|
11
|
+
const strategy = name.slice("load:".length);
|
|
12
|
+
if (!STRATEGIES.has(strategy)) {
|
|
13
|
+
throw new LoadDirectiveError(
|
|
14
|
+
`Unknown load strategy 'load:${strategy}'. Expected one of ${[...STRATEGIES].join(", ")}.`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
switch (strategy) {
|
|
18
|
+
case "eager":
|
|
19
|
+
return EAGER;
|
|
20
|
+
case "idle":
|
|
21
|
+
return { kind: "idle" };
|
|
22
|
+
case "never":
|
|
23
|
+
return { kind: "never" };
|
|
24
|
+
case "visible":
|
|
25
|
+
return value ? { kind: "visible", rootMargin: value } : { kind: "visible" };
|
|
26
|
+
case "interaction":
|
|
27
|
+
return {
|
|
28
|
+
kind: "interaction",
|
|
29
|
+
events: value ? splitEvents(value) : [...DEFAULT_INTERACTION_EVENTS]
|
|
30
|
+
};
|
|
31
|
+
case "media":
|
|
32
|
+
if (!value) {
|
|
33
|
+
throw new LoadDirectiveError(
|
|
34
|
+
`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
return { kind: "media", query: value };
|
|
38
|
+
default:
|
|
39
|
+
throw new LoadDirectiveError(`Unhandled load strategy '${strategy}'.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function splitEvents(value) {
|
|
43
|
+
const events = value.split(/[\s,]+/).map((e) => e.trim()).filter(Boolean);
|
|
44
|
+
if (events.length === 0) {
|
|
45
|
+
throw new LoadDirectiveError(`'load:interaction' was given no event names.`);
|
|
46
|
+
}
|
|
47
|
+
return events;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/analyze/reactive-expr.ts
|
|
51
|
+
var STABLE_MEMBER = "children";
|
|
52
|
+
function isReactiveShape(shape) {
|
|
53
|
+
switch (shape.kind) {
|
|
54
|
+
case "call":
|
|
55
|
+
return true;
|
|
56
|
+
case "member":
|
|
57
|
+
return shape.property !== STABLE_MEMBER;
|
|
58
|
+
case "compound":
|
|
59
|
+
return shape.parts.some(isReactiveShape);
|
|
60
|
+
case "opaque":
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// src/analyze/expr-shape.ts
|
|
66
|
+
var CALL = /* @__PURE__ */ new Set(["CallExpression", "OptionalCallExpression"]);
|
|
67
|
+
var MEMBER = /* @__PURE__ */ new Set(["MemberExpression", "OptionalMemberExpression"]);
|
|
68
|
+
function shapeOf(node) {
|
|
69
|
+
if (!node) return { kind: "opaque" };
|
|
70
|
+
if (CALL.has(node.type)) return { kind: "call" };
|
|
71
|
+
if (MEMBER.has(node.type)) {
|
|
72
|
+
const property = node.property;
|
|
73
|
+
const computed = node.computed === true;
|
|
74
|
+
return {
|
|
75
|
+
kind: "member",
|
|
76
|
+
property: !computed && property?.type === "Identifier" ? property.name : null
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (node.type === "ConditionalExpression") {
|
|
80
|
+
return { kind: "compound", parts: [node.test, node.consequent, node.alternate].map(part) };
|
|
81
|
+
}
|
|
82
|
+
if (node.type === "LogicalExpression" || node.type === "BinaryExpression") {
|
|
83
|
+
return { kind: "compound", parts: [node.left, node.right].map(part) };
|
|
84
|
+
}
|
|
85
|
+
if (node.type === "TemplateLiteral") {
|
|
86
|
+
return { kind: "compound", parts: node.expressions.map(part) };
|
|
87
|
+
}
|
|
88
|
+
if (node.type === "ObjectExpression") {
|
|
89
|
+
const props = node.properties.filter(
|
|
90
|
+
(p) => (p.type === "ObjectProperty" || p.type === "Property") && p.computed !== true
|
|
91
|
+
);
|
|
92
|
+
return { kind: "compound", parts: props.map((p) => part(p.value)) };
|
|
93
|
+
}
|
|
94
|
+
if (node.type === "ArrayExpression") {
|
|
95
|
+
const items = node.elements.filter(
|
|
96
|
+
(e) => e != null && e.type !== "SpreadElement"
|
|
97
|
+
);
|
|
98
|
+
return { kind: "compound", parts: items.map(part) };
|
|
99
|
+
}
|
|
100
|
+
return { kind: "opaque" };
|
|
101
|
+
}
|
|
102
|
+
var part = (n) => shapeOf(n);
|
|
103
|
+
|
|
104
|
+
// src/optimize/analyze-static.ts
|
|
105
|
+
function propReason(prop) {
|
|
106
|
+
switch (prop.kind) {
|
|
107
|
+
case "event":
|
|
108
|
+
return "event";
|
|
109
|
+
case "ref":
|
|
110
|
+
return "ref";
|
|
111
|
+
case "spread":
|
|
112
|
+
return "spread";
|
|
113
|
+
case "class":
|
|
114
|
+
case "style":
|
|
115
|
+
return "class-or-style-directive";
|
|
116
|
+
case "attr":
|
|
117
|
+
case "prop":
|
|
118
|
+
if (prop.reactive) return "reactive-prop";
|
|
119
|
+
if (prop.expr !== void 0) return "expression-prop";
|
|
120
|
+
return void 0;
|
|
121
|
+
/* c8 ignore next 2 */
|
|
122
|
+
default:
|
|
123
|
+
return "expression-prop";
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function analyzeStatic(root) {
|
|
127
|
+
const staticElements = [];
|
|
128
|
+
const reasons = /* @__PURE__ */ new Map();
|
|
129
|
+
const visit = (node) => {
|
|
130
|
+
switch (node.kind) {
|
|
131
|
+
case "text":
|
|
132
|
+
return true;
|
|
133
|
+
case "expr":
|
|
134
|
+
return false;
|
|
135
|
+
case "component":
|
|
136
|
+
case "control":
|
|
137
|
+
for (const child of node.children) visit(child);
|
|
138
|
+
return false;
|
|
139
|
+
case "fragment":
|
|
140
|
+
for (const child of node.children) visit(child);
|
|
141
|
+
return false;
|
|
142
|
+
case "element": {
|
|
143
|
+
let childrenStatic = true;
|
|
144
|
+
for (const child of node.children) {
|
|
145
|
+
if (!visit(child)) childrenStatic = false;
|
|
146
|
+
}
|
|
147
|
+
let reason;
|
|
148
|
+
for (const prop of node.props) {
|
|
149
|
+
reason = propReason(prop);
|
|
150
|
+
if (reason) break;
|
|
151
|
+
}
|
|
152
|
+
if (!reason && !childrenStatic) {
|
|
153
|
+
reason = childReason(node);
|
|
154
|
+
}
|
|
155
|
+
node.static = !reason;
|
|
156
|
+
if (reason) reasons.set(node, reason);
|
|
157
|
+
else staticElements.push(node);
|
|
158
|
+
return node.static;
|
|
159
|
+
}
|
|
160
|
+
/* c8 ignore next 2 */
|
|
161
|
+
default:
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
for (const node of Array.isArray(root) ? root : [root]) visit(node);
|
|
166
|
+
return { staticElements, reasons };
|
|
167
|
+
}
|
|
168
|
+
function childReason(node) {
|
|
169
|
+
for (const child of node.children) {
|
|
170
|
+
if (child.kind === "expr") return "expression-child";
|
|
171
|
+
if (child.kind === "component") return "component-child";
|
|
172
|
+
if (child.kind === "control") return "control-child";
|
|
173
|
+
if (child.kind === "element" && !child.static) return "expression-child";
|
|
174
|
+
if (child.kind === "fragment") return "expression-child";
|
|
175
|
+
}
|
|
176
|
+
return "expression-child";
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/lower/text.ts
|
|
180
|
+
function cleanTemplateText(value) {
|
|
181
|
+
const lines = value.split(/\r\n|\n|\r/);
|
|
182
|
+
let lastNonEmpty = 0;
|
|
183
|
+
for (let i = 0; i < lines.length; i++) {
|
|
184
|
+
if (/[^ \t]/.test(lines[i])) lastNonEmpty = i;
|
|
185
|
+
}
|
|
186
|
+
let out = "";
|
|
187
|
+
for (let i = 0; i < lines.length; i++) {
|
|
188
|
+
let line = lines[i].replace(/\t/g, " ");
|
|
189
|
+
if (i !== 0) line = line.replace(/^ +/, "");
|
|
190
|
+
if (i !== lines.length - 1) line = line.replace(/ +$/, "");
|
|
191
|
+
if (!line) continue;
|
|
192
|
+
if (i !== lastNonEmpty) line += " ";
|
|
193
|
+
out += line;
|
|
194
|
+
}
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/analyze/paren.ts
|
|
199
|
+
function skipQuoted(src, start) {
|
|
200
|
+
const quote = src[start];
|
|
201
|
+
for (let i = start + 1; i < src.length; i++) {
|
|
202
|
+
const c = src[i];
|
|
203
|
+
if (c === "\\") i++;
|
|
204
|
+
else if (c === quote) return i + 1;
|
|
205
|
+
else if (c === "\n") return -1;
|
|
206
|
+
}
|
|
207
|
+
return -1;
|
|
208
|
+
}
|
|
209
|
+
function skipTemplate(src, start) {
|
|
210
|
+
let i = start + 1;
|
|
211
|
+
while (i < src.length) {
|
|
212
|
+
const c = src[i];
|
|
213
|
+
if (c === "\\") {
|
|
214
|
+
i += 2;
|
|
215
|
+
} else if (c === "`") {
|
|
216
|
+
return i + 1;
|
|
217
|
+
} else if (c === "$" && src[i + 1] === "{") {
|
|
218
|
+
let depth = 1;
|
|
219
|
+
i += 2;
|
|
220
|
+
while (i < src.length && depth > 0) {
|
|
221
|
+
const k = src[i];
|
|
222
|
+
if (k === "\\") i += 2;
|
|
223
|
+
else if (k === "`") {
|
|
224
|
+
const end = skipTemplate(src, i);
|
|
225
|
+
if (end < 0) return -1;
|
|
226
|
+
i = end;
|
|
227
|
+
} else if (k === '"' || k === "'") {
|
|
228
|
+
const end = skipQuoted(src, i);
|
|
229
|
+
if (end < 0) return -1;
|
|
230
|
+
i = end;
|
|
231
|
+
} else {
|
|
232
|
+
if (k === "{") depth++;
|
|
233
|
+
else if (k === "}") depth--;
|
|
234
|
+
i++;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
i++;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return -1;
|
|
242
|
+
}
|
|
243
|
+
function skipRegex(src, start) {
|
|
244
|
+
let inClass = false;
|
|
245
|
+
for (let i = start + 1; i < src.length; i++) {
|
|
246
|
+
const c = src[i];
|
|
247
|
+
if (c === "\\") i++;
|
|
248
|
+
else if (c === "[") inClass = true;
|
|
249
|
+
else if (c === "]") inClass = false;
|
|
250
|
+
else if (c === "\n") return -1;
|
|
251
|
+
else if (c === "/" && !inClass) {
|
|
252
|
+
let end = i + 1;
|
|
253
|
+
while (end < src.length && /[a-z]/i.test(src[end])) end++;
|
|
254
|
+
return end;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return -1;
|
|
258
|
+
}
|
|
259
|
+
function divides(prev) {
|
|
260
|
+
return prev !== "" && /[A-Za-z0-9_$)\]]/.test(prev);
|
|
261
|
+
}
|
|
262
|
+
function topLevelComma(src) {
|
|
263
|
+
let depth = 0;
|
|
264
|
+
let prev = "";
|
|
265
|
+
let i = 0;
|
|
266
|
+
while (i < src.length) {
|
|
267
|
+
const c = src[i];
|
|
268
|
+
if (c === '"' || c === "'") {
|
|
269
|
+
const end = skipQuoted(src, i);
|
|
270
|
+
if (end < 0) return null;
|
|
271
|
+
i = end;
|
|
272
|
+
prev = c;
|
|
273
|
+
} else if (c === "`") {
|
|
274
|
+
const end = skipTemplate(src, i);
|
|
275
|
+
if (end < 0) return null;
|
|
276
|
+
i = end;
|
|
277
|
+
prev = c;
|
|
278
|
+
} else if (c === "/" && src[i + 1] === "/") {
|
|
279
|
+
return null;
|
|
280
|
+
} else if (c === "/" && src[i + 1] === "*") {
|
|
281
|
+
const end = src.indexOf("*/", i + 2);
|
|
282
|
+
if (end < 0) return null;
|
|
283
|
+
i = end + 2;
|
|
284
|
+
} else if (c === "/" && !divides(prev)) {
|
|
285
|
+
const end = skipRegex(src, i);
|
|
286
|
+
if (end < 0) return null;
|
|
287
|
+
i = end;
|
|
288
|
+
prev = "/";
|
|
289
|
+
} else {
|
|
290
|
+
if (c === "(" || c === "[" || c === "{") depth++;
|
|
291
|
+
else if (c === ")" || c === "]" || c === "}") {
|
|
292
|
+
depth--;
|
|
293
|
+
if (depth < 0) return null;
|
|
294
|
+
} else if (c === "," && depth === 0) return true;
|
|
295
|
+
if (!/\s/.test(c)) prev = c;
|
|
296
|
+
i++;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
return depth === 0 ? false : null;
|
|
300
|
+
}
|
|
301
|
+
function paren(code, position) {
|
|
302
|
+
const src = code.trim();
|
|
303
|
+
if (src === "") return `(${code})`;
|
|
304
|
+
if (position === "arrowBody" && src[0] === "{") return `(${code})`;
|
|
305
|
+
return topLevelComma(src) === false ? code : `(${code})`;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// src/lower/jsx.ts
|
|
309
|
+
var SVG_TAGS = /* @__PURE__ */ new Set([
|
|
310
|
+
"svg",
|
|
311
|
+
"path",
|
|
312
|
+
"circle",
|
|
313
|
+
"rect",
|
|
314
|
+
"line",
|
|
315
|
+
"polygon",
|
|
316
|
+
"polyline",
|
|
317
|
+
"ellipse",
|
|
318
|
+
"g",
|
|
319
|
+
"defs",
|
|
320
|
+
"clipPath",
|
|
321
|
+
"text"
|
|
322
|
+
]);
|
|
323
|
+
var EVENT_RE = /^on[A-Z]/;
|
|
324
|
+
var DELEGATED = /* @__PURE__ */ new Set([
|
|
325
|
+
"click",
|
|
326
|
+
"dblclick",
|
|
327
|
+
"input",
|
|
328
|
+
"change",
|
|
329
|
+
"submit",
|
|
330
|
+
"focus",
|
|
331
|
+
"blur",
|
|
332
|
+
"keydown",
|
|
333
|
+
"keyup",
|
|
334
|
+
"keypress",
|
|
335
|
+
"mousedown",
|
|
336
|
+
"mouseup"
|
|
337
|
+
]);
|
|
338
|
+
var isReactive = (node) => isReactiveShape(shapeOf(node));
|
|
339
|
+
var posOf = (node, ctx) => {
|
|
340
|
+
if (!ctx.sourceFile) return void 0;
|
|
341
|
+
const at = node.loc?.start;
|
|
342
|
+
return at ? { line: at.line, column: at.column } : void 0;
|
|
343
|
+
};
|
|
344
|
+
function literalOf(node) {
|
|
345
|
+
if (node.type === "StringLiteral" || node.type === "NumericLiteral" || node.type === "BooleanLiteral") {
|
|
346
|
+
return node.value;
|
|
347
|
+
}
|
|
348
|
+
if (node.type === "Literal" && (typeof node.value === "string" || typeof node.value === "number" || typeof node.value === "boolean")) {
|
|
349
|
+
return node.value;
|
|
350
|
+
}
|
|
351
|
+
return void 0;
|
|
352
|
+
}
|
|
353
|
+
var isString = (node) => !!node && typeof literalOf(node) === "string";
|
|
354
|
+
function tagInfo(name, ctx) {
|
|
355
|
+
if (name.type === "JSXIdentifier") {
|
|
356
|
+
return { tag: name.name, component: name.name[0] !== name.name[0].toLowerCase() };
|
|
357
|
+
}
|
|
358
|
+
if (name.type === "JSXMemberExpression") return { tag: ctx.code(name), component: true };
|
|
359
|
+
if (name.type === "JSXNamespacedName") {
|
|
360
|
+
return { tag: `${name.namespace.name}:${name.name.name}`, component: false };
|
|
361
|
+
}
|
|
362
|
+
return { tag: "div", component: false };
|
|
363
|
+
}
|
|
364
|
+
function attrName(name) {
|
|
365
|
+
if (name.type === "JSXIdentifier") return name.name === "class" ? "className" : name.name;
|
|
366
|
+
if (name.type === "JSXNamespacedName") return `${name.namespace.name}:${name.name.name}`;
|
|
367
|
+
return "unknown";
|
|
368
|
+
}
|
|
369
|
+
function buildAttr(attr, ctx) {
|
|
370
|
+
const name = attrName(attr.name);
|
|
371
|
+
const isEvent = EVENT_RE.test(name);
|
|
372
|
+
const isHandler = isEvent || name.startsWith("on:") || name === "ref";
|
|
373
|
+
const kind = isEvent ? "event" : "attr";
|
|
374
|
+
const base = { name, kind };
|
|
375
|
+
if (isEvent) {
|
|
376
|
+
const evt = name.slice(2).toLowerCase();
|
|
377
|
+
base.event = { name: evt, delegated: DELEGATED.has(evt) };
|
|
378
|
+
}
|
|
379
|
+
const v = attr.value;
|
|
380
|
+
if (v == null) {
|
|
381
|
+
base.literal = true;
|
|
382
|
+
base.at = posOf(attr, ctx);
|
|
383
|
+
return base;
|
|
384
|
+
}
|
|
385
|
+
if (isString(v)) {
|
|
386
|
+
base.literal = literalOf(v);
|
|
387
|
+
base.at = posOf(v, ctx);
|
|
388
|
+
return base;
|
|
389
|
+
}
|
|
390
|
+
if (v.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression") {
|
|
391
|
+
const expr = v.expression;
|
|
392
|
+
const literal = literalOf(expr);
|
|
393
|
+
if (literal !== void 0) {
|
|
394
|
+
base.literal = literal;
|
|
395
|
+
base.at = posOf(expr, ctx);
|
|
396
|
+
return base;
|
|
397
|
+
}
|
|
398
|
+
base.expr = ctx.code(expr);
|
|
399
|
+
base.reactive = isHandler ? false : isReactive(expr);
|
|
400
|
+
base.at = posOf(expr, ctx);
|
|
401
|
+
if (expr.type === "JSXElement" || expr.type === "JSXFragment") base.jsxElement = true;
|
|
402
|
+
return base;
|
|
403
|
+
}
|
|
404
|
+
base.literal = true;
|
|
405
|
+
return base;
|
|
406
|
+
}
|
|
407
|
+
function attrExprCode(attr, ctx) {
|
|
408
|
+
const v = attr.value;
|
|
409
|
+
if (v == null) return null;
|
|
410
|
+
if (isString(v)) return JSON.stringify(literalOf(v));
|
|
411
|
+
if (v.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression") {
|
|
412
|
+
return ctx.code(v.expression);
|
|
413
|
+
}
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
function buildProps(attrs, ctx) {
|
|
417
|
+
const props = [];
|
|
418
|
+
const usePairs = [];
|
|
419
|
+
for (const a of attrs) {
|
|
420
|
+
if (a.type === "JSXSpreadAttribute") {
|
|
421
|
+
props.push({ name: "", kind: "spread", expr: ctx.code(a.argument) });
|
|
422
|
+
continue;
|
|
423
|
+
}
|
|
424
|
+
if (a.type !== "JSXAttribute") continue;
|
|
425
|
+
if (isLoadDirective(attrName(a.name))) continue;
|
|
426
|
+
const ns = a.name.type === "JSXNamespacedName" ? a.name.namespace.name : null;
|
|
427
|
+
if (ns === "use") {
|
|
428
|
+
const dir = a.name.name.name;
|
|
429
|
+
ctx.used.add(dir);
|
|
430
|
+
const opts = attrExprCode(a, ctx);
|
|
431
|
+
usePairs.push(opts != null ? `[${dir}, () => ${paren(opts, "arrowBody")}]` : `[${dir}]`);
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (ns === "oncapture") {
|
|
435
|
+
const evt = a.name.name.name.toLowerCase();
|
|
436
|
+
const h = attrExprCode(a, ctx) ?? "undefined";
|
|
437
|
+
props.push({ name: "on:" + evt, kind: "attr", expr: `[${h}, { capture: true }]` });
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
props.push(buildAttr(a, ctx));
|
|
441
|
+
}
|
|
442
|
+
if (usePairs.length > 0) props.push({ name: "use", kind: "attr", expr: `[${usePairs.join(", ")}]` });
|
|
443
|
+
return props;
|
|
444
|
+
}
|
|
445
|
+
function buildChildren(children, ctx) {
|
|
446
|
+
const out = [];
|
|
447
|
+
for (const child of children) {
|
|
448
|
+
if (child.type === "JSXText") {
|
|
449
|
+
const text = cleanTemplateText(child.value);
|
|
450
|
+
if (text) out.push({ kind: "text", value: text });
|
|
451
|
+
} else if (child.type === "JSXExpressionContainer") {
|
|
452
|
+
if (child.expression?.type !== "JSXEmptyExpression") {
|
|
453
|
+
const expr = child.expression;
|
|
454
|
+
const reactive = isReactive(expr);
|
|
455
|
+
out.push({
|
|
456
|
+
kind: "expr",
|
|
457
|
+
code: ctx.code(expr),
|
|
458
|
+
reactive,
|
|
459
|
+
...reactive ? { at: posOf(expr, ctx) } : {}
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
} else if (child.type === "JSXElement" || child.type === "JSXFragment") {
|
|
463
|
+
out.push(buildNode(child, ctx));
|
|
464
|
+
} else if (child.type === "JSXSpreadChild") {
|
|
465
|
+
out.push({ kind: "expr", code: ctx.code(child.expression), reactive: false });
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return out;
|
|
469
|
+
}
|
|
470
|
+
function readLoad(attrs) {
|
|
471
|
+
for (const a of attrs) {
|
|
472
|
+
if (a.type !== "JSXAttribute") continue;
|
|
473
|
+
const name = attrName(a.name);
|
|
474
|
+
if (!isLoadDirective(name)) continue;
|
|
475
|
+
if (a.value && !isString(a.value)) {
|
|
476
|
+
throw new LoadDirectiveError(
|
|
477
|
+
`'${name}' needs a literal value, not an expression — the strategy is compile-time.`
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
return parseLoadDirective(name, a.value ? literalOf(a.value) : null);
|
|
481
|
+
}
|
|
482
|
+
return void 0;
|
|
483
|
+
}
|
|
484
|
+
function buildNode(node, ctx) {
|
|
485
|
+
if (node.type === "JSXFragment") {
|
|
486
|
+
return { kind: "fragment", children: buildChildren(node.children, ctx) };
|
|
487
|
+
}
|
|
488
|
+
const { tag, component } = tagInfo(node.openingElement.name, ctx);
|
|
489
|
+
const props = buildProps(node.openingElement.attributes, ctx);
|
|
490
|
+
const children = buildChildren(node.children, ctx);
|
|
491
|
+
const at = ctx.sourceFile && node.loc?.start ? { file: ctx.sourceFile, line: node.loc.start.line, column: node.loc.start.column } : void 0;
|
|
492
|
+
if (component) {
|
|
493
|
+
const load = readLoad(node.openingElement.attributes);
|
|
494
|
+
return { kind: "component", name: tag, props, children, ...load ? { load } : {}, ...at ? { at } : {} };
|
|
495
|
+
}
|
|
496
|
+
return { kind: "element", tag, svg: SVG_TAGS.has(tag), props, children, static: false, ...at ? { at } : {} };
|
|
497
|
+
}
|
|
498
|
+
function buildJsxIR(node, ctx) {
|
|
499
|
+
const ir = buildNode(node, ctx);
|
|
500
|
+
analyzeStatic(ir);
|
|
501
|
+
return ir;
|
|
502
|
+
}
|
|
503
|
+
export {
|
|
504
|
+
SVG_TAGS,
|
|
505
|
+
buildJsxIR
|
|
506
|
+
};
|