@fluixi/compiler 1.0.0-alpha.100 → 1.0.0-alpha.102
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/README.md +13 -13
- package/dist/analyze/props-destructure.d.cts +1 -1
- package/dist/analyze/props-destructure.d.ts +1 -1
- package/dist/analyze/props-destructure.js +1 -1
- package/dist/analyze/reactive-bindings.d.cts +1 -1
- package/dist/analyze/reactive-bindings.d.ts +1 -1
- package/dist/analyze/reactive-bindings.js +3 -3
- package/dist/analyze/static-graph.cjs +1 -1
- package/dist/analyze/static-graph.js +2 -2
- package/dist/analyze/static-graph.mjs +1 -1
- package/dist/{babel-I6BUWUCU.mjs → babel-WBQWG5BI.mjs} +23 -23
- package/dist/{chunk-C3XPDB4Y.mjs → chunk-AOKTQGX3.mjs} +1 -1
- package/dist/{chunk-HXEXPWJ2.mjs → chunk-EEUWXI5C.mjs} +2 -2
- package/dist/{chunk-3AICWNF7.mjs → chunk-HUWJHS6T.mjs} +1 -1
- package/dist/{chunk-NU3W67UZ.mjs → chunk-KGXFUVHJ.mjs} +2 -2
- package/dist/{chunk-GX5XV6Z7.mjs → chunk-MASWFMPJ.mjs} +1 -1
- package/dist/{chunk-SKAVY75W.mjs → chunk-TFGOAGRI.mjs} +1 -1
- package/dist/{chunk-6CWJWGE2.mjs → chunk-WUV5ZIYZ.mjs} +10 -10
- package/dist/codegen/backends/imperative.js +2 -2
- package/dist/frontend/babel/{build-ir-lit.cjs → build-ir-html.cjs} +19 -19
- package/dist/frontend/babel/{build-ir-lit.d.cts → build-ir-html.d.cts} +5 -5
- package/dist/frontend/babel/{build-ir-lit.d.ts → build-ir-html.d.ts} +6 -6
- package/dist/frontend/babel/build-ir-html.d.ts.map +1 -0
- package/dist/frontend/babel/{build-ir-lit.js → build-ir-html.js} +4 -4
- package/dist/frontend/babel/{build-ir-lit.mjs → build-ir-html.mjs} +15 -15
- package/dist/frontend/babel/build-ir.cjs +14 -14
- package/dist/frontend/babel/build-ir.d.cts +1 -1
- package/dist/frontend/babel/build-ir.d.ts +1 -1
- package/dist/frontend/babel/build-ir.js +5 -5
- package/dist/frontend/babel/build-ir.mjs +14 -14
- package/dist/frontend/babel/index.cjs +28 -28
- package/dist/frontend/babel/index.d.cts +0 -11
- package/dist/frontend/babel/index.d.ts +0 -11
- package/dist/frontend/babel/index.d.ts.map +1 -1
- package/dist/frontend/babel/index.js +2 -14
- package/dist/frontend/babel/index.mjs +28 -28
- package/dist/frontend/babel/lower-template.cjs +15 -15
- package/dist/frontend/babel/lower-template.d.cts +3 -3
- package/dist/frontend/babel/lower-template.d.ts +3 -3
- package/dist/frontend/babel/lower-template.d.ts.map +1 -1
- package/dist/frontend/babel/lower-template.js +4 -4
- package/dist/frontend/babel/lower-template.mjs +15 -15
- package/dist/frontend/babel/plugin.cjs +25 -25
- package/dist/frontend/babel/plugin.d.cts +6 -22
- package/dist/frontend/babel/plugin.d.ts +6 -22
- package/dist/frontend/babel/plugin.d.ts.map +1 -1
- package/dist/frontend/babel/plugin.js +19 -42
- package/dist/frontend/babel/plugin.mjs +25 -25
- package/dist/frontend/babel/server-functions.js +2 -2
- package/dist/index.cjs +9 -9
- package/dist/index.mjs +9 -9
- package/dist/integrations.cjs +42 -42
- package/dist/integrations.d.cts +7 -22
- package/dist/integrations.d.ts +7 -22
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +3 -34
- package/dist/integrations.mjs +13 -13
- package/dist/ir/nodes.d.cts +1 -1
- package/dist/ir/nodes.d.ts +1 -1
- package/dist/lower/compile-template.cjs +9 -9
- package/dist/lower/compile-template.d.cts +2 -2
- package/dist/lower/compile-template.d.ts +2 -2
- package/dist/lower/compile-template.d.ts.map +1 -1
- package/dist/lower/compile-template.js +1 -1
- package/dist/lower/compile-template.mjs +9 -9
- package/dist/lower/jsx.js +2 -2
- package/dist/lower/template.cjs +8 -8
- package/dist/lower/template.d.cts +6 -6
- package/dist/lower/template.d.ts +6 -6
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +14 -14
- package/dist/lower/template.mjs +8 -8
- package/dist/resolve/builtins.cjs +1 -1
- package/dist/resolve/builtins.d.cts +2 -2
- package/dist/resolve/builtins.d.ts +2 -2
- package/dist/resolve/builtins.js +1 -1
- package/dist/resolve/builtins.mjs +1 -1
- package/dist/resolve/component-globals.d.cts +2 -2
- package/dist/resolve/component-globals.d.ts +2 -2
- package/dist/resolve/component-globals.js +1 -1
- package/dist/resolve/load-directive.d.cts +1 -1
- package/dist/resolve/load-directive.d.ts +1 -1
- package/dist/resolve/load-directive.js +1 -1
- package/dist/resolve/resolve-ir.d.cts +1 -1
- package/dist/resolve/resolve-ir.d.ts +1 -1
- package/dist/{server-fns-VZLHMQTC.mjs → server-fns-I6FKYS22.mjs} +5 -5
- package/dist/{server-functions-UAZKOLZW.mjs → server-functions-MATGYTBX.mjs} +3 -3
- package/dist/transform/bindings.d.cts +1 -1
- package/dist/transform/bindings.d.ts +1 -1
- package/dist/transform/bindings.js +1 -1
- package/dist/transform/index.cjs +17 -17
- package/dist/transform/index.mjs +17 -17
- package/dist/transform/intrinsics.d.cts +1 -1
- package/dist/transform/intrinsics.d.ts +1 -1
- package/dist/transform/intrinsics.js +1 -1
- package/dist/transform/source-locations.d.cts +1 -1
- package/dist/transform/source-locations.d.ts +1 -1
- package/dist/transform/source-locations.d.ts.map +1 -1
- package/dist/transform/source-locations.js +6 -6
- package/dist/transform/styles.d.cts +2 -2
- package/dist/transform/styles.d.ts +2 -2
- package/dist/transform/styles.d.ts.map +1 -1
- package/dist/transform/styles.js +5 -5
- package/dist/transform/templates.cjs +16 -16
- package/dist/transform/templates.d.cts +2 -2
- package/dist/transform/templates.d.ts +2 -2
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +10 -10
- package/dist/transform/templates.mjs +16 -16
- package/dist/{transform-3W45L3EA.mjs → transform-AP5PSRT7.mjs} +15 -15
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/dist/vite-styles.js +2 -2
- package/package.json +4 -4
- package/dist/frontend/babel/build-ir-lit.d.ts.map +0 -1
|
@@ -1,22 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @fileoverview Babel front-end adapter for the Fluixi compiler.
|
|
3
|
-
* @module @fluixi/compiler/babel
|
|
4
|
-
*
|
|
5
|
-
* This is one of the compiler's front-end adapters: it parses with @babel and
|
|
6
|
-
* runs the JSX transform. The transform/codegen it currently performs is the
|
|
7
|
-
* existing behaviour (emits the jsx() automatic runtime), switching codegen to
|
|
8
|
-
* the IR-driven backends (see ../../codegen) is a later step. SWC/other
|
|
9
|
-
* front-ends will plug in alongside this without touching the rest of the pipeline.
|
|
10
|
-
*/
|
|
11
1
|
// Export the main plugin
|
|
12
2
|
export { default } from './plugin.js';
|
|
13
|
-
// Export types
|
|
14
3
|
export * from './types.js';
|
|
15
4
|
// Re-export for convenience
|
|
16
5
|
import plugin from './plugin.js';
|
|
17
6
|
/** Named export for explicit usage */
|
|
18
7
|
export const babelPluginReactiveJSX = plugin;
|
|
19
|
-
/** Helper to create plugin with options */
|
|
20
8
|
export function createPlugin(options) {
|
|
21
9
|
return [plugin, options];
|
|
22
10
|
}
|
|
@@ -31,7 +19,7 @@ export function createPreset(options = {}) {
|
|
|
31
19
|
importSource: '@fluixi/jsx',
|
|
32
20
|
development: process.env.NODE_ENV === 'development',
|
|
33
21
|
detectReactivity: true,
|
|
34
|
-
|
|
22
|
+
useHtmlTag: true,
|
|
35
23
|
hoistStatics: true,
|
|
36
24
|
delegateEvents: true,
|
|
37
25
|
optimizeControlFlow: true,
|
|
@@ -57,7 +45,7 @@ export const presets = {
|
|
|
57
45
|
}),
|
|
58
46
|
minimal: createPreset({
|
|
59
47
|
detectReactivity: false,
|
|
60
|
-
|
|
48
|
+
useHtmlTag: false,
|
|
61
49
|
hoistStatics: false,
|
|
62
50
|
delegateEvents: false,
|
|
63
51
|
optimizeControlFlow: false,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @fluixi/compiler v1.0.0-alpha.
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.102 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
2
|
|
|
3
3
|
// src/frontend/babel/plugin.ts
|
|
4
4
|
import { declare } from "@babel/helper-plugin-utils";
|
|
@@ -1120,7 +1120,7 @@ var Lowerer = class {
|
|
|
1120
1120
|
for (const s of imports) this.used.add(s);
|
|
1121
1121
|
return inlineTemplates(code, templates);
|
|
1122
1122
|
}
|
|
1123
|
-
//
|
|
1123
|
+
// content
|
|
1124
1124
|
lowerRoot(children) {
|
|
1125
1125
|
const nodes = this.lowerChildren(children);
|
|
1126
1126
|
if (nodes.length === 1) return nodes[0];
|
|
@@ -1249,8 +1249,8 @@ var Lowerer = class {
|
|
|
1249
1249
|
}
|
|
1250
1250
|
return { slots, rest };
|
|
1251
1251
|
}
|
|
1252
|
-
//
|
|
1253
|
-
/** `<el if=${cond}
|
|
1252
|
+
// control-flow sugar
|
|
1253
|
+
/** `<el if=${cond}>...</el>` (+ optional `<el else>`) → `<Show when fallback>`. */
|
|
1254
1254
|
lowerIf(el, condHole, elseEl) {
|
|
1255
1255
|
const cond = this.hole(condHole);
|
|
1256
1256
|
const props = [
|
|
@@ -1265,8 +1265,8 @@ var Lowerer = class {
|
|
|
1265
1265
|
return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
|
|
1266
1266
|
}
|
|
1267
1267
|
/**
|
|
1268
|
-
* `<el each=${items} key?>${item =>
|
|
1269
|
-
* content is repeated per item. Content that is not a `${item =>
|
|
1268
|
+
* `<el each=${items} key?>${item => ...}</el>` → `<el><For each>{item => ...}</For></el>`: the
|
|
1269
|
+
* content is repeated per item. Content that is not a `${item => ...}` arrow is repeated as
|
|
1270
1270
|
* it is. Null when the element has no `each`.
|
|
1271
1271
|
*/
|
|
1272
1272
|
lowerEach(el) {
|
|
@@ -1303,7 +1303,7 @@ var Lowerer = class {
|
|
|
1303
1303
|
const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
|
|
1304
1304
|
return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
|
|
1305
1305
|
}
|
|
1306
|
-
//
|
|
1306
|
+
// attributes
|
|
1307
1307
|
/**
|
|
1308
1308
|
* `element`: a DOM element, where each class:/style: value that moves is its own accessor.
|
|
1309
1309
|
* A component gets the object as before, rebuilt whole when any value moves.
|
|
@@ -1444,7 +1444,7 @@ var Lowerer = class {
|
|
|
1444
1444
|
if (mods.includes("passive")) opts.push("passive: true");
|
|
1445
1445
|
return opts.length ? `{ ${opts.join(", ")} }` : null;
|
|
1446
1446
|
}
|
|
1447
|
-
/** `bind:value=${sig}` → `value={read()}` + `onInput={e => write(e
|
|
1447
|
+
/** `bind:value=${sig}` → `value={read()}` + `onInput={e => write(e...value)}`. */
|
|
1448
1448
|
bindProps(prop, h) {
|
|
1449
1449
|
const sigCode = h.code;
|
|
1450
1450
|
const checked = prop === "checked";
|
|
@@ -1470,7 +1470,7 @@ var Lowerer = class {
|
|
|
1470
1470
|
}
|
|
1471
1471
|
];
|
|
1472
1472
|
}
|
|
1473
|
-
/** A plain attribute (incl.
|
|
1473
|
+
/** A plain attribute (incl. html `?bool`, mixed values), old `mkProp` behavior. */
|
|
1474
1474
|
plainAttr(a) {
|
|
1475
1475
|
const v = a.value;
|
|
1476
1476
|
let name = a.name;
|
|
@@ -1537,7 +1537,7 @@ function bindHole(expr, used, onNested) {
|
|
|
1537
1537
|
if (t.isObjectExpression(expr)) hole.object = true;
|
|
1538
1538
|
return hole;
|
|
1539
1539
|
}
|
|
1540
|
-
function
|
|
1540
|
+
function lowerHtmlTemplate(node, used, opts = {}) {
|
|
1541
1541
|
const quasi = node.quasi;
|
|
1542
1542
|
const holes = quasi.expressions.map((e) => bindHole(e, used, opts.onNested));
|
|
1543
1543
|
return lowerTemplate(buildPieces(quasi), holes, used, opts);
|
|
@@ -1630,9 +1630,9 @@ function childReason(node) {
|
|
|
1630
1630
|
return "expression-child";
|
|
1631
1631
|
}
|
|
1632
1632
|
|
|
1633
|
-
// src/frontend/babel/build-ir-
|
|
1634
|
-
function
|
|
1635
|
-
const ir =
|
|
1633
|
+
// src/frontend/babel/build-ir-html.ts
|
|
1634
|
+
function buildIRFromHtml(node, used = /* @__PURE__ */ new Set(), opts = {}) {
|
|
1635
|
+
const ir = lowerHtmlTemplate(node, used, opts);
|
|
1636
1636
|
analyzeStatic(ir);
|
|
1637
1637
|
return ir;
|
|
1638
1638
|
}
|
|
@@ -2041,12 +2041,12 @@ function transformNestedJSX(node, used, onNested) {
|
|
|
2041
2041
|
const { code, imports, templates } = imperativeBackend.emit(nestedIR, {});
|
|
2042
2042
|
emitInto(path, inlineTemplates(code, templates), imports);
|
|
2043
2043
|
},
|
|
2044
|
-
// Nested
|
|
2044
|
+
// Nested html templates compose: ${cond ? html`...` : html`...`},
|
|
2045
2045
|
// ${list.map(x => html`<li>${x}</li>`)}. Compile them the same way.
|
|
2046
2046
|
TaggedTemplateExpression(path) {
|
|
2047
2047
|
const tag = path.node.tag;
|
|
2048
2048
|
if (!t2.isIdentifier(tag) || tag.name !== "html" && tag.name !== "svg") return;
|
|
2049
|
-
const ir =
|
|
2049
|
+
const ir = buildIRFromHtml(path.node, used, { svg: tag.name === "svg", onNested });
|
|
2050
2050
|
onNested?.(ir);
|
|
2051
2051
|
const { code, imports, templates } = imperativeBackend.emit(ir, {});
|
|
2052
2052
|
emitInto(path, inlineTemplates(code, templates), imports);
|
|
@@ -2089,11 +2089,11 @@ var plugin_default = declare((api, options = {}) => {
|
|
|
2089
2089
|
// `fluixi()` needs no `format` option. Injected imports are deduped, so a
|
|
2090
2090
|
// file mixing the two styles won't redeclare a binding.
|
|
2091
2091
|
format = "both",
|
|
2092
|
-
|
|
2092
|
+
htmlTag = "html",
|
|
2093
2093
|
resolve: resolveRules = []
|
|
2094
2094
|
} = options;
|
|
2095
2095
|
const componentResolver = createComponentResolver(resolveRules);
|
|
2096
|
-
const
|
|
2096
|
+
const compileHtml = format === "html" || format === "both";
|
|
2097
2097
|
const pluginState = {
|
|
2098
2098
|
irImports: /* @__PURE__ */ new Set(),
|
|
2099
2099
|
libModule: "@fluixi/core",
|
|
@@ -2102,7 +2102,7 @@ var plugin_default = declare((api, options = {}) => {
|
|
|
2102
2102
|
templateClone,
|
|
2103
2103
|
partialTemplates,
|
|
2104
2104
|
hasJSX: false,
|
|
2105
|
-
|
|
2105
|
+
hasHtmlTag: false,
|
|
2106
2106
|
needsControlFlowImport: false,
|
|
2107
2107
|
needsCreateMemo: false,
|
|
2108
2108
|
controlFlowComponents: /* @__PURE__ */ new Set(),
|
|
@@ -2126,8 +2126,8 @@ var plugin_default = declare((api, options = {}) => {
|
|
|
2126
2126
|
enter(path, state) {
|
|
2127
2127
|
Object.assign(state, {
|
|
2128
2128
|
hasJSX: false,
|
|
2129
|
-
|
|
2130
|
-
|
|
2129
|
+
hasHtmlTag: false,
|
|
2130
|
+
hasHtmlIR: false,
|
|
2131
2131
|
needsControlFlowImport: false,
|
|
2132
2132
|
needsCreateMemo: false,
|
|
2133
2133
|
controlFlowComponents: /* @__PURE__ */ new Set(),
|
|
@@ -2152,7 +2152,7 @@ var plugin_default = declare((api, options = {}) => {
|
|
|
2152
2152
|
},
|
|
2153
2153
|
exit(path, state) {
|
|
2154
2154
|
const imports = [];
|
|
2155
|
-
if (state.hasJSX || state.
|
|
2155
|
+
if (state.hasJSX || state.hasHtmlIR) {
|
|
2156
2156
|
if (state.irImports.size > 0) {
|
|
2157
2157
|
const CF = /* @__PURE__ */ new Set([
|
|
2158
2158
|
"Show",
|
|
@@ -2342,8 +2342,8 @@ var plugin_default = declare((api, options = {}) => {
|
|
|
2342
2342
|
path.replaceWith(emitViaIR(path.node, state));
|
|
2343
2343
|
},
|
|
2344
2344
|
TaggedTemplateExpression(path, state) {
|
|
2345
|
-
if (
|
|
2346
|
-
path.replaceWith(
|
|
2345
|
+
if (compileHtml && t3.isIdentifier(path.node.tag) && (path.node.tag.name === htmlTag || path.node.tag.name === "svg")) {
|
|
2346
|
+
path.replaceWith(emitHtmlViaIR(path.node, state));
|
|
2347
2347
|
}
|
|
2348
2348
|
}
|
|
2349
2349
|
}
|
|
@@ -2446,10 +2446,10 @@ function dedupeImports(imports) {
|
|
|
2446
2446
|
}
|
|
2447
2447
|
return out;
|
|
2448
2448
|
}
|
|
2449
|
-
function
|
|
2449
|
+
function emitHtmlViaIR(node, state) {
|
|
2450
2450
|
const used = /* @__PURE__ */ new Set();
|
|
2451
2451
|
const svg = t3.isIdentifier(node.tag) && node.tag.name === "svg";
|
|
2452
|
-
const ir =
|
|
2452
|
+
const ir = buildIRFromHtml(node, used, { svg, onNested: nestedHook(state) });
|
|
2453
2453
|
resolveComponentSources(ir, {
|
|
2454
2454
|
resolver: state.componentResolver,
|
|
2455
2455
|
modules: {
|
|
@@ -2464,7 +2464,7 @@ function emitLitViaIR(node, state) {
|
|
|
2464
2464
|
for (const s of imports) used.add(s);
|
|
2465
2465
|
for (const s of used) state.irImports.add(s);
|
|
2466
2466
|
collectRuntimeNeeds(ir, state);
|
|
2467
|
-
state.
|
|
2467
|
+
state.hasHtmlIR = true;
|
|
2468
2468
|
const expression = template2.expression(adoptTemplates(code, templates, state), {
|
|
2469
2469
|
placeholderPattern: false,
|
|
2470
2470
|
plugins: ["typescript"]
|
|
@@ -2540,7 +2540,7 @@ function createPreset(options = {}) {
|
|
|
2540
2540
|
importSource: "@fluixi/jsx",
|
|
2541
2541
|
development: false,
|
|
2542
2542
|
detectReactivity: true,
|
|
2543
|
-
|
|
2543
|
+
useHtmlTag: true,
|
|
2544
2544
|
hoistStatics: true,
|
|
2545
2545
|
delegateEvents: true,
|
|
2546
2546
|
optimizeControlFlow: true,
|
|
@@ -2565,7 +2565,7 @@ var presets = {
|
|
|
2565
2565
|
}),
|
|
2566
2566
|
minimal: createPreset({
|
|
2567
2567
|
detectReactivity: false,
|
|
2568
|
-
|
|
2568
|
+
useHtmlTag: false,
|
|
2569
2569
|
hoistStatics: false,
|
|
2570
2570
|
delegateEvents: false,
|
|
2571
2571
|
optimizeControlFlow: false
|
|
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/frontend/babel/lower-template.ts
|
|
31
31
|
var lower_template_exports = {};
|
|
32
32
|
__export(lower_template_exports, {
|
|
33
|
-
|
|
33
|
+
lowerHtmlTemplate: () => lowerHtmlTemplate
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(lower_template_exports);
|
|
36
36
|
var import_core2 = require("@babel/core");
|
|
@@ -974,7 +974,7 @@ var Lowerer = class {
|
|
|
974
974
|
for (const s of imports) this.used.add(s);
|
|
975
975
|
return inlineTemplates(code, templates);
|
|
976
976
|
}
|
|
977
|
-
//
|
|
977
|
+
// content
|
|
978
978
|
lowerRoot(children) {
|
|
979
979
|
const nodes = this.lowerChildren(children);
|
|
980
980
|
if (nodes.length === 1) return nodes[0];
|
|
@@ -1103,8 +1103,8 @@ var Lowerer = class {
|
|
|
1103
1103
|
}
|
|
1104
1104
|
return { slots, rest };
|
|
1105
1105
|
}
|
|
1106
|
-
//
|
|
1107
|
-
/** `<el if=${cond}
|
|
1106
|
+
// control-flow sugar
|
|
1107
|
+
/** `<el if=${cond}>...</el>` (+ optional `<el else>`) → `<Show when fallback>`. */
|
|
1108
1108
|
lowerIf(el, condHole, elseEl) {
|
|
1109
1109
|
const cond = this.hole(condHole);
|
|
1110
1110
|
const props = [
|
|
@@ -1119,8 +1119,8 @@ var Lowerer = class {
|
|
|
1119
1119
|
return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
|
|
1120
1120
|
}
|
|
1121
1121
|
/**
|
|
1122
|
-
* `<el each=${items} key?>${item =>
|
|
1123
|
-
* content is repeated per item. Content that is not a `${item =>
|
|
1122
|
+
* `<el each=${items} key?>${item => ...}</el>` → `<el><For each>{item => ...}</For></el>`: the
|
|
1123
|
+
* content is repeated per item. Content that is not a `${item => ...}` arrow is repeated as
|
|
1124
1124
|
* it is. Null when the element has no `each`.
|
|
1125
1125
|
*/
|
|
1126
1126
|
lowerEach(el) {
|
|
@@ -1157,7 +1157,7 @@ var Lowerer = class {
|
|
|
1157
1157
|
const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
|
|
1158
1158
|
return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
|
|
1159
1159
|
}
|
|
1160
|
-
//
|
|
1160
|
+
// attributes
|
|
1161
1161
|
/**
|
|
1162
1162
|
* `element`: a DOM element, where each class:/style: value that moves is its own accessor.
|
|
1163
1163
|
* A component gets the object as before, rebuilt whole when any value moves.
|
|
@@ -1298,7 +1298,7 @@ var Lowerer = class {
|
|
|
1298
1298
|
if (mods.includes("passive")) opts.push("passive: true");
|
|
1299
1299
|
return opts.length ? `{ ${opts.join(", ")} }` : null;
|
|
1300
1300
|
}
|
|
1301
|
-
/** `bind:value=${sig}` → `value={read()}` + `onInput={e => write(e
|
|
1301
|
+
/** `bind:value=${sig}` → `value={read()}` + `onInput={e => write(e...value)}`. */
|
|
1302
1302
|
bindProps(prop, h) {
|
|
1303
1303
|
const sigCode = h.code;
|
|
1304
1304
|
const checked = prop === "checked";
|
|
@@ -1324,7 +1324,7 @@ var Lowerer = class {
|
|
|
1324
1324
|
}
|
|
1325
1325
|
];
|
|
1326
1326
|
}
|
|
1327
|
-
/** A plain attribute (incl.
|
|
1327
|
+
/** A plain attribute (incl. html `?bool`, mixed values), old `mkProp` behavior. */
|
|
1328
1328
|
plainAttr(a) {
|
|
1329
1329
|
const v = a.value;
|
|
1330
1330
|
let name = a.name;
|
|
@@ -1449,9 +1449,9 @@ function childReason(node) {
|
|
|
1449
1449
|
return "expression-child";
|
|
1450
1450
|
}
|
|
1451
1451
|
|
|
1452
|
-
// src/frontend/babel/build-ir-
|
|
1453
|
-
function
|
|
1454
|
-
const ir =
|
|
1452
|
+
// src/frontend/babel/build-ir-html.ts
|
|
1453
|
+
function buildIRFromHtml(node, used = /* @__PURE__ */ new Set(), opts = {}) {
|
|
1454
|
+
const ir = lowerHtmlTemplate(node, used, opts);
|
|
1455
1455
|
analyzeStatic(ir);
|
|
1456
1456
|
return ir;
|
|
1457
1457
|
}
|
|
@@ -1860,12 +1860,12 @@ function transformNestedJSX(node, used, onNested) {
|
|
|
1860
1860
|
const { code, imports, templates } = imperativeBackend.emit(nestedIR, {});
|
|
1861
1861
|
emitInto(path, inlineTemplates(code, templates), imports);
|
|
1862
1862
|
},
|
|
1863
|
-
// Nested
|
|
1863
|
+
// Nested html templates compose: ${cond ? html`...` : html`...`},
|
|
1864
1864
|
// ${list.map(x => html`<li>${x}</li>`)}. Compile them the same way.
|
|
1865
1865
|
TaggedTemplateExpression(path) {
|
|
1866
1866
|
const tag = path.node.tag;
|
|
1867
1867
|
if (!import_core.types.isIdentifier(tag) || tag.name !== "html" && tag.name !== "svg") return;
|
|
1868
|
-
const ir =
|
|
1868
|
+
const ir = buildIRFromHtml(path.node, used, { svg: tag.name === "svg", onNested });
|
|
1869
1869
|
onNested?.(ir);
|
|
1870
1870
|
const { code, imports, templates } = imperativeBackend.emit(ir, {});
|
|
1871
1871
|
emitInto(path, inlineTemplates(code, templates), imports);
|
|
@@ -1912,7 +1912,7 @@ function bindHole(expr, used, onNested) {
|
|
|
1912
1912
|
if (import_core2.types.isObjectExpression(expr)) hole.object = true;
|
|
1913
1913
|
return hole;
|
|
1914
1914
|
}
|
|
1915
|
-
function
|
|
1915
|
+
function lowerHtmlTemplate(node, used, opts = {}) {
|
|
1916
1916
|
const quasi = node.quasi;
|
|
1917
1917
|
const holes = quasi.expressions.map((e) => bindHole(e, used, opts.onNested));
|
|
1918
1918
|
return lowerTemplate(buildPieces(quasi), holes, used, opts);
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The lowering itself is in ../../lower/template.ts and takes no Babel. What is
|
|
5
5
|
* left here is the part that genuinely needs to read JavaScript: turning each
|
|
6
|
-
* `${
|
|
6
|
+
* `${...}` into a `TemplateHole`: its source text, whether it is reactive, and
|
|
7
7
|
* the two structural facts the lowering branches on (a single-expression arrow,
|
|
8
8
|
* an object literal).
|
|
9
9
|
*
|
|
@@ -14,10 +14,10 @@ import { types as t } from '@babel/core';
|
|
|
14
14
|
import type { IRNode } from '../../ir/nodes.cjs';
|
|
15
15
|
import { type NestedHook } from './build-ir.cjs';
|
|
16
16
|
/**
|
|
17
|
-
* Build IR from
|
|
17
|
+
* Build IR from an `` html`...` `` / `` svg`...` `` TaggedTemplateExpression.
|
|
18
18
|
* `used` collects runtime symbols emitted for anything nested inside a hole.
|
|
19
19
|
*/
|
|
20
|
-
export declare function
|
|
20
|
+
export declare function lowerHtmlTemplate(node: t.TaggedTemplateExpression, used: Set<string>, opts?: {
|
|
21
21
|
svg?: boolean;
|
|
22
22
|
onNested?: NestedHook;
|
|
23
23
|
}): IRNode;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The lowering itself is in ../../lower/template.ts and takes no Babel. What is
|
|
5
5
|
* left here is the part that genuinely needs to read JavaScript: turning each
|
|
6
|
-
* `${
|
|
6
|
+
* `${...}` into a `TemplateHole`: its source text, whether it is reactive, and
|
|
7
7
|
* the two structural facts the lowering branches on (a single-expression arrow,
|
|
8
8
|
* an object literal).
|
|
9
9
|
*
|
|
@@ -14,10 +14,10 @@ import { types as t } from '@babel/core';
|
|
|
14
14
|
import type { IRNode } from '../../ir/nodes.js';
|
|
15
15
|
import { type NestedHook } from './build-ir.js';
|
|
16
16
|
/**
|
|
17
|
-
* Build IR from
|
|
17
|
+
* Build IR from an `` html`...` `` / `` svg`...` `` TaggedTemplateExpression.
|
|
18
18
|
* `used` collects runtime symbols emitted for anything nested inside a hole.
|
|
19
19
|
*/
|
|
20
|
-
export declare function
|
|
20
|
+
export declare function lowerHtmlTemplate(node: t.TaggedTemplateExpression, used: Set<string>, opts?: {
|
|
21
21
|
svg?: boolean;
|
|
22
22
|
onNested?: NestedHook;
|
|
23
23
|
}): IRNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lower-template.d.ts","sourceRoot":"","sources":["../../../src/frontend/babel/lower-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAgCzE;;;GAGG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"lower-template.d.ts","sourceRoot":"","sources":["../../../src/frontend/babel/lower-template.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,KAAK,IAAI,CAAC,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAgCzE;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,CAAC,CAAC,wBAAwB,EAChC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,EACjB,IAAI,GAAE;IAAE,GAAG,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,UAAU,CAAA;CAAO,GAClD,MAAM,CAIR"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The lowering itself is in ../../lower/template.ts and takes no Babel. What is
|
|
5
5
|
* left here is the part that genuinely needs to read JavaScript: turning each
|
|
6
|
-
* `${
|
|
6
|
+
* `${...}` into a `TemplateHole`: its source text, whether it is reactive, and
|
|
7
7
|
* the two structural facts the lowering branches on (a single-expression arrow,
|
|
8
8
|
* an object literal).
|
|
9
9
|
*
|
|
@@ -18,7 +18,7 @@ const generate = _generate.default ?? _generate;
|
|
|
18
18
|
function gen(node) {
|
|
19
19
|
return generate(node, { concise: true }).code;
|
|
20
20
|
}
|
|
21
|
-
/** Describe one `${
|
|
21
|
+
/** Describe one `${...}` for the lowering. */
|
|
22
22
|
function bindHole(expr, used, onNested) {
|
|
23
23
|
const hole = {
|
|
24
24
|
code: genExpr(expr, used, onNested),
|
|
@@ -41,10 +41,10 @@ function bindHole(expr, used, onNested) {
|
|
|
41
41
|
return hole;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* Build IR from
|
|
44
|
+
* Build IR from an `` html`...` `` / `` svg`...` `` TaggedTemplateExpression.
|
|
45
45
|
* `used` collects runtime symbols emitted for anything nested inside a hole.
|
|
46
46
|
*/
|
|
47
|
-
export function
|
|
47
|
+
export function lowerHtmlTemplate(node, used, opts = {}) {
|
|
48
48
|
const quasi = node.quasi;
|
|
49
49
|
const holes = quasi.expressions.map((e) => bindHole(e, used, opts.onNested));
|
|
50
50
|
return lowerTemplate(buildPieces(quasi), holes, used, opts);
|
|
@@ -942,7 +942,7 @@ var Lowerer = class {
|
|
|
942
942
|
for (const s of imports) this.used.add(s);
|
|
943
943
|
return inlineTemplates(code, templates);
|
|
944
944
|
}
|
|
945
|
-
//
|
|
945
|
+
// content
|
|
946
946
|
lowerRoot(children) {
|
|
947
947
|
const nodes = this.lowerChildren(children);
|
|
948
948
|
if (nodes.length === 1) return nodes[0];
|
|
@@ -1071,8 +1071,8 @@ var Lowerer = class {
|
|
|
1071
1071
|
}
|
|
1072
1072
|
return { slots, rest };
|
|
1073
1073
|
}
|
|
1074
|
-
//
|
|
1075
|
-
/** `<el if=${cond}
|
|
1074
|
+
// control-flow sugar
|
|
1075
|
+
/** `<el if=${cond}>...</el>` (+ optional `<el else>`) → `<Show when fallback>`. */
|
|
1076
1076
|
lowerIf(el, condHole, elseEl) {
|
|
1077
1077
|
const cond = this.hole(condHole);
|
|
1078
1078
|
const props = [
|
|
@@ -1087,8 +1087,8 @@ var Lowerer = class {
|
|
|
1087
1087
|
return { kind: "component", name: "Show", props, children: [child], ...at ? { at } : {}, ...cond.at ? { bindAt: cond.at } : {} };
|
|
1088
1088
|
}
|
|
1089
1089
|
/**
|
|
1090
|
-
* `<el each=${items} key?>${item =>
|
|
1091
|
-
* content is repeated per item. Content that is not a `${item =>
|
|
1090
|
+
* `<el each=${items} key?>${item => ...}</el>` → `<el><For each>{item => ...}</For></el>`: the
|
|
1091
|
+
* content is repeated per item. Content that is not a `${item => ...}` arrow is repeated as
|
|
1092
1092
|
* it is. Null when the element has no `each`.
|
|
1093
1093
|
*/
|
|
1094
1094
|
lowerEach(el) {
|
|
@@ -1125,7 +1125,7 @@ var Lowerer = class {
|
|
|
1125
1125
|
const clone = { ...el, attributes: el.attributes.filter((a) => !drop(a)) };
|
|
1126
1126
|
return clone.kind === "Element" ? this.lowerElement(clone) : this.lowerComponent(clone);
|
|
1127
1127
|
}
|
|
1128
|
-
//
|
|
1128
|
+
// attributes
|
|
1129
1129
|
/**
|
|
1130
1130
|
* `element`: a DOM element, where each class:/style: value that moves is its own accessor.
|
|
1131
1131
|
* A component gets the object as before, rebuilt whole when any value moves.
|
|
@@ -1266,7 +1266,7 @@ var Lowerer = class {
|
|
|
1266
1266
|
if (mods.includes("passive")) opts.push("passive: true");
|
|
1267
1267
|
return opts.length ? `{ ${opts.join(", ")} }` : null;
|
|
1268
1268
|
}
|
|
1269
|
-
/** `bind:value=${sig}` → `value={read()}` + `onInput={e => write(e
|
|
1269
|
+
/** `bind:value=${sig}` → `value={read()}` + `onInput={e => write(e...value)}`. */
|
|
1270
1270
|
bindProps(prop, h) {
|
|
1271
1271
|
const sigCode = h.code;
|
|
1272
1272
|
const checked = prop === "checked";
|
|
@@ -1292,7 +1292,7 @@ var Lowerer = class {
|
|
|
1292
1292
|
}
|
|
1293
1293
|
];
|
|
1294
1294
|
}
|
|
1295
|
-
/** A plain attribute (incl.
|
|
1295
|
+
/** A plain attribute (incl. html `?bool`, mixed values), old `mkProp` behavior. */
|
|
1296
1296
|
plainAttr(a) {
|
|
1297
1297
|
const v = a.value;
|
|
1298
1298
|
let name = a.name;
|
|
@@ -1417,9 +1417,9 @@ function childReason(node) {
|
|
|
1417
1417
|
return "expression-child";
|
|
1418
1418
|
}
|
|
1419
1419
|
|
|
1420
|
-
// src/frontend/babel/build-ir-
|
|
1421
|
-
function
|
|
1422
|
-
const ir =
|
|
1420
|
+
// src/frontend/babel/build-ir-html.ts
|
|
1421
|
+
function buildIRFromHtml(node, used = /* @__PURE__ */ new Set(), opts = {}) {
|
|
1422
|
+
const ir = lowerHtmlTemplate(node, used, opts);
|
|
1423
1423
|
analyzeStatic(ir);
|
|
1424
1424
|
return ir;
|
|
1425
1425
|
}
|
|
@@ -1828,12 +1828,12 @@ function transformNestedJSX(node, used, onNested) {
|
|
|
1828
1828
|
const { code, imports, templates } = imperativeBackend.emit(nestedIR, {});
|
|
1829
1829
|
emitInto(path, inlineTemplates(code, templates), imports);
|
|
1830
1830
|
},
|
|
1831
|
-
// Nested
|
|
1831
|
+
// Nested html templates compose: ${cond ? html`...` : html`...`},
|
|
1832
1832
|
// ${list.map(x => html`<li>${x}</li>`)}. Compile them the same way.
|
|
1833
1833
|
TaggedTemplateExpression(path) {
|
|
1834
1834
|
const tag = path.node.tag;
|
|
1835
1835
|
if (!t.isIdentifier(tag) || tag.name !== "html" && tag.name !== "svg") return;
|
|
1836
|
-
const ir =
|
|
1836
|
+
const ir = buildIRFromHtml(path.node, used, { svg: tag.name === "svg", onNested });
|
|
1837
1837
|
onNested?.(ir);
|
|
1838
1838
|
const { code, imports, templates } = imperativeBackend.emit(ir, {});
|
|
1839
1839
|
emitInto(path, inlineTemplates(code, templates), imports);
|
|
@@ -1880,7 +1880,7 @@ function bindHole(expr, used, onNested) {
|
|
|
1880
1880
|
if (t2.isObjectExpression(expr)) hole.object = true;
|
|
1881
1881
|
return hole;
|
|
1882
1882
|
}
|
|
1883
|
-
function
|
|
1883
|
+
function lowerHtmlTemplate(node, used, opts = {}) {
|
|
1884
1884
|
const quasi = node.quasi;
|
|
1885
1885
|
const holes = quasi.expressions.map((e) => bindHole(e, used, opts.onNested));
|
|
1886
1886
|
return lowerTemplate(buildPieces(quasi), holes, used, opts);
|
|
@@ -1898,5 +1898,5 @@ function buildPieces(quasi) {
|
|
|
1898
1898
|
return pieces;
|
|
1899
1899
|
}
|
|
1900
1900
|
export {
|
|
1901
|
-
|
|
1901
|
+
lowerHtmlTemplate
|
|
1902
1902
|
};
|