@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
|
@@ -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;
|
|
@@ -468,6 +468,7 @@ var INTRINSICS = {
|
|
|
468
468
|
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
469
469
|
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
470
470
|
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
471
|
+
$cachedResource: { export: "cachedResource", module: "@fluixi/reactive/cached-resource", returns: "resource-handle" },
|
|
471
472
|
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
472
473
|
// name. Still worth having: no import to write, and when a shorter form is
|
|
473
474
|
// designed, the change is this line rather than a compiler pass.
|
|
@@ -478,6 +479,19 @@ var INTRINSICS = {
|
|
|
478
479
|
// dependency analysis must not guess at.
|
|
479
480
|
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
480
481
|
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" },
|
|
482
|
+
// Scopes, scheduling and lifecycle: no value to classify, but the same authoring promise,
|
|
483
|
+
// no import to write. `$cleanup` registers a callback on the current owner (`onCleanup`).
|
|
484
|
+
$batch: { export: "batch", module: REACTIVE_MODULE, returns: "plain" },
|
|
485
|
+
$cleanup: { export: "onCleanup", module: REACTIVE_MODULE, returns: "plain" },
|
|
486
|
+
$root: { export: "root", module: REACTIVE_MODULE, returns: "plain" },
|
|
487
|
+
$context: { export: "context", module: REACTIVE_MODULE, returns: "plain" },
|
|
488
|
+
$renderEffect: { export: "renderEffect", module: REACTIVE_MODULE, returns: "effect" },
|
|
489
|
+
$computed: { export: "computed", module: REACTIVE_MODULE, returns: "effect" },
|
|
490
|
+
// Storage for where the code runs, and a signal kept in it. `$persisted` is a signal
|
|
491
|
+
// handle as far as reads go: the same accessor with `set` on it.
|
|
492
|
+
$storage: { export: "useStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
493
|
+
$asyncStorage: { export: "useAsyncStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
494
|
+
$persisted: { export: "persisted", module: "@fluixi/core/storage", returns: "signal-handle" },
|
|
481
495
|
// An environment variable, public or server-only; the browser build refuses a secret.
|
|
482
496
|
$env: { export: "env", module: "@fluixi/start/env", returns: "plain" }
|
|
483
497
|
};
|
|
@@ -655,13 +669,16 @@ function emitComponent(name, props, children, used, templates, at) {
|
|
|
655
669
|
used.add("createComponent");
|
|
656
670
|
const spreads = props.filter((p) => p.kind === "spread");
|
|
657
671
|
const normal = props.filter((p) => p.kind !== "spread");
|
|
658
|
-
const
|
|
659
|
-
(p) => `get ${propKey(p.name)}() { return ${componentPropValue(p)}; }`
|
|
660
|
-
);
|
|
672
|
+
const bodies = normal.map((p) => [p.name, componentPropValue(p)]);
|
|
661
673
|
if (children.length > 0) {
|
|
662
|
-
|
|
674
|
+
bodies.push(["children", emitChildren(children, used, templates)]);
|
|
675
|
+
}
|
|
676
|
+
let obj = `{ ${bodies.map(([name2, body]) => `get ${propKey(name2)}() { return ${body}; }`).join(", ")} }`;
|
|
677
|
+
if (bodies.some(([, body]) => /\bthis\b/.test(body))) {
|
|
678
|
+
const thunks = bodies.map(([name2, body]) => `${JSON.stringify(name2)}: () => ${body}`);
|
|
679
|
+
const getters = bodies.map(([name2]) => `get ${propKey(name2)}() { return _$t[${JSON.stringify(name2)}](); }`);
|
|
680
|
+
obj = `((_$t) => ({ ${getters.join(", ")} }))({ ${thunks.join(", ")} })`;
|
|
663
681
|
}
|
|
664
|
-
let obj = `{ ${entries.join(", ")} }`;
|
|
665
682
|
if (spreads.length > 0) {
|
|
666
683
|
used.add("mergeProps");
|
|
667
684
|
obj = `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
|
|
@@ -743,7 +760,8 @@ function emitNode(node, used, templates) {
|
|
|
743
760
|
} else {
|
|
744
761
|
used.add("spread");
|
|
745
762
|
const svgFlag = node.svg ? ", isSVG: true" : "";
|
|
746
|
-
const
|
|
763
|
+
const accessors = node.props.filter((p) => p.kind !== "spread" && p.expr !== void 0 && p.reactive && p.name !== "ref").map((p) => p.name);
|
|
764
|
+
const customFlag = node.tag.includes("-") ? `, isCustomElement: true, accessors: ${JSON.stringify(accessors)}` : "";
|
|
747
765
|
parts.push(
|
|
748
766
|
`spread({ element: ${el}, props: ${emitProps(node.props, null, used)}${svgFlag}${customFlag} });`
|
|
749
767
|
);
|
|
@@ -874,6 +892,7 @@ var DELEGATED = /* @__PURE__ */ new Set([
|
|
|
874
892
|
function escapeTemplate(s) {
|
|
875
893
|
return s.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
876
894
|
}
|
|
895
|
+
var CONTAINER = "container";
|
|
877
896
|
function capitalize(s) {
|
|
878
897
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
879
898
|
}
|
|
@@ -928,10 +947,6 @@ var Lowerer = class {
|
|
|
928
947
|
if (hasElse) i = elseIdx;
|
|
929
948
|
continue;
|
|
930
949
|
}
|
|
931
|
-
if (child.attributes.some((a) => a.kind === "EachDirective")) {
|
|
932
|
-
out.push(this.lowerEach(child));
|
|
933
|
-
continue;
|
|
934
|
-
}
|
|
935
950
|
}
|
|
936
951
|
const node = this.lowerNode(child);
|
|
937
952
|
if (node) out.push(node);
|
|
@@ -973,13 +988,16 @@ var Lowerer = class {
|
|
|
973
988
|
node.props.unshift({ name: "component", kind: "attr", expr: `() => ${paren(this.hole(isAttr.value.hole).code, "arrowBody")}` });
|
|
974
989
|
return node;
|
|
975
990
|
}
|
|
991
|
+
const each = this.lowerEach(el);
|
|
992
|
+
const children = each ? [each] : this.lowerChildren(el.children);
|
|
993
|
+
if (el.tag === CONTAINER) return children.length === 1 ? children[0] : { kind: "fragment", children };
|
|
976
994
|
const at = this.tagAt(el);
|
|
977
995
|
return {
|
|
978
996
|
kind: "element",
|
|
979
997
|
tag: el.tag,
|
|
980
998
|
svg: el.namespace === "svg",
|
|
981
999
|
props: this.lowerAttributes(el.attributes),
|
|
982
|
-
children
|
|
1000
|
+
children,
|
|
983
1001
|
static: false,
|
|
984
1002
|
...at ? { at } : {}
|
|
985
1003
|
};
|
|
@@ -1051,10 +1069,14 @@ var Lowerer = class {
|
|
|
1051
1069
|
const at = this.tagAt(el);
|
|
1052
1070
|
return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
|
|
1053
1071
|
}
|
|
1054
|
-
/**
|
|
1072
|
+
/**
|
|
1073
|
+
* `<el each=${items} key?>${item => …}</el>` → `<el><For each>{item => …}</For></el>`: the
|
|
1074
|
+
* content is repeated per item. Content that is not a `${item => …}` arrow is repeated as
|
|
1075
|
+
* it is. Null when the element has no `each`.
|
|
1076
|
+
*/
|
|
1055
1077
|
lowerEach(el) {
|
|
1056
1078
|
const eachDir = el.attributes.find((a) => a.kind === "EachDirective");
|
|
1057
|
-
if (!eachDir || eachDir.kind !== "EachDirective") return
|
|
1079
|
+
if (!eachDir || eachDir.kind !== "EachDirective") return null;
|
|
1058
1080
|
const each = this.hole(eachDir.hole);
|
|
1059
1081
|
const props = [{ name: "each", kind: "attr", expr: each.code, reactive: each.reactive, ...each.at ? { at: each.at } : {} }];
|
|
1060
1082
|
if (eachDir.key) {
|
|
@@ -1064,12 +1086,12 @@ var Lowerer = class {
|
|
|
1064
1086
|
const arrow = this.itemArrow(el);
|
|
1065
1087
|
let childrenCode;
|
|
1066
1088
|
if (arrow) {
|
|
1067
|
-
const
|
|
1068
|
-
|
|
1069
|
-
childrenCode = `(${arrow.params.join(", ")}) => ${paren(this.emit(repeated), "arrowBody")}`;
|
|
1089
|
+
const body = arrow.bodyReactive ? `() => ${paren(arrow.body, "arrowBody")}` : paren(arrow.body, "arrowBody");
|
|
1090
|
+
childrenCode = `(${arrow.params.join(", ")}) => ${body}`;
|
|
1070
1091
|
} else {
|
|
1071
|
-
const
|
|
1072
|
-
|
|
1092
|
+
const content = this.lowerChildren(el.children);
|
|
1093
|
+
const ir = content.length === 1 ? content[0] : { kind: "fragment", children: content };
|
|
1094
|
+
childrenCode = `() => ${paren(this.emit(ir), "arrowBody")}`;
|
|
1073
1095
|
}
|
|
1074
1096
|
const children = [{ kind: "expr", code: childrenCode, reactive: false }];
|
|
1075
1097
|
const at = this.tagAt(el);
|
|
@@ -1086,25 +1108,6 @@ var Lowerer = class {
|
|
|
1086
1108
|
const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
|
|
1087
1109
|
return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
|
|
1088
1110
|
}
|
|
1089
|
-
/** Same element (minus each/key) but with explicit IR children. */
|
|
1090
|
-
rebuildWithChildren(el, children) {
|
|
1091
|
-
const props = this.lowerAttributes(
|
|
1092
|
-
el.attributes.filter((a) => a.kind !== "EachDirective")
|
|
1093
|
-
);
|
|
1094
|
-
if (el.kind === "Element") {
|
|
1095
|
-
const at = this.tagAt(el);
|
|
1096
|
-
return {
|
|
1097
|
-
kind: "element",
|
|
1098
|
-
tag: el.tag,
|
|
1099
|
-
svg: el.namespace === "svg",
|
|
1100
|
-
props,
|
|
1101
|
-
children,
|
|
1102
|
-
static: false,
|
|
1103
|
-
...at ? { at } : {}
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
return { kind: "component", name: el.tag, props, children };
|
|
1107
|
-
}
|
|
1108
1111
|
// --- attributes ---------------------------------------------------------
|
|
1109
1112
|
lowerAttributes(attrs) {
|
|
1110
1113
|
const props = [];
|
|
@@ -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/optimize/analyze-static.ts
|
|
4
4
|
function propReason(prop) {
|
|
@@ -442,6 +442,7 @@ var INTRINSICS = {
|
|
|
442
442
|
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
443
443
|
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
444
444
|
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
445
|
+
$cachedResource: { export: "cachedResource", module: "@fluixi/reactive/cached-resource", returns: "resource-handle" },
|
|
445
446
|
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
446
447
|
// name. Still worth having: no import to write, and when a shorter form is
|
|
447
448
|
// designed, the change is this line rather than a compiler pass.
|
|
@@ -452,6 +453,19 @@ var INTRINSICS = {
|
|
|
452
453
|
// dependency analysis must not guess at.
|
|
453
454
|
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
454
455
|
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" },
|
|
456
|
+
// Scopes, scheduling and lifecycle: no value to classify, but the same authoring promise,
|
|
457
|
+
// no import to write. `$cleanup` registers a callback on the current owner (`onCleanup`).
|
|
458
|
+
$batch: { export: "batch", module: REACTIVE_MODULE, returns: "plain" },
|
|
459
|
+
$cleanup: { export: "onCleanup", module: REACTIVE_MODULE, returns: "plain" },
|
|
460
|
+
$root: { export: "root", module: REACTIVE_MODULE, returns: "plain" },
|
|
461
|
+
$context: { export: "context", module: REACTIVE_MODULE, returns: "plain" },
|
|
462
|
+
$renderEffect: { export: "renderEffect", module: REACTIVE_MODULE, returns: "effect" },
|
|
463
|
+
$computed: { export: "computed", module: REACTIVE_MODULE, returns: "effect" },
|
|
464
|
+
// Storage for where the code runs, and a signal kept in it. `$persisted` is a signal
|
|
465
|
+
// handle as far as reads go: the same accessor with `set` on it.
|
|
466
|
+
$storage: { export: "useStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
467
|
+
$asyncStorage: { export: "useAsyncStorage", module: "@fluixi/core/storage", returns: "plain" },
|
|
468
|
+
$persisted: { export: "persisted", module: "@fluixi/core/storage", returns: "signal-handle" },
|
|
455
469
|
// An environment variable, public or server-only; the browser build refuses a secret.
|
|
456
470
|
$env: { export: "env", module: "@fluixi/start/env", returns: "plain" }
|
|
457
471
|
};
|
|
@@ -629,13 +643,16 @@ function emitComponent(name, props, children, used, templates, at) {
|
|
|
629
643
|
used.add("createComponent");
|
|
630
644
|
const spreads = props.filter((p) => p.kind === "spread");
|
|
631
645
|
const normal = props.filter((p) => p.kind !== "spread");
|
|
632
|
-
const
|
|
633
|
-
(p) => `get ${propKey(p.name)}() { return ${componentPropValue(p)}; }`
|
|
634
|
-
);
|
|
646
|
+
const bodies = normal.map((p) => [p.name, componentPropValue(p)]);
|
|
635
647
|
if (children.length > 0) {
|
|
636
|
-
|
|
648
|
+
bodies.push(["children", emitChildren(children, used, templates)]);
|
|
649
|
+
}
|
|
650
|
+
let obj = `{ ${bodies.map(([name2, body]) => `get ${propKey(name2)}() { return ${body}; }`).join(", ")} }`;
|
|
651
|
+
if (bodies.some(([, body]) => /\bthis\b/.test(body))) {
|
|
652
|
+
const thunks = bodies.map(([name2, body]) => `${JSON.stringify(name2)}: () => ${body}`);
|
|
653
|
+
const getters = bodies.map(([name2]) => `get ${propKey(name2)}() { return _$t[${JSON.stringify(name2)}](); }`);
|
|
654
|
+
obj = `((_$t) => ({ ${getters.join(", ")} }))({ ${thunks.join(", ")} })`;
|
|
637
655
|
}
|
|
638
|
-
let obj = `{ ${entries.join(", ")} }`;
|
|
639
656
|
if (spreads.length > 0) {
|
|
640
657
|
used.add("mergeProps");
|
|
641
658
|
obj = `mergeProps(${spreads.map((s) => s.expr).join(", ")}, ${obj})`;
|
|
@@ -717,7 +734,8 @@ function emitNode(node, used, templates) {
|
|
|
717
734
|
} else {
|
|
718
735
|
used.add("spread");
|
|
719
736
|
const svgFlag = node.svg ? ", isSVG: true" : "";
|
|
720
|
-
const
|
|
737
|
+
const accessors = node.props.filter((p) => p.kind !== "spread" && p.expr !== void 0 && p.reactive && p.name !== "ref").map((p) => p.name);
|
|
738
|
+
const customFlag = node.tag.includes("-") ? `, isCustomElement: true, accessors: ${JSON.stringify(accessors)}` : "";
|
|
721
739
|
parts.push(
|
|
722
740
|
`spread({ element: ${el}, props: ${emitProps(node.props, null, used)}${svgFlag}${customFlag} });`
|
|
723
741
|
);
|
|
@@ -850,6 +868,7 @@ var DELEGATED = /* @__PURE__ */ new Set([
|
|
|
850
868
|
function escapeTemplate(s) {
|
|
851
869
|
return s.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
852
870
|
}
|
|
871
|
+
var CONTAINER = "container";
|
|
853
872
|
function capitalize(s) {
|
|
854
873
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
855
874
|
}
|
|
@@ -904,10 +923,6 @@ var Lowerer = class {
|
|
|
904
923
|
if (hasElse) i = elseIdx;
|
|
905
924
|
continue;
|
|
906
925
|
}
|
|
907
|
-
if (child.attributes.some((a) => a.kind === "EachDirective")) {
|
|
908
|
-
out.push(this.lowerEach(child));
|
|
909
|
-
continue;
|
|
910
|
-
}
|
|
911
926
|
}
|
|
912
927
|
const node = this.lowerNode(child);
|
|
913
928
|
if (node) out.push(node);
|
|
@@ -949,13 +964,16 @@ var Lowerer = class {
|
|
|
949
964
|
node.props.unshift({ name: "component", kind: "attr", expr: `() => ${paren(this.hole(isAttr.value.hole).code, "arrowBody")}` });
|
|
950
965
|
return node;
|
|
951
966
|
}
|
|
967
|
+
const each = this.lowerEach(el);
|
|
968
|
+
const children = each ? [each] : this.lowerChildren(el.children);
|
|
969
|
+
if (el.tag === CONTAINER) return children.length === 1 ? children[0] : { kind: "fragment", children };
|
|
952
970
|
const at = this.tagAt(el);
|
|
953
971
|
return {
|
|
954
972
|
kind: "element",
|
|
955
973
|
tag: el.tag,
|
|
956
974
|
svg: el.namespace === "svg",
|
|
957
975
|
props: this.lowerAttributes(el.attributes),
|
|
958
|
-
children
|
|
976
|
+
children,
|
|
959
977
|
static: false,
|
|
960
978
|
...at ? { at } : {}
|
|
961
979
|
};
|
|
@@ -1027,10 +1045,14 @@ var Lowerer = class {
|
|
|
1027
1045
|
const at = this.tagAt(el);
|
|
1028
1046
|
return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
|
|
1029
1047
|
}
|
|
1030
|
-
/**
|
|
1048
|
+
/**
|
|
1049
|
+
* `<el each=${items} key?>${item => …}</el>` → `<el><For each>{item => …}</For></el>`: the
|
|
1050
|
+
* content is repeated per item. Content that is not a `${item => …}` arrow is repeated as
|
|
1051
|
+
* it is. Null when the element has no `each`.
|
|
1052
|
+
*/
|
|
1031
1053
|
lowerEach(el) {
|
|
1032
1054
|
const eachDir = el.attributes.find((a) => a.kind === "EachDirective");
|
|
1033
|
-
if (!eachDir || eachDir.kind !== "EachDirective") return
|
|
1055
|
+
if (!eachDir || eachDir.kind !== "EachDirective") return null;
|
|
1034
1056
|
const each = this.hole(eachDir.hole);
|
|
1035
1057
|
const props = [{ name: "each", kind: "attr", expr: each.code, reactive: each.reactive, ...each.at ? { at: each.at } : {} }];
|
|
1036
1058
|
if (eachDir.key) {
|
|
@@ -1040,12 +1062,12 @@ var Lowerer = class {
|
|
|
1040
1062
|
const arrow = this.itemArrow(el);
|
|
1041
1063
|
let childrenCode;
|
|
1042
1064
|
if (arrow) {
|
|
1043
|
-
const
|
|
1044
|
-
|
|
1045
|
-
childrenCode = `(${arrow.params.join(", ")}) => ${paren(this.emit(repeated), "arrowBody")}`;
|
|
1065
|
+
const body = arrow.bodyReactive ? `() => ${paren(arrow.body, "arrowBody")}` : paren(arrow.body, "arrowBody");
|
|
1066
|
+
childrenCode = `(${arrow.params.join(", ")}) => ${body}`;
|
|
1046
1067
|
} else {
|
|
1047
|
-
const
|
|
1048
|
-
|
|
1068
|
+
const content = this.lowerChildren(el.children);
|
|
1069
|
+
const ir = content.length === 1 ? content[0] : { kind: "fragment", children: content };
|
|
1070
|
+
childrenCode = `() => ${paren(this.emit(ir), "arrowBody")}`;
|
|
1049
1071
|
}
|
|
1050
1072
|
const children = [{ kind: "expr", code: childrenCode, reactive: false }];
|
|
1051
1073
|
const at = this.tagAt(el);
|
|
@@ -1062,25 +1084,6 @@ var Lowerer = class {
|
|
|
1062
1084
|
const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
|
|
1063
1085
|
return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
|
|
1064
1086
|
}
|
|
1065
|
-
/** Same element (minus each/key) but with explicit IR children. */
|
|
1066
|
-
rebuildWithChildren(el, children) {
|
|
1067
|
-
const props = this.lowerAttributes(
|
|
1068
|
-
el.attributes.filter((a) => a.kind !== "EachDirective")
|
|
1069
|
-
);
|
|
1070
|
-
if (el.kind === "Element") {
|
|
1071
|
-
const at = this.tagAt(el);
|
|
1072
|
-
return {
|
|
1073
|
-
kind: "element",
|
|
1074
|
-
tag: el.tag,
|
|
1075
|
-
svg: el.namespace === "svg",
|
|
1076
|
-
props,
|
|
1077
|
-
children,
|
|
1078
|
-
static: false,
|
|
1079
|
-
...at ? { at } : {}
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
return { kind: "component", name: el.tag, props, children };
|
|
1083
|
-
}
|
|
1084
1087
|
// --- attributes ---------------------------------------------------------
|
|
1085
1088
|
lowerAttributes(attrs) {
|
|
1086
1089
|
const props = [];
|