@fluixi/compiler 1.0.0-alpha.92 → 1.0.0-alpha.93
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/intrinsics.cjs +18 -0
- package/dist/analyze/intrinsics.d.ts.map +1 -1
- package/dist/analyze/intrinsics.js +18 -0
- package/dist/analyze/intrinsics.mjs +18 -0
- package/dist/analyze/reactive-bindings.cjs +18 -0
- package/dist/analyze/reactive-bindings.mjs +18 -0
- package/dist/analyze/static-graph.cjs +22 -4
- package/dist/analyze/static-graph.d.ts.map +1 -1
- package/dist/analyze/static-graph.js +6 -4
- package/dist/analyze/static-graph.mjs +22 -4
- package/dist/{babel-GI375YZ2.mjs → babel-RJHJQVEM.mjs} +4 -4
- package/dist/{chunk-QZ4CJPYP.mjs → chunk-56QSOVVL.mjs} +1 -1
- package/dist/{chunk-XJ5H2MXY.mjs → chunk-OD53TMER.mjs} +19 -1
- package/dist/{chunk-DWNWN5RH.mjs → chunk-R7PPFBCL.mjs} +1 -1
- package/dist/{chunk-VOUI6XPV.mjs → chunk-TJIH7TLX.mjs} +1 -1
- package/dist/{chunk-VC6X44FS.mjs → chunk-U7HCFLZ2.mjs} +153 -48
- package/dist/codegen/backends/imperative.cjs +24 -6
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +19 -4
- package/dist/codegen/backends/imperative.mjs +24 -6
- package/dist/frontend/babel/build-ir-lit.cjs +120 -43
- package/dist/frontend/babel/build-ir-lit.mjs +120 -43
- package/dist/frontend/babel/build-ir.cjs +120 -43
- package/dist/frontend/babel/build-ir.mjs +120 -43
- package/dist/frontend/babel/index.cjs +121 -44
- package/dist/frontend/babel/index.mjs +121 -44
- package/dist/frontend/babel/lower-template.cjs +120 -43
- package/dist/frontend/babel/lower-template.mjs +120 -43
- package/dist/frontend/babel/plugin.cjs +120 -43
- package/dist/frontend/babel/plugin.mjs +120 -43
- package/dist/index.cjs +41 -38
- package/dist/index.mjs +41 -38
- package/dist/integrations.cjs +176 -52
- package/dist/integrations.mjs +8 -8
- package/dist/lower/compile-template.cjs +41 -38
- package/dist/lower/compile-template.mjs +41 -38
- package/dist/lower/jsx.cjs +509 -6
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +114 -6
- package/dist/lower/jsx.mjs +509 -6
- package/dist/lower/template.cjs +40 -37
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +22 -30
- package/dist/lower/template.mjs +40 -37
- package/dist/resolve/builtins.cjs +1 -1
- package/dist/resolve/builtins.mjs +1 -1
- package/dist/resolve/component-globals.cjs +14 -0
- package/dist/resolve/component-globals.mjs +14 -0
- package/dist/resolve/write-globals.cjs +14 -0
- package/dist/resolve/write-globals.mjs +14 -0
- package/dist/{server-fns-BBZRZUPP.mjs → server-fns-ZFRDIQ2X.mjs} +4 -4
- package/dist/{server-functions-VEGLIFCE.mjs → server-functions-CTDXX67X.mjs} +3 -3
- package/dist/transform/index.cjs +170 -47
- package/dist/transform/index.mjs +170 -47
- package/dist/transform/intrinsics.cjs +18 -0
- package/dist/transform/intrinsics.mjs +18 -0
- package/dist/transform/source-locations.cjs +64 -3
- package/dist/transform/source-locations.d.cts +7 -2
- package/dist/transform/source-locations.d.ts +7 -2
- package/dist/transform/source-locations.d.ts.map +1 -1
- package/dist/transform/source-locations.js +68 -3
- package/dist/transform/source-locations.mjs +64 -3
- package/dist/transform/templates.cjs +169 -46
- package/dist/transform/templates.js +2 -2
- package/dist/transform/templates.mjs +169 -46
- package/dist/{transform-UWZ7ZGJ2.mjs → transform-QWWQDCXE.mjs} +7 -7
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +9 -3
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/compiler v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.93 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -328,6 +328,7 @@ var INTRINSICS = {
|
|
|
328
328
|
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
329
329
|
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
330
330
|
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
331
|
+
$cachedResource: { export: "cachedResource", module: "@fluixi/reactive/cached-resource", returns: "resource-handle" },
|
|
331
332
|
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
332
333
|
// name. Still worth having: no import to write, and when a shorter form is
|
|
333
334
|
// designed, the change is this line rather than a compiler pass.
|
|
@@ -338,6 +339,19 @@ var INTRINSICS = {
|
|
|
338
339
|
// dependency analysis must not guess at.
|
|
339
340
|
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
340
341
|
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" },
|
|
342
|
+
// Scopes, scheduling and lifecycle: no value to classify, but the same authoring promise,
|
|
343
|
+
// no import to write. `$cleanup` registers a callback on the current owner (`onCleanup`).
|
|
344
|
+
$batch: { export: "batch", module: REACTIVE_MODULE, returns: "plain" },
|
|
345
|
+
$cleanup: { export: "onCleanup", module: REACTIVE_MODULE, returns: "plain" },
|
|
346
|
+
$root: { export: "root", module: REACTIVE_MODULE, returns: "plain" },
|
|
347
|
+
$context: { export: "context", module: REACTIVE_MODULE, returns: "plain" },
|
|
348
|
+
$renderEffect: { export: "renderEffect", module: REACTIVE_MODULE, returns: "effect" },
|
|
349
|
+
$computed: { export: "computed", module: REACTIVE_MODULE, returns: "effect" },
|
|
350
|
+
// Storage for where the code runs, and a signal kept in it. `$persisted` is a signal
|
|
351
|
+
// handle as far as reads go: the same accessor with `set` on it.
|
|
352
|
+
$storage: { export: "useStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
353
|
+
$asyncStorage: { export: "useAsyncStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
354
|
+
$persisted: { export: "persisted", module: "@fluixi/core/storage", returns: "signal-handle" },
|
|
341
355
|
// An environment variable, public or server-only; the browser build refuses a secret.
|
|
342
356
|
$env: { export: "env", module: "@fluixi/start/env", returns: "plain" }
|
|
343
357
|
};
|
|
@@ -515,13 +529,16 @@ function emitComponent(name, props, children, used, templates, at) {
|
|
|
515
529
|
used.add("createComponent");
|
|
516
530
|
const spreads = props.filter((p) => p.kind === "spread");
|
|
517
531
|
const normal = props.filter((p) => p.kind !== "spread");
|
|
518
|
-
const
|
|
519
|
-
(p) => `get ${propKey(p.name)}() { return ${componentPropValue(p)}; }`
|
|
520
|
-
);
|
|
532
|
+
const bodies = normal.map((p) => [p.name, componentPropValue(p)]);
|
|
521
533
|
if (children.length > 0) {
|
|
522
|
-
|
|
534
|
+
bodies.push(["children", emitChildren(children, used, templates)]);
|
|
535
|
+
}
|
|
536
|
+
let obj = `{ ${bodies.map(([name2, body]) => `get ${propKey(name2)}() { return ${body}; }`).join(", ")} }`;
|
|
537
|
+
if (bodies.some(([, body]) => /\bthis\b/.test(body))) {
|
|
538
|
+
const thunks = bodies.map(([name2, body]) => `${JSON.stringify(name2)}: () => ${body}`);
|
|
539
|
+
const getters = bodies.map(([name2]) => `get ${propKey(name2)}() { return _$t[${JSON.stringify(name2)}](); }`);
|
|
540
|
+
obj = `((_$t) => ({ ${getters.join(", ")} }))({ ${thunks.join(", ")} })`;
|
|
523
541
|
}
|
|
524
|
-
let obj = `{ ${entries.join(", ")} }`;
|
|
525
542
|
if (spreads.length > 0) {
|
|
526
543
|
used.add("mergeProps");
|
|
527
544
|
obj = `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
|
|
@@ -603,7 +620,8 @@ function emitNode(node, used, templates) {
|
|
|
603
620
|
} else {
|
|
604
621
|
used.add("spread");
|
|
605
622
|
const svgFlag = node.svg ? ", isSVG: true" : "";
|
|
606
|
-
const
|
|
623
|
+
const accessors = node.props.filter((p) => p.kind !== "spread" && p.expr !== void 0 && p.reactive && p.name !== "ref").map((p) => p.name);
|
|
624
|
+
const customFlag = node.tag.includes("-") ? `, isCustomElement: true, accessors: ${JSON.stringify(accessors)}` : "";
|
|
607
625
|
parts.push(
|
|
608
626
|
`spread({ element: ${el}, props: ${emitProps(node.props, null, used)}${svgFlag}${customFlag} });`
|
|
609
627
|
);
|
|
@@ -674,6 +692,7 @@ var DELEGATED = /* @__PURE__ */ new Set([
|
|
|
674
692
|
function escapeTemplate(s) {
|
|
675
693
|
return s.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
676
694
|
}
|
|
695
|
+
var CONTAINER = "container";
|
|
677
696
|
function capitalize(s) {
|
|
678
697
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
679
698
|
}
|
|
@@ -728,10 +747,6 @@ var Lowerer = class {
|
|
|
728
747
|
if (hasElse) i = elseIdx;
|
|
729
748
|
continue;
|
|
730
749
|
}
|
|
731
|
-
if (child.attributes.some((a) => a.kind === "EachDirective")) {
|
|
732
|
-
out.push(this.lowerEach(child));
|
|
733
|
-
continue;
|
|
734
|
-
}
|
|
735
750
|
}
|
|
736
751
|
const node = this.lowerNode(child);
|
|
737
752
|
if (node) out.push(node);
|
|
@@ -773,13 +788,16 @@ var Lowerer = class {
|
|
|
773
788
|
node.props.unshift({ name: "component", kind: "attr", expr: `() => ${paren(this.hole(isAttr.value.hole).code, "arrowBody")}` });
|
|
774
789
|
return node;
|
|
775
790
|
}
|
|
791
|
+
const each = this.lowerEach(el);
|
|
792
|
+
const children = each ? [each] : this.lowerChildren(el.children);
|
|
793
|
+
if (el.tag === CONTAINER) return children.length === 1 ? children[0] : { kind: "fragment", children };
|
|
776
794
|
const at = this.tagAt(el);
|
|
777
795
|
return {
|
|
778
796
|
kind: "element",
|
|
779
797
|
tag: el.tag,
|
|
780
798
|
svg: el.namespace === "svg",
|
|
781
799
|
props: this.lowerAttributes(el.attributes),
|
|
782
|
-
children
|
|
800
|
+
children,
|
|
783
801
|
static: false,
|
|
784
802
|
...at ? { at } : {}
|
|
785
803
|
};
|
|
@@ -851,10 +869,14 @@ var Lowerer = class {
|
|
|
851
869
|
const at = this.tagAt(el);
|
|
852
870
|
return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
|
|
853
871
|
}
|
|
854
|
-
/**
|
|
872
|
+
/**
|
|
873
|
+
* `<el each=${items} key?>${item => …}</el>` → `<el><For each>{item => …}</For></el>`: the
|
|
874
|
+
* content is repeated per item. Content that is not a `${item => …}` arrow is repeated as
|
|
875
|
+
* it is. Null when the element has no `each`.
|
|
876
|
+
*/
|
|
855
877
|
lowerEach(el) {
|
|
856
878
|
const eachDir = el.attributes.find((a) => a.kind === "EachDirective");
|
|
857
|
-
if (!eachDir || eachDir.kind !== "EachDirective") return
|
|
879
|
+
if (!eachDir || eachDir.kind !== "EachDirective") return null;
|
|
858
880
|
const each = this.hole(eachDir.hole);
|
|
859
881
|
const props = [{ name: "each", kind: "attr", expr: each.code, reactive: each.reactive, ...each.at ? { at: each.at } : {} }];
|
|
860
882
|
if (eachDir.key) {
|
|
@@ -864,12 +886,12 @@ var Lowerer = class {
|
|
|
864
886
|
const arrow = this.itemArrow(el);
|
|
865
887
|
let childrenCode;
|
|
866
888
|
if (arrow) {
|
|
867
|
-
const
|
|
868
|
-
|
|
869
|
-
childrenCode = `(${arrow.params.join(", ")}) => ${paren(this.emit(repeated), "arrowBody")}`;
|
|
889
|
+
const body = arrow.bodyReactive ? `() => ${paren(arrow.body, "arrowBody")}` : paren(arrow.body, "arrowBody");
|
|
890
|
+
childrenCode = `(${arrow.params.join(", ")}) => ${body}`;
|
|
870
891
|
} else {
|
|
871
|
-
const
|
|
872
|
-
|
|
892
|
+
const content = this.lowerChildren(el.children);
|
|
893
|
+
const ir = content.length === 1 ? content[0] : { kind: "fragment", children: content };
|
|
894
|
+
childrenCode = `() => ${paren(this.emit(ir), "arrowBody")}`;
|
|
873
895
|
}
|
|
874
896
|
const children = [{ kind: "expr", code: childrenCode, reactive: false }];
|
|
875
897
|
const at = this.tagAt(el);
|
|
@@ -886,25 +908,6 @@ var Lowerer = class {
|
|
|
886
908
|
const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
|
|
887
909
|
return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
|
|
888
910
|
}
|
|
889
|
-
/** Same element (minus each/key) but with explicit IR children. */
|
|
890
|
-
rebuildWithChildren(el, children) {
|
|
891
|
-
const props = this.lowerAttributes(
|
|
892
|
-
el.attributes.filter((a) => a.kind !== "EachDirective")
|
|
893
|
-
);
|
|
894
|
-
if (el.kind === "Element") {
|
|
895
|
-
const at = this.tagAt(el);
|
|
896
|
-
return {
|
|
897
|
-
kind: "element",
|
|
898
|
-
tag: el.tag,
|
|
899
|
-
svg: el.namespace === "svg",
|
|
900
|
-
props,
|
|
901
|
-
children,
|
|
902
|
-
static: false,
|
|
903
|
-
...at ? { at } : {}
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
return { kind: "component", name: el.tag, props, children };
|
|
907
|
-
}
|
|
908
911
|
// --- attributes ---------------------------------------------------------
|
|
909
912
|
lowerAttributes(attrs) {
|
|
910
913
|
const props = [];
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/compiler v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.93 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
|
|
3
3
|
// src/analyze/reactive-expr.ts
|
|
4
4
|
var STABLE_MEMBER = "children";
|
|
@@ -281,6 +281,7 @@ var INTRINSICS = {
|
|
|
281
281
|
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
282
282
|
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
283
283
|
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
284
|
+
$cachedResource: { export: "cachedResource", module: "@fluixi/reactive/cached-resource", returns: "resource-handle" },
|
|
284
285
|
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
285
286
|
// name. Still worth having: no import to write, and when a shorter form is
|
|
286
287
|
// designed, the change is this line rather than a compiler pass.
|
|
@@ -291,6 +292,19 @@ var INTRINSICS = {
|
|
|
291
292
|
// dependency analysis must not guess at.
|
|
292
293
|
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
293
294
|
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" },
|
|
295
|
+
// Scopes, scheduling and lifecycle: no value to classify, but the same authoring promise,
|
|
296
|
+
// no import to write. `$cleanup` registers a callback on the current owner (`onCleanup`).
|
|
297
|
+
$batch: { export: "batch", module: REACTIVE_MODULE, returns: "plain" },
|
|
298
|
+
$cleanup: { export: "onCleanup", module: REACTIVE_MODULE, returns: "plain" },
|
|
299
|
+
$root: { export: "root", module: REACTIVE_MODULE, returns: "plain" },
|
|
300
|
+
$context: { export: "context", module: REACTIVE_MODULE, returns: "plain" },
|
|
301
|
+
$renderEffect: { export: "renderEffect", module: REACTIVE_MODULE, returns: "effect" },
|
|
302
|
+
$computed: { export: "computed", module: REACTIVE_MODULE, returns: "effect" },
|
|
303
|
+
// Storage for where the code runs, and a signal kept in it. `$persisted` is a signal
|
|
304
|
+
// handle as far as reads go: the same accessor with `set` on it.
|
|
305
|
+
$storage: { export: "useStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
306
|
+
$asyncStorage: { export: "useAsyncStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
307
|
+
$persisted: { export: "persisted", module: "@fluixi/core/storage", returns: "signal-handle" },
|
|
294
308
|
// An environment variable, public or server-only; the browser build refuses a secret.
|
|
295
309
|
$env: { export: "env", module: "@fluixi/start/env", returns: "plain" }
|
|
296
310
|
};
|
|
@@ -468,13 +482,16 @@ function emitComponent(name, props, children, used, templates, at) {
|
|
|
468
482
|
used.add("createComponent");
|
|
469
483
|
const spreads = props.filter((p) => p.kind === "spread");
|
|
470
484
|
const normal = props.filter((p) => p.kind !== "spread");
|
|
471
|
-
const
|
|
472
|
-
(p) => `get ${propKey(p.name)}() { return ${componentPropValue(p)}; }`
|
|
473
|
-
);
|
|
485
|
+
const bodies = normal.map((p) => [p.name, componentPropValue(p)]);
|
|
474
486
|
if (children.length > 0) {
|
|
475
|
-
|
|
487
|
+
bodies.push(["children", emitChildren(children, used, templates)]);
|
|
488
|
+
}
|
|
489
|
+
let obj = `{ ${bodies.map(([name2, body]) => `get ${propKey(name2)}() { return ${body}; }`).join(", ")} }`;
|
|
490
|
+
if (bodies.some(([, body]) => /\bthis\b/.test(body))) {
|
|
491
|
+
const thunks = bodies.map(([name2, body]) => `${JSON.stringify(name2)}: () => ${body}`);
|
|
492
|
+
const getters = bodies.map(([name2]) => `get ${propKey(name2)}() { return _$t[${JSON.stringify(name2)}](); }`);
|
|
493
|
+
obj = `((_$t) => ({ ${getters.join(", ")} }))({ ${thunks.join(", ")} })`;
|
|
476
494
|
}
|
|
477
|
-
let obj = `{ ${entries.join(", ")} }`;
|
|
478
495
|
if (spreads.length > 0) {
|
|
479
496
|
used.add("mergeProps");
|
|
480
497
|
obj = `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
|
|
@@ -556,7 +573,8 @@ function emitNode(node, used, templates) {
|
|
|
556
573
|
} else {
|
|
557
574
|
used.add("spread");
|
|
558
575
|
const svgFlag = node.svg ? ", isSVG: true" : "";
|
|
559
|
-
const
|
|
576
|
+
const accessors = node.props.filter((p) => p.kind !== "spread" && p.expr !== void 0 && p.reactive && p.name !== "ref").map((p) => p.name);
|
|
577
|
+
const customFlag = node.tag.includes("-") ? `, isCustomElement: true, accessors: ${JSON.stringify(accessors)}` : "";
|
|
560
578
|
parts.push(
|
|
561
579
|
`spread({ element: ${el}, props: ${emitProps(node.props, null, used)}${svgFlag}${customFlag} });`
|
|
562
580
|
);
|
|
@@ -627,6 +645,7 @@ var DELEGATED = /* @__PURE__ */ new Set([
|
|
|
627
645
|
function escapeTemplate(s) {
|
|
628
646
|
return s.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
629
647
|
}
|
|
648
|
+
var CONTAINER = "container";
|
|
630
649
|
function capitalize(s) {
|
|
631
650
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
632
651
|
}
|
|
@@ -681,10 +700,6 @@ var Lowerer = class {
|
|
|
681
700
|
if (hasElse) i = elseIdx;
|
|
682
701
|
continue;
|
|
683
702
|
}
|
|
684
|
-
if (child.attributes.some((a) => a.kind === "EachDirective")) {
|
|
685
|
-
out.push(this.lowerEach(child));
|
|
686
|
-
continue;
|
|
687
|
-
}
|
|
688
703
|
}
|
|
689
704
|
const node = this.lowerNode(child);
|
|
690
705
|
if (node) out.push(node);
|
|
@@ -726,13 +741,16 @@ var Lowerer = class {
|
|
|
726
741
|
node.props.unshift({ name: "component", kind: "attr", expr: `() => ${paren(this.hole(isAttr.value.hole).code, "arrowBody")}` });
|
|
727
742
|
return node;
|
|
728
743
|
}
|
|
744
|
+
const each = this.lowerEach(el);
|
|
745
|
+
const children = each ? [each] : this.lowerChildren(el.children);
|
|
746
|
+
if (el.tag === CONTAINER) return children.length === 1 ? children[0] : { kind: "fragment", children };
|
|
729
747
|
const at = this.tagAt(el);
|
|
730
748
|
return {
|
|
731
749
|
kind: "element",
|
|
732
750
|
tag: el.tag,
|
|
733
751
|
svg: el.namespace === "svg",
|
|
734
752
|
props: this.lowerAttributes(el.attributes),
|
|
735
|
-
children
|
|
753
|
+
children,
|
|
736
754
|
static: false,
|
|
737
755
|
...at ? { at } : {}
|
|
738
756
|
};
|
|
@@ -804,10 +822,14 @@ var Lowerer = class {
|
|
|
804
822
|
const at = this.tagAt(el);
|
|
805
823
|
return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
|
|
806
824
|
}
|
|
807
|
-
/**
|
|
825
|
+
/**
|
|
826
|
+
* `<el each=${items} key?>${item => …}</el>` → `<el><For each>{item => …}</For></el>`: the
|
|
827
|
+
* content is repeated per item. Content that is not a `${item => …}` arrow is repeated as
|
|
828
|
+
* it is. Null when the element has no `each`.
|
|
829
|
+
*/
|
|
808
830
|
lowerEach(el) {
|
|
809
831
|
const eachDir = el.attributes.find((a) => a.kind === "EachDirective");
|
|
810
|
-
if (!eachDir || eachDir.kind !== "EachDirective") return
|
|
832
|
+
if (!eachDir || eachDir.kind !== "EachDirective") return null;
|
|
811
833
|
const each = this.hole(eachDir.hole);
|
|
812
834
|
const props = [{ name: "each", kind: "attr", expr: each.code, reactive: each.reactive, ...each.at ? { at: each.at } : {} }];
|
|
813
835
|
if (eachDir.key) {
|
|
@@ -817,12 +839,12 @@ var Lowerer = class {
|
|
|
817
839
|
const arrow = this.itemArrow(el);
|
|
818
840
|
let childrenCode;
|
|
819
841
|
if (arrow) {
|
|
820
|
-
const
|
|
821
|
-
|
|
822
|
-
childrenCode = `(${arrow.params.join(", ")}) => ${paren(this.emit(repeated), "arrowBody")}`;
|
|
842
|
+
const body = arrow.bodyReactive ? `() => ${paren(arrow.body, "arrowBody")}` : paren(arrow.body, "arrowBody");
|
|
843
|
+
childrenCode = `(${arrow.params.join(", ")}) => ${body}`;
|
|
823
844
|
} else {
|
|
824
|
-
const
|
|
825
|
-
|
|
845
|
+
const content = this.lowerChildren(el.children);
|
|
846
|
+
const ir = content.length === 1 ? content[0] : { kind: "fragment", children: content };
|
|
847
|
+
childrenCode = `() => ${paren(this.emit(ir), "arrowBody")}`;
|
|
826
848
|
}
|
|
827
849
|
const children = [{ kind: "expr", code: childrenCode, reactive: false }];
|
|
828
850
|
const at = this.tagAt(el);
|
|
@@ -839,25 +861,6 @@ var Lowerer = class {
|
|
|
839
861
|
const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
|
|
840
862
|
return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
|
|
841
863
|
}
|
|
842
|
-
/** Same element (minus each/key) but with explicit IR children. */
|
|
843
|
-
rebuildWithChildren(el, children) {
|
|
844
|
-
const props = this.lowerAttributes(
|
|
845
|
-
el.attributes.filter((a) => a.kind !== "EachDirective")
|
|
846
|
-
);
|
|
847
|
-
if (el.kind === "Element") {
|
|
848
|
-
const at = this.tagAt(el);
|
|
849
|
-
return {
|
|
850
|
-
kind: "element",
|
|
851
|
-
tag: el.tag,
|
|
852
|
-
svg: el.namespace === "svg",
|
|
853
|
-
props,
|
|
854
|
-
children,
|
|
855
|
-
static: false,
|
|
856
|
-
...at ? { at } : {}
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
return { kind: "component", name: el.tag, props, children };
|
|
860
|
-
}
|
|
861
864
|
// --- attributes ---------------------------------------------------------
|
|
862
865
|
lowerAttributes(attrs) {
|
|
863
866
|
const props = [];
|