@fluixi/compiler 1.0.0-alpha.82 → 1.0.0-alpha.84
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.mjs +41 -1
- package/dist/analyze/intrinsics.cjs +80 -1
- package/dist/analyze/intrinsics.d.cts +66 -0
- 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.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.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.mjs +17 -1
- package/dist/analyze/static-graph.cjs +811 -0
- package/dist/analyze/static-graph.d.cts +102 -0
- package/dist/analyze/static-graph.d.ts +103 -0
- package/dist/analyze/static-graph.d.ts.map +1 -0
- package/dist/analyze/static-graph.js +869 -0
- package/dist/analyze/static-graph.mjs +793 -0
- package/dist/babel-NRW4EFTG.mjs +636 -0
- package/dist/chunk-3YKZ4GNH.mjs +11 -0
- package/dist/chunk-EZR7NZOY.mjs +1718 -0
- package/dist/chunk-FSSWUXUR.mjs +16 -0
- package/dist/chunk-MJV3UXIL.mjs +158 -0
- package/dist/chunk-R2VHAZAX.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.map +1 -1
- package/dist/codegen/backends/imperative.js +68 -13
- 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.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.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 +16 -0
- package/dist/codegen/serialize-static.d.ts.map +1 -1
- package/dist/codegen/serialize-static.js +25 -0
- 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.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.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.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.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.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 +1594 -13
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.mjs +1574 -13
- package/dist/integrations.cjs +4307 -25
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.d.ts +16 -0
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +21 -2
- package/dist/integrations.mjs +531 -17
- package/dist/ir/nodes.cjs +18 -1
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/ir/nodes.d.ts +46 -0
- package/dist/ir/nodes.d.ts.map +1 -1
- package/dist/lower/compile-template.cjs +1356 -1
- package/dist/lower/compile-template.d.cts +69 -0
- package/dist/lower/compile-template.d.ts +12 -0
- package/dist/lower/compile-template.d.ts.map +1 -1
- package/dist/lower/compile-template.js +5 -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 +2 -0
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +27 -4
- 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 +14 -1
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +106 -19
- 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.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.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.mjs +67 -1
- package/dist/options.cjs +33 -1
- package/dist/options.d.cts +39 -0
- 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.mjs +53 -1
- package/dist/resolve/component-globals.cjs +233 -13
- package/dist/resolve/component-globals.d.cts +80 -0
- package/dist/resolve/component-globals.mjs +210 -13
- package/dist/resolve/component-resolver.cjs +80 -1
- package/dist/resolve/component-resolver.d.cts +68 -0
- 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.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.mjs +85 -1
- package/dist/resolve/write-globals.cjs +318 -13
- package/dist/resolve/write-globals.d.cts +30 -0
- package/dist/resolve/write-globals.mjs +297 -13
- package/dist/server-fns-4ZXN6DYU.mjs +78 -0
- package/dist/server-functions-V6D6DRIA.mjs +82 -0
- package/dist/transform/bindings.cjs +71 -1
- package/dist/transform/bindings.d.cts +16 -0
- 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.mjs +193 -3
- package/dist/transform/props.cjs +441 -3
- package/dist/transform/props.d.cts +45 -0
- 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.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.mjs +1155 -11
- package/dist/transform/source-locations.cjs +330 -0
- package/dist/transform/source-locations.d.cts +43 -0
- package/dist/transform/source-locations.d.ts +44 -0
- package/dist/transform/source-locations.d.ts.map +1 -0
- package/dist/transform/source-locations.js +238 -0
- package/dist/transform/source-locations.mjs +307 -0
- package/dist/transform/templates.cjs +2701 -7
- package/dist/transform/templates.d.cts +69 -0
- package/dist/transform/templates.d.ts +12 -4
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +72 -7
- package/dist/transform/templates.mjs +3743 -16
- package/dist/transform-BT4MMASR.mjs +893 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/dist/babel-4JUDAR2G.mjs +0 -1
- package/dist/chunk-3SAEGOMQ.mjs +0 -1
- package/dist/chunk-IBRM4W7I.mjs +0 -10
- package/dist/chunk-OHHZCYIQ.mjs +0 -1
- package/dist/chunk-PVR2SN3B.mjs +0 -1
- package/dist/chunk-QUIYULS2.mjs +0 -1
- package/dist/chunk-YR3SAEO7.mjs +0 -1
- package/dist/server-fns-6QM243HC.mjs +0 -2
- package/dist/server-functions-E3LKCZ4R.mjs +0 -1
- package/dist/transform-5WC4FWJE.mjs +0 -8
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { planPartialTemplate } from '../partial-template.js';
|
|
2
|
-
import { isSerializable, serializeStatic, isPlainLiteralAttr, htmlAttrName, } from '../serialize-static.js';
|
|
2
|
+
import { isSerializable, serializeStatic, templatePositions, isPlainLiteralAttr, htmlAttrName, } from '../serialize-static.js';
|
|
3
3
|
import { RUNTIME_CONTRACT_V1 } from '../contract.js';
|
|
4
|
+
import { markHole, markProps, SOURCE_MARKER } from '../../transform/source-locations.js';
|
|
5
|
+
import { paren } from '../../analyze/paren.js';
|
|
4
6
|
/**
|
|
5
7
|
* Imperative fine-grained backend — emits createNativeElement/insert/spread/
|
|
6
8
|
* createComponent (RUNTIME_CONTRACT_V1), the runtime proven by the @fluixi/dom
|
|
@@ -34,9 +36,17 @@ function propKey(name) {
|
|
|
34
36
|
}
|
|
35
37
|
function propValue(p) {
|
|
36
38
|
if (p.expr !== undefined) {
|
|
39
|
+
// A ref is not reactive, but which variable ends up holding the element is worth
|
|
40
|
+
// saying, so it carries its own text and position.
|
|
41
|
+
if (p.name === 'ref' && p.at)
|
|
42
|
+
return markHole(paren(p.expr, 'value'), p.at.line, p.at.column, p.expr);
|
|
37
43
|
// Events and non-reactive expressions pass through; reactive ones become thunks
|
|
38
44
|
// so the runtime (spread/insert) can wire a render effect.
|
|
39
|
-
|
|
45
|
+
if (!p.reactive)
|
|
46
|
+
return paren(p.expr, 'value');
|
|
47
|
+
const accessor = `() => ${paren(p.expr, 'arrowBody')}`;
|
|
48
|
+
// `at` is the gate: a production build carries no marker.
|
|
49
|
+
return p.at ? markHole(accessor, p.at.line, p.at.column, p.directive) : accessor;
|
|
40
50
|
}
|
|
41
51
|
return JSON.stringify(p.literal ?? true);
|
|
42
52
|
}
|
|
@@ -49,8 +59,9 @@ function propValue(p) {
|
|
|
49
59
|
* function instead of the value (e.g. `history.get is not a function`).
|
|
50
60
|
*/
|
|
51
61
|
function componentPropValue(p) {
|
|
62
|
+
// Sits in a `return`, where a top-level comma would read as a sequence.
|
|
52
63
|
if (p.expr !== undefined)
|
|
53
|
-
return
|
|
64
|
+
return paren(p.expr, 'value');
|
|
54
65
|
return JSON.stringify(p.literal ?? true);
|
|
55
66
|
}
|
|
56
67
|
/** Build a props object literal (or mergeProps(...) when spreads are present). */
|
|
@@ -67,12 +78,20 @@ function emitProps(props, childrenExpr, used) {
|
|
|
67
78
|
}
|
|
68
79
|
return obj;
|
|
69
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* The memo a component lowers to is an accessor, so it takes the same hole mark as any
|
|
83
|
+
* other reactive binding. Without it, the insert that places the subtree reports whatever
|
|
84
|
+
* the runtime stack says — a position in the compiled file.
|
|
85
|
+
*/
|
|
86
|
+
function markBind(code, at) {
|
|
87
|
+
return at ? markHole(code, at.line, at.column) : code;
|
|
88
|
+
}
|
|
70
89
|
function emitChildren(children, used, templates) {
|
|
71
90
|
if (children.length === 1)
|
|
72
91
|
return emitNode(children[0], used, templates);
|
|
73
92
|
return `[${children.map((c) => emitNode(c, used, templates)).join(', ')}]`;
|
|
74
93
|
}
|
|
75
|
-
function emitComponent(name, props, children, used, templates) {
|
|
94
|
+
function emitComponent(name, props, children, used, templates, at) {
|
|
76
95
|
used.add('createMemo');
|
|
77
96
|
used.add('createComponent');
|
|
78
97
|
const spreads = props.filter((p) => p.kind === 'spread');
|
|
@@ -95,6 +114,14 @@ function emitComponent(name, props, children, used, templates) {
|
|
|
95
114
|
used.add('mergeProps');
|
|
96
115
|
obj = `mergeProps(${spreads.map((s) => s.expr).join(', ')}, ${obj})`;
|
|
97
116
|
}
|
|
117
|
+
// Every prop is a getter, so none of them can carry a position. The map rides alongside,
|
|
118
|
+
// and a build that recorded no locations emits nothing.
|
|
119
|
+
const propAt = {};
|
|
120
|
+
for (const p of normal)
|
|
121
|
+
if (p.at)
|
|
122
|
+
propAt[p.name] = [p.at.line, p.at.column];
|
|
123
|
+
if (Object.keys(propAt).length)
|
|
124
|
+
obj = markProps(obj, propAt);
|
|
98
125
|
// The memo never recomputes — every prop is a getter, so this callback reads nothing
|
|
99
126
|
// reactive. It is here for what it makes `insert` do, and it cannot be elided.
|
|
100
127
|
//
|
|
@@ -115,7 +142,14 @@ function emitComponent(name, props, children, used, templates) {
|
|
|
115
142
|
// Control flow does use a bare arrow, and that is not a counter-example: control flow
|
|
116
143
|
// is the reactive boundary and is *meant* to re-run. A user component is meant to run
|
|
117
144
|
// once.
|
|
118
|
-
|
|
145
|
+
// The mark goes inside the call, where it runs before createMemo makes the node and so
|
|
146
|
+
// is the one the node takes. Devtools installs the global; without it this is a no-op.
|
|
147
|
+
const mark = at
|
|
148
|
+
? `globalThis.${SOURCE_MARKER}?.(${JSON.stringify(at.file)},${at.line},${at.column},${JSON.stringify(name)}), `
|
|
149
|
+
: '';
|
|
150
|
+
// The mark makes this a sequence, which has to stay wrapped to pass as one argument.
|
|
151
|
+
// Without one there is nothing to wrap, and a production build never has one.
|
|
152
|
+
return `createMemo(${paren(`${mark}() => createComponent(${name}, ${obj})`, 'value')})`;
|
|
119
153
|
}
|
|
120
154
|
/** `el.setAttribute("class", "card")` for a compile-time constant. */
|
|
121
155
|
function staticAttrAssignment(el, prop) {
|
|
@@ -133,18 +167,25 @@ function emitNode(node, used, templates) {
|
|
|
133
167
|
switch (node.kind) {
|
|
134
168
|
case 'text':
|
|
135
169
|
return JSON.stringify(node.value);
|
|
136
|
-
case 'expr':
|
|
137
|
-
|
|
170
|
+
case 'expr': {
|
|
171
|
+
if (!node.reactive)
|
|
172
|
+
return paren(node.code, 'value');
|
|
173
|
+
const accessor = `() => ${paren(node.code, 'arrowBody')}`;
|
|
174
|
+
return node.at ? markHole(accessor, node.at.line, node.at.column) : accessor;
|
|
175
|
+
}
|
|
138
176
|
case 'fragment':
|
|
139
177
|
if (node.children.length === 0)
|
|
140
178
|
return 'null';
|
|
141
179
|
return emitChildren(node.children, used, templates);
|
|
142
180
|
case 'component':
|
|
143
|
-
|
|
181
|
+
// No reactive prop means no `bindAt`, which is most tags. The insert that places the
|
|
182
|
+
// subtree still has to report somewhere, and the tag itself is where it was written —
|
|
183
|
+
// without this it reports whatever the runtime stack says, a line in the compiled file.
|
|
184
|
+
return markBind(emitComponent(node.name, node.props, node.children, used, templates, node.at), node.bindAt ?? node.at);
|
|
144
185
|
case 'control': {
|
|
145
186
|
const name = CONTROL_COMPONENT[node.control] ?? node.control;
|
|
146
187
|
used.add(name);
|
|
147
|
-
return emitComponent(name, node.props, node.children, used, templates);
|
|
188
|
+
return markBind(emitComponent(name, node.props, node.children, used, templates), node.bindAt);
|
|
148
189
|
}
|
|
149
190
|
case 'element': {
|
|
150
191
|
// A static subtree is parsed once into a <template> and cloned per instance:
|
|
@@ -157,7 +198,12 @@ function emitNode(node, used, templates) {
|
|
|
157
198
|
used.add('templateNode');
|
|
158
199
|
const id = `_tmpl$${templates.length}`;
|
|
159
200
|
templates.push({ id, html: serializeStatic(node), tag: node.tag, svg: false });
|
|
160
|
-
|
|
201
|
+
// The positions ride along so devtools can name the line each element was written
|
|
202
|
+
// on; the template string itself maps back to the root and nothing finer.
|
|
203
|
+
const at = templatePositions(node);
|
|
204
|
+
return at
|
|
205
|
+
? `templateNode(${id}, ${JSON.stringify(node.tag)}, false, false, ${JSON.stringify(at)})`
|
|
206
|
+
: `templateNode(${id}, ${JSON.stringify(node.tag)})`;
|
|
161
207
|
}
|
|
162
208
|
// Structure static, contents dynamic — the common shape. One template for the
|
|
163
209
|
// structure, then each hole filled through a reference into the clone. Every
|
|
@@ -172,7 +218,10 @@ function emitNode(node, used, templates) {
|
|
|
172
218
|
used.add('holeScope');
|
|
173
219
|
const id = `_tmpl$${templates.length}`;
|
|
174
220
|
templates.push({ id, html: plan.html, tag: plan.tag, svg: false });
|
|
175
|
-
const
|
|
221
|
+
const at = templatePositions(node);
|
|
222
|
+
const lines = [
|
|
223
|
+
`const _el$ = templateNode(${id}, ${JSON.stringify(plan.tag)}, true${at ? `, false, ${JSON.stringify(at)}` : ''});`,
|
|
224
|
+
];
|
|
176
225
|
// Every reference first: inserting shifts what follows, so the walk has to be
|
|
177
226
|
// complete before any content goes in.
|
|
178
227
|
for (const step of plan.steps)
|
|
@@ -184,7 +233,7 @@ function emitNode(node, used, templates) {
|
|
|
184
233
|
// `holeScope` places the hydration cursor at what the server rendered for
|
|
185
234
|
// this hole, so anything the content builds internally adopts too.
|
|
186
235
|
lines.push(`insert(${hole.parentRef}, holeScope(${hole.startRef}, () => ` +
|
|
187
|
-
|
|
236
|
+
`${paren(emitNode(hole.node, used, templates), 'arrowBody')}), ` +
|
|
188
237
|
`${hole.endRef}, holeContent(${hole.startRef}, ${hole.endRef}));`);
|
|
189
238
|
}
|
|
190
239
|
lines.push('return _el$;');
|
|
@@ -195,7 +244,13 @@ function emitNode(node, used, templates) {
|
|
|
195
244
|
const tag = JSON.stringify(node.tag);
|
|
196
245
|
const el = '_el$';
|
|
197
246
|
const parts = [];
|
|
198
|
-
|
|
247
|
+
// The third argument is where the tag was written. An element built this way is not
|
|
248
|
+
// in a template, so nothing else records it.
|
|
249
|
+
const createArgs = node.at
|
|
250
|
+
? `${tag}, ${node.svg}, ${JSON.stringify(node.at)}`
|
|
251
|
+
: node.svg
|
|
252
|
+
? `${tag}, true`
|
|
253
|
+
: tag;
|
|
199
254
|
parts.push(`const ${el} = createNativeElement(${createArgs});`);
|
|
200
255
|
if (node.props.length > 0) {
|
|
201
256
|
// Literal attributes are written straight on. `spread` is a generic helper that
|