@fluixi/compiler 1.0.0-alpha.83 → 1.0.0-alpha.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyze/expr-shape.cjs +62 -1
- package/dist/analyze/expr-shape.d.cts +14 -0
- package/dist/analyze/expr-shape.d.ts +2 -2
- package/dist/analyze/expr-shape.js +1 -1
- package/dist/analyze/expr-shape.mjs +41 -1
- package/dist/analyze/intrinsics.cjs +80 -1
- package/dist/analyze/intrinsics.d.cts +66 -0
- package/dist/analyze/intrinsics.d.ts +7 -7
- package/dist/analyze/intrinsics.d.ts.map +1 -1
- package/dist/analyze/intrinsics.js +3 -3
- package/dist/analyze/intrinsics.mjs +59 -1
- package/dist/analyze/paren.cjs +134 -0
- package/dist/analyze/paren.d.cts +23 -0
- package/dist/analyze/paren.d.ts +24 -0
- package/dist/analyze/paren.d.ts.map +1 -0
- package/dist/analyze/paren.js +168 -0
- package/dist/analyze/paren.mjs +113 -0
- package/dist/analyze/props-destructure.cjs +226 -1
- package/dist/analyze/props-destructure.d.cts +83 -0
- package/dist/analyze/props-destructure.d.ts +3 -3
- package/dist/analyze/props-destructure.d.ts.map +1 -1
- package/dist/analyze/props-destructure.js +4 -4
- package/dist/analyze/props-destructure.mjs +205 -1
- package/dist/analyze/reactive-bindings.cjs +190 -1
- package/dist/analyze/reactive-bindings.d.cts +42 -0
- package/dist/analyze/reactive-bindings.d.ts +1 -1
- package/dist/analyze/reactive-bindings.js +2 -2
- package/dist/analyze/reactive-bindings.mjs +167 -1
- package/dist/analyze/reactive-expr.cjs +38 -1
- package/dist/analyze/reactive-expr.d.cts +38 -0
- package/dist/analyze/reactive-expr.d.ts +4 -4
- package/dist/analyze/reactive-expr.d.ts.map +1 -1
- package/dist/analyze/reactive-expr.js +2 -2
- package/dist/analyze/reactive-expr.mjs +17 -1
- package/dist/analyze/static-graph.cjs +811 -1
- package/dist/analyze/static-graph.d.cts +102 -0
- package/dist/analyze/static-graph.d.ts +1 -1
- package/dist/analyze/static-graph.d.ts.map +1 -1
- package/dist/analyze/static-graph.js +11 -11
- package/dist/analyze/static-graph.mjs +793 -1
- package/dist/babel-TGY76XJ7.mjs +636 -0
- package/dist/chunk-4PLHS2FP.mjs +158 -0
- package/dist/chunk-6DB5FXS4.mjs +1718 -0
- package/dist/chunk-F74GFKSL.mjs +16 -0
- package/dist/chunk-G6QC2WRJ.mjs +11 -0
- package/dist/chunk-RUDJDZAA.mjs +1078 -0
- package/dist/codegen/backend.cjs +18 -1
- package/dist/codegen/backend.d.cts +35 -0
- package/dist/codegen/backends/imperative.cjs +542 -1
- package/dist/codegen/backends/imperative.d.cts +11 -0
- package/dist/codegen/backends/imperative.d.ts +1 -1
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +24 -20
- package/dist/codegen/backends/imperative.mjs +519 -1
- package/dist/codegen/contract.cjs +52 -1
- package/dist/codegen/contract.d.cts +24 -0
- package/dist/codegen/contract.d.ts +2 -2
- package/dist/codegen/contract.js +2 -2
- package/dist/codegen/contract.mjs +31 -1
- package/dist/codegen/partial-template.cjs +176 -1
- package/dist/codegen/partial-template.d.cts +61 -0
- package/dist/codegen/partial-template.d.ts +4 -4
- package/dist/codegen/partial-template.js +0 -0
- package/dist/codegen/partial-template.mjs +153 -1
- package/dist/codegen/serialize-static.cjs +125 -1
- package/dist/codegen/serialize-static.d.cts +38 -0
- package/dist/codegen/serialize-static.d.ts +3 -3
- package/dist/codegen/serialize-static.js +6 -6
- package/dist/codegen/serialize-static.mjs +104 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
- package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
- package/dist/frontend/babel/build-ir-lit.d.ts +2 -2
- package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
- package/dist/frontend/babel/build-ir.cjs +1524 -1
- package/dist/frontend/babel/build-ir.d.cts +35 -0
- package/dist/frontend/babel/build-ir.d.ts +2 -2
- package/dist/frontend/babel/build-ir.js +2 -2
- package/dist/frontend/babel/build-ir.mjs +1495 -1
- package/dist/frontend/babel/index.cjs +2186 -1
- package/dist/frontend/babel/index.d.cts +33 -0
- package/dist/frontend/babel/index.d.ts +1 -1
- package/dist/frontend/babel/index.js +1 -1
- package/dist/frontend/babel/index.mjs +2156 -1
- package/dist/frontend/babel/lower-template.cjs +1507 -1
- package/dist/frontend/babel/lower-template.d.cts +23 -0
- package/dist/frontend/babel/lower-template.d.ts +1 -1
- package/dist/frontend/babel/lower-template.js +2 -2
- package/dist/frontend/babel/lower-template.mjs +1478 -1
- package/dist/frontend/babel/plugin.cjs +2132 -1
- package/dist/frontend/babel/plugin.d.cts +95 -0
- package/dist/frontend/babel/plugin.d.ts +5 -5
- package/dist/frontend/babel/plugin.d.ts.map +1 -1
- package/dist/frontend/babel/plugin.js +14 -14
- package/dist/frontend/babel/plugin.mjs +2103 -1
- package/dist/frontend/babel/server-functions.cjs +110 -1
- package/dist/frontend/babel/server-functions.d.cts +10 -0
- package/dist/frontend/babel/server-functions.mjs +89 -1
- package/dist/frontend/babel/types.cjs +18 -1
- package/dist/frontend/babel/types.d.cts +33 -0
- package/dist/frontend/types.cjs +18 -1
- package/dist/frontend/types.d.cts +25 -0
- package/dist/frontend/vocabulary.cjs +98 -0
- package/dist/frontend/vocabulary.d.cts +79 -0
- package/dist/frontend/vocabulary.d.ts +80 -0
- package/dist/frontend/vocabulary.d.ts.map +1 -0
- package/dist/frontend/vocabulary.js +124 -0
- package/dist/frontend/vocabulary.mjs +77 -0
- package/dist/index.cjs +1595 -14
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +1575 -14
- package/dist/integrations.cjs +4312 -26
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.d.ts +9 -9
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +29 -8
- package/dist/integrations.mjs +536 -18
- package/dist/ir/nodes.cjs +18 -1
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/ir/nodes.d.ts +6 -6
- package/dist/lower/compile-template.cjs +1356 -1
- package/dist/lower/compile-template.d.cts +69 -0
- package/dist/lower/compile-template.d.ts +3 -3
- package/dist/lower/compile-template.js +1 -1
- package/dist/lower/compile-template.mjs +1336 -1
- package/dist/lower/jsx.cjs +529 -1
- package/dist/lower/jsx.d.cts +25 -0
- package/dist/lower/jsx.d.ts +1 -1
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +6 -5
- package/dist/lower/jsx.mjs +506 -1
- package/dist/lower/template.cjs +1061 -1
- package/dist/lower/template.d.cts +53 -0
- package/dist/lower/template.d.ts +3 -3
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +12 -11
- package/dist/lower/template.mjs +1042 -1
- package/dist/lower/text.cjs +42 -1
- package/dist/lower/text.d.cts +10 -0
- package/dist/lower/text.d.ts +2 -2
- package/dist/lower/text.d.ts.map +1 -1
- package/dist/lower/text.js +2 -2
- package/dist/lower/text.mjs +21 -1
- package/dist/optimize/analyze-static.cjs +112 -1
- package/dist/optimize/analyze-static.d.cts +39 -0
- package/dist/optimize/analyze-static.d.ts +2 -2
- package/dist/optimize/analyze-static.js +2 -2
- package/dist/optimize/analyze-static.mjs +91 -1
- package/dist/optimize/collapse-strategies.cjs +90 -1
- package/dist/optimize/collapse-strategies.d.cts +30 -0
- package/dist/optimize/collapse-strategies.d.ts +3 -3
- package/dist/optimize/collapse-strategies.mjs +67 -1
- package/dist/options.cjs +33 -1
- package/dist/options.d.cts +39 -0
- package/dist/options.d.ts +2 -2
- package/dist/options.mjs +12 -1
- package/dist/resolve/builtins.cjs +73 -1
- package/dist/resolve/builtins.d.cts +68 -0
- package/dist/resolve/builtins.d.ts +8 -8
- package/dist/resolve/builtins.d.ts.map +1 -1
- package/dist/resolve/builtins.js +4 -4
- package/dist/resolve/builtins.mjs +53 -1
- package/dist/resolve/component-globals.cjs +234 -14
- package/dist/resolve/component-globals.d.cts +80 -0
- package/dist/resolve/component-globals.d.ts +5 -5
- package/dist/resolve/component-globals.js +10 -10
- package/dist/resolve/component-globals.mjs +211 -14
- package/dist/resolve/component-resolver.cjs +80 -1
- package/dist/resolve/component-resolver.d.cts +68 -0
- package/dist/resolve/component-resolver.d.ts +3 -3
- package/dist/resolve/component-resolver.d.ts.map +1 -1
- package/dist/resolve/component-resolver.js +3 -3
- package/dist/resolve/component-resolver.mjs +59 -1
- package/dist/resolve/load-directive.cjs +93 -1
- package/dist/resolve/load-directive.d.cts +53 -0
- package/dist/resolve/load-directive.d.ts +5 -5
- package/dist/resolve/load-directive.js +6 -6
- package/dist/resolve/load-directive.mjs +72 -1
- package/dist/resolve/resolve-ir.cjs +108 -1
- package/dist/resolve/resolve-ir.d.cts +53 -0
- package/dist/resolve/resolve-ir.d.ts +6 -6
- package/dist/resolve/resolve-ir.d.ts.map +1 -1
- package/dist/resolve/resolve-ir.js +1 -1
- package/dist/resolve/resolve-ir.mjs +85 -1
- package/dist/resolve/write-globals.cjs +319 -14
- package/dist/resolve/write-globals.d.cts +30 -0
- package/dist/resolve/write-globals.js +2 -2
- package/dist/resolve/write-globals.mjs +298 -14
- package/dist/server-fns-ZYWQTSZU.mjs +78 -0
- package/dist/server-functions-PCERFA7A.mjs +82 -0
- package/dist/transform/bindings.cjs +71 -1
- package/dist/transform/bindings.d.cts +16 -0
- package/dist/transform/bindings.d.ts +1 -1
- package/dist/transform/bindings.js +1 -1
- package/dist/transform/bindings.mjs +50 -1
- package/dist/transform/index.cjs +2732 -8
- package/dist/transform/index.d.cts +15 -0
- package/dist/transform/index.mjs +3773 -17
- package/dist/transform/intrinsics.cjs +216 -3
- package/dist/transform/intrinsics.d.cts +21 -0
- package/dist/transform/intrinsics.js +1 -1
- package/dist/transform/intrinsics.mjs +193 -3
- package/dist/transform/props.cjs +441 -3
- package/dist/transform/props.d.cts +45 -0
- package/dist/transform/props.d.ts +1 -1
- package/dist/transform/props.d.ts.map +1 -1
- package/dist/transform/props.js +4 -4
- package/dist/transform/props.mjs +1482 -12
- package/dist/transform/server-fn-id.cjs +35 -1
- package/dist/transform/server-fn-id.d.cts +9 -0
- package/dist/transform/server-fn-id.d.ts +1 -1
- package/dist/transform/server-fn-id.js +2 -2
- package/dist/transform/server-fn-id.mjs +14 -1
- package/dist/transform/server-fns.cjs +114 -2
- package/dist/transform/server-fns.d.cts +12 -0
- package/dist/transform/server-fns.js +3 -3
- package/dist/transform/server-fns.mjs +1155 -11
- package/dist/transform/source-locations.cjs +330 -1
- package/dist/transform/source-locations.d.cts +43 -0
- package/dist/transform/source-locations.d.ts +1 -1
- package/dist/transform/source-locations.js +5 -5
- package/dist/transform/source-locations.mjs +307 -1
- package/dist/transform/templates.cjs +2701 -7
- package/dist/transform/templates.d.cts +69 -0
- package/dist/transform/templates.d.ts +2 -2
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +7 -7
- package/dist/transform/templates.mjs +3743 -16
- package/dist/transform-RWDTQUF5.mjs +893 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/dist/babel-VXKH6MRQ.mjs +0 -1
- package/dist/chunk-3SAEGOMQ.mjs +0 -1
- package/dist/chunk-5KMMN5QP.mjs +0 -1
- package/dist/chunk-IBRM4W7I.mjs +0 -10
- package/dist/chunk-OHHZCYIQ.mjs +0 -1
- package/dist/chunk-YKZ54NVE.mjs +0 -1
- package/dist/server-fns-6QM243HC.mjs +0 -2
- package/dist/server-functions-E3LKCZ4R.mjs +0 -1
- package/dist/transform-C4ZXRVGP.mjs +0 -8
|
@@ -1 +1,330 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/transform/source-locations.ts
|
|
21
|
+
var source_locations_exports = {};
|
|
22
|
+
__export(source_locations_exports, {
|
|
23
|
+
COMPONENT_MARKER: () => COMPONENT_MARKER,
|
|
24
|
+
HOLE_MARKER: () => HOLE_MARKER,
|
|
25
|
+
PROPS_MARKER: () => PROPS_MARKER,
|
|
26
|
+
SOURCE_MARKER: () => SOURCE_MARKER,
|
|
27
|
+
collectSourceEdits: () => collectSourceEdits,
|
|
28
|
+
markHole: () => markHole,
|
|
29
|
+
markProps: () => markProps,
|
|
30
|
+
mayHaveReactiveCall: () => mayHaveReactiveCall
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(source_locations_exports);
|
|
33
|
+
|
|
34
|
+
// src/analyze/intrinsics.ts
|
|
35
|
+
var REACTIVE_MODULE = "@fluixi/reactive/signal";
|
|
36
|
+
var INTRINSICS = {
|
|
37
|
+
$signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
|
|
38
|
+
$memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
|
|
39
|
+
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
40
|
+
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
41
|
+
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
42
|
+
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
43
|
+
// name. Still worth having: no import to write, and when a shorter form is
|
|
44
|
+
// designed, the change is this line rather than a compiler pass.
|
|
45
|
+
$selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
46
|
+
$deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
47
|
+
// Not value constructors, but the compiler has to know them: they change what a read
|
|
48
|
+
// does. `untrack` suppresses dependency collection, which is exactly the kind of thing
|
|
49
|
+
// dependency analysis must not guess at.
|
|
50
|
+
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
51
|
+
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" }
|
|
52
|
+
};
|
|
53
|
+
var RUNTIME_PRIMITIVES = {
|
|
54
|
+
signal: "signal-handle",
|
|
55
|
+
memo: "memo-handle",
|
|
56
|
+
effect: "effect",
|
|
57
|
+
store: "store-handle",
|
|
58
|
+
createSignal: ["signal-accessor", "signal-setter"],
|
|
59
|
+
createMemo: "memo-accessor",
|
|
60
|
+
createEffect: "effect",
|
|
61
|
+
createRenderEffect: "effect",
|
|
62
|
+
createStore: "reactive-object",
|
|
63
|
+
resource: "resource-handle",
|
|
64
|
+
createResource: "reactive-object",
|
|
65
|
+
createSelector: "memo-accessor",
|
|
66
|
+
createDeferred: "memo-accessor"
|
|
67
|
+
};
|
|
68
|
+
var PRIMITIVE_MODULES = [
|
|
69
|
+
"@fluixi/reactive",
|
|
70
|
+
"@fluixi/reactive/signal",
|
|
71
|
+
"@fluixi/reactive/store",
|
|
72
|
+
"@fluixi/core"
|
|
73
|
+
];
|
|
74
|
+
var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
|
|
75
|
+
function isIntrinsicName(name) {
|
|
76
|
+
return Object.prototype.hasOwnProperty.call(INTRINSICS, name);
|
|
77
|
+
}
|
|
78
|
+
function isPrimitiveModule(source) {
|
|
79
|
+
return PRIMITIVE_MODULES.includes(source);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/analyze/reactive-bindings.ts
|
|
83
|
+
function patternNames(node, out) {
|
|
84
|
+
if (!node) return;
|
|
85
|
+
switch (node.type) {
|
|
86
|
+
case "Identifier":
|
|
87
|
+
out.add(node.name);
|
|
88
|
+
return;
|
|
89
|
+
case "ObjectPattern":
|
|
90
|
+
for (const p of node.properties ?? []) {
|
|
91
|
+
if (p.type === "RestElement") patternNames(p.argument, out);
|
|
92
|
+
else patternNames(p.value, out);
|
|
93
|
+
}
|
|
94
|
+
return;
|
|
95
|
+
case "ArrayPattern":
|
|
96
|
+
for (const e of node.elements ?? []) patternNames(e, out);
|
|
97
|
+
return;
|
|
98
|
+
case "AssignmentPattern":
|
|
99
|
+
patternNames(node.left, out);
|
|
100
|
+
return;
|
|
101
|
+
case "RestElement":
|
|
102
|
+
patternNames(node.argument, out);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function walk(root, visit) {
|
|
107
|
+
if (!root || typeof root !== "object" || typeof root.type !== "string") return;
|
|
108
|
+
visit(root);
|
|
109
|
+
for (const key of Object.keys(root)) {
|
|
110
|
+
if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
|
|
111
|
+
const value = root[key];
|
|
112
|
+
if (Array.isArray(value)) for (const item of value) walk(item, visit);
|
|
113
|
+
else if (value && typeof value === "object") walk(value, visit);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function calledPrimitive(node, bindings) {
|
|
117
|
+
if (node.type !== "CallExpression") return void 0;
|
|
118
|
+
const callee = node.callee;
|
|
119
|
+
if (callee?.type !== "Identifier") return void 0;
|
|
120
|
+
const name = callee.name;
|
|
121
|
+
const imported = bindings.primitives.get(name);
|
|
122
|
+
if (imported) return imported;
|
|
123
|
+
const intrinsic = INTRINSICS[name];
|
|
124
|
+
if (intrinsic && !bindings.shadowed.has(name)) return intrinsic.returns;
|
|
125
|
+
return void 0;
|
|
126
|
+
}
|
|
127
|
+
function classify(id, returns, kinds) {
|
|
128
|
+
if (Array.isArray(returns)) {
|
|
129
|
+
if (id.type === "ArrayPattern") {
|
|
130
|
+
id.elements.forEach((element, index) => {
|
|
131
|
+
const kind = returns[index];
|
|
132
|
+
if (element?.type === "Identifier" && kind) kinds.set(element.name, kind);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (id.type === "Identifier") kinds.set(id.name, returns);
|
|
138
|
+
}
|
|
139
|
+
function resolveReactiveBindings(program) {
|
|
140
|
+
const bindings = { kinds: /* @__PURE__ */ new Map(), primitives: /* @__PURE__ */ new Map(), shadowed: /* @__PURE__ */ new Set() };
|
|
141
|
+
const root = program;
|
|
142
|
+
walk(root, (node) => {
|
|
143
|
+
const names = /* @__PURE__ */ new Set();
|
|
144
|
+
if (node.type === "VariableDeclarator") patternNames(node.id, names);
|
|
145
|
+
else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") patternNames(node.id, names);
|
|
146
|
+
else if (node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") patternNames(node.local, names);
|
|
147
|
+
else if (node.type === "ImportSpecifier") patternNames(node.local, names);
|
|
148
|
+
else if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration") {
|
|
149
|
+
for (const p of node.params ?? []) patternNames(p, names);
|
|
150
|
+
}
|
|
151
|
+
for (const name of names) if (INTRINSICS[name]) bindings.shadowed.add(name);
|
|
152
|
+
});
|
|
153
|
+
for (const statement of root.body ?? []) {
|
|
154
|
+
if (statement.type !== "ImportDeclaration") continue;
|
|
155
|
+
if (!isPrimitiveModule(statement.source?.value)) continue;
|
|
156
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
157
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
158
|
+
const importedNode = specifier.imported;
|
|
159
|
+
const imported = importedNode.type === "Identifier" ? importedNode.name : importedNode.value;
|
|
160
|
+
const returns = RUNTIME_PRIMITIVES[imported];
|
|
161
|
+
if (returns) bindings.primitives.set(specifier.local.name, returns);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
walk(root, (node) => {
|
|
165
|
+
if (node.type !== "VariableDeclarator" || !node.init) return;
|
|
166
|
+
const returns = calledPrimitive(node.init, bindings);
|
|
167
|
+
if (returns) classify(node.id, returns, bindings.kinds);
|
|
168
|
+
});
|
|
169
|
+
return bindings;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/transform/source-locations.ts
|
|
173
|
+
var SOURCE_MARKER = "__fx_source";
|
|
174
|
+
var COMPONENT_MARKER = "__fx_component";
|
|
175
|
+
var HOLE_MARKER = "__fx_hole";
|
|
176
|
+
var markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MARKER} ?? ((f) => f))(${accessor},${line},${column}${name === void 0 ? "" : `,${JSON.stringify(name)}`})`;
|
|
177
|
+
var PROPS_MARKER = "__fx_props";
|
|
178
|
+
var markProps = (object, at) => `(globalThis.${PROPS_MARKER} ?? ((p) => p))(${object},${JSON.stringify(at)})`;
|
|
179
|
+
var RUNTIME_PRIMITIVES2 = /* @__PURE__ */ new Set([
|
|
180
|
+
"signal",
|
|
181
|
+
"memo",
|
|
182
|
+
"effect",
|
|
183
|
+
"store",
|
|
184
|
+
"resource",
|
|
185
|
+
"watch",
|
|
186
|
+
"createSignal",
|
|
187
|
+
"createMemo",
|
|
188
|
+
"createEffect",
|
|
189
|
+
"createStore",
|
|
190
|
+
"createResource"
|
|
191
|
+
]);
|
|
192
|
+
function mayHaveReactiveCall(code) {
|
|
193
|
+
for (const name of RUNTIME_PRIMITIVES2) {
|
|
194
|
+
if (code.includes(name)) return true;
|
|
195
|
+
}
|
|
196
|
+
return code.includes("$signal") || code.includes("$memo") || code.includes("$effect") || code.includes("$store");
|
|
197
|
+
}
|
|
198
|
+
var SINGLE_STATEMENT_PARENTS = /* @__PURE__ */ new Set([
|
|
199
|
+
"IfStatement",
|
|
200
|
+
"ForStatement",
|
|
201
|
+
"ForInStatement",
|
|
202
|
+
"ForOfStatement",
|
|
203
|
+
"WhileStatement",
|
|
204
|
+
"DoWhileStatement",
|
|
205
|
+
"LabeledStatement",
|
|
206
|
+
"WithStatement"
|
|
207
|
+
]);
|
|
208
|
+
function isLoneBranch(statement, parent) {
|
|
209
|
+
if (!parent || statement.type === "BlockStatement") return false;
|
|
210
|
+
return SINGLE_STATEMENT_PARENTS.has(parent.type);
|
|
211
|
+
}
|
|
212
|
+
function isExport(node) {
|
|
213
|
+
return node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration";
|
|
214
|
+
}
|
|
215
|
+
function isStatement(node) {
|
|
216
|
+
return node.type.endsWith("Statement") || node.type === "VariableDeclaration";
|
|
217
|
+
}
|
|
218
|
+
function walk2(node, visit, stack = []) {
|
|
219
|
+
if (!node || typeof node.type !== "string") return;
|
|
220
|
+
visit(node, stack);
|
|
221
|
+
stack.push(node);
|
|
222
|
+
for (const key of Object.keys(node)) {
|
|
223
|
+
if (key === "loc" || key === "parent") continue;
|
|
224
|
+
const value = node[key];
|
|
225
|
+
if (Array.isArray(value)) {
|
|
226
|
+
for (const child of value) walk2(child, visit, stack);
|
|
227
|
+
} else if (value && typeof value.type === "string") {
|
|
228
|
+
walk2(value, visit, stack);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
stack.pop();
|
|
232
|
+
}
|
|
233
|
+
function nameFor(stack) {
|
|
234
|
+
const declarator = stack[stack.length - 1];
|
|
235
|
+
if (declarator?.type !== "VariableDeclarator") return void 0;
|
|
236
|
+
const id = declarator.id;
|
|
237
|
+
if (id?.type === "Identifier") return id.name;
|
|
238
|
+
if (id?.type === "ArrayPattern") {
|
|
239
|
+
const first = id.elements?.[0];
|
|
240
|
+
if (first?.type === "Identifier") return first.name;
|
|
241
|
+
}
|
|
242
|
+
return void 0;
|
|
243
|
+
}
|
|
244
|
+
function componentName(node) {
|
|
245
|
+
if (node.type === "FunctionDeclaration") {
|
|
246
|
+
const name = node.id?.name;
|
|
247
|
+
return name && name[0] === name[0]?.toUpperCase() ? name : void 0;
|
|
248
|
+
}
|
|
249
|
+
if (node.type === "VariableDeclarator") {
|
|
250
|
+
const id = node.id;
|
|
251
|
+
const init = node.init;
|
|
252
|
+
if (id?.type !== "Identifier" || !init) return void 0;
|
|
253
|
+
if (init.type !== "ArrowFunctionExpression" && init.type !== "FunctionExpression") return void 0;
|
|
254
|
+
const name = id.name;
|
|
255
|
+
return name[0] === name[0]?.toUpperCase() ? name : void 0;
|
|
256
|
+
}
|
|
257
|
+
return void 0;
|
|
258
|
+
}
|
|
259
|
+
function collectSourceEdits(program, filename) {
|
|
260
|
+
const edits = [];
|
|
261
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
262
|
+
const { primitives, shadowed } = resolveReactiveBindings(program);
|
|
263
|
+
walk2(program, (node, stack) => {
|
|
264
|
+
const component = componentName(node);
|
|
265
|
+
if (component) {
|
|
266
|
+
const at = node.loc?.start;
|
|
267
|
+
let end2 = node.end;
|
|
268
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
269
|
+
const up = stack[i];
|
|
270
|
+
if (up.type !== "VariableDeclaration" && up.type !== "ExportNamedDeclaration" && up.type !== "ExportDefaultDeclaration") {
|
|
271
|
+
break;
|
|
272
|
+
}
|
|
273
|
+
end2 = up.end;
|
|
274
|
+
}
|
|
275
|
+
if (at) {
|
|
276
|
+
edits.push({
|
|
277
|
+
start: end2,
|
|
278
|
+
end: end2,
|
|
279
|
+
code: `;globalThis.${COMPONENT_MARKER}?.(${JSON.stringify(component)},${JSON.stringify(filename)},${at.line},${at.column});`
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (node.type !== "CallExpression") return;
|
|
284
|
+
const callee = node.callee;
|
|
285
|
+
if (callee?.type !== "Identifier") return;
|
|
286
|
+
const name = callee.name;
|
|
287
|
+
const intrinsic = isIntrinsicName(name) && !shadowed.has(name) ? INTRINSICS[name] : void 0;
|
|
288
|
+
const imported = primitives.has(name) || RUNTIME_PRIMITIVES2.has(name);
|
|
289
|
+
if (!intrinsic && !imported) return;
|
|
290
|
+
const position = node.loc?.start;
|
|
291
|
+
if (!position) return;
|
|
292
|
+
let statement;
|
|
293
|
+
let parent;
|
|
294
|
+
let index = -1;
|
|
295
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
296
|
+
if (isStatement(stack[i]) || isExport(stack[i])) {
|
|
297
|
+
statement = stack[i];
|
|
298
|
+
parent = stack[i - 1];
|
|
299
|
+
index = i;
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (!statement) return;
|
|
304
|
+
let start = statement.start;
|
|
305
|
+
let end = statement.end;
|
|
306
|
+
for (let i = index - 1; i >= 0; i--) {
|
|
307
|
+
if (!isExport(stack[i])) break;
|
|
308
|
+
start = stack[i].start;
|
|
309
|
+
end = stack[i].end;
|
|
310
|
+
parent = stack[i - 1];
|
|
311
|
+
}
|
|
312
|
+
if (claimed.has(start)) return;
|
|
313
|
+
claimed.add(start);
|
|
314
|
+
const label = nameFor(stack);
|
|
315
|
+
const args = [
|
|
316
|
+
JSON.stringify(filename),
|
|
317
|
+
String(position.line),
|
|
318
|
+
String(position.column),
|
|
319
|
+
label ? JSON.stringify(label) : void 0
|
|
320
|
+
].filter((a) => a !== void 0).join(",");
|
|
321
|
+
const mark = `globalThis.${SOURCE_MARKER}?.(${args});`;
|
|
322
|
+
if (isLoneBranch(statement, parent)) {
|
|
323
|
+
edits.push({ start, end: start, code: `{${mark}` });
|
|
324
|
+
edits.push({ start: end, end, code: "}" });
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
edits.push({ start, end: start, code: mark });
|
|
328
|
+
});
|
|
329
|
+
return { edits, marked: edits.length };
|
|
330
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface SourceEdit {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
code: string;
|
|
5
|
+
}
|
|
6
|
+
export interface SourceLocationsResult {
|
|
7
|
+
edits: SourceEdit[];
|
|
8
|
+
/** How many creation sites were marked. */
|
|
9
|
+
marked: number;
|
|
10
|
+
}
|
|
11
|
+
/** Installed by @fluixi/devtools; undefined everywhere else. */
|
|
12
|
+
export declare const SOURCE_MARKER = "__fx_source";
|
|
13
|
+
/** Where a component was declared. Keyed by name, since that is all the runtime carries. */
|
|
14
|
+
export declare const COMPONENT_MARKER = "__fx_component";
|
|
15
|
+
/**
|
|
16
|
+
* Where one reactive hole was written. This one wraps: the position has to travel with the
|
|
17
|
+
* accessor to wherever the dom wires it up. A template is emitted as one overwrite, so the
|
|
18
|
+
* source map has a single entry for the root and every hole traces back to it.
|
|
19
|
+
*
|
|
20
|
+
* `?? (f => f)` and not `?.()`: the value is the accessor, and returning undefined would
|
|
21
|
+
* delete the binding.
|
|
22
|
+
*/
|
|
23
|
+
export declare const HOLE_MARKER = "__fx_hole";
|
|
24
|
+
/**
|
|
25
|
+
* `_(() => x(), 9, 25)`, or the accessor untouched when nothing is watching.
|
|
26
|
+
*
|
|
27
|
+
* `name` is the source text the value came from, for a `ref` where knowing which variable
|
|
28
|
+
* holds the element is the whole question.
|
|
29
|
+
*/
|
|
30
|
+
export declare const markHole: (accessor: string, line: number, column: number, name?: string) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Where each prop of a component tag was written.
|
|
33
|
+
*
|
|
34
|
+
* The props object is built as getters, so nothing in it can carry a position of its own.
|
|
35
|
+
* The marker takes the object and a name-to-position map, and hands the object straight
|
|
36
|
+
* back: devtools keeps the map, and a build without it passes the object through.
|
|
37
|
+
*/
|
|
38
|
+
export declare const PROPS_MARKER = "__fx_props";
|
|
39
|
+
/** `_({ get a() {…} }, {"a":[9,25]})`, or the object untouched when nothing is watching. */
|
|
40
|
+
export declare const markProps: (object: string, at: Record<string, [number, number]>) => string;
|
|
41
|
+
/** Cheap enough to run before parsing. */
|
|
42
|
+
export declare function mayHaveReactiveCall(code: string): boolean;
|
|
43
|
+
export declare function collectSourceEdits(program: unknown, filename: string): SourceLocationsResult;
|
|
@@ -33,7 +33,7 @@ export declare const markHole: (accessor: string, line: number, column: number,
|
|
|
33
33
|
*
|
|
34
34
|
* The props object is built as getters, so nothing in it can carry a position of its own.
|
|
35
35
|
* The marker takes the object and a name-to-position map, and hands the object straight
|
|
36
|
-
* back
|
|
36
|
+
* back: devtools keeps the map, and a build without it passes the object through.
|
|
37
37
|
*/
|
|
38
38
|
export declare const PROPS_MARKER = "__fx_props";
|
|
39
39
|
/** `_({ get a() {…} }, {"a":[9,25]})`, or the object untouched when nothing is watching. */
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* → globalThis.__fx_source?.("src/App.ts",1,14,"count"); const count = signal(0);
|
|
6
6
|
*
|
|
7
7
|
* A statement in front of the one that creates the node, not a wrapper round the call: the
|
|
8
|
-
* call may already be being rewritten
|
|
8
|
+
* call may already be being rewritten: `$signal` becomes `signal`, and two passes editing
|
|
9
9
|
* one span is a splice over a splice.
|
|
10
10
|
*
|
|
11
11
|
* A global rather than an import, so the author's modules do not each take a dependency on
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* Positions come from the original source, before any pass moves anything.
|
|
15
15
|
*
|
|
16
|
-
* Development only, and one mark per statement
|
|
16
|
+
* Development only, and one mark per statement: the runtime keeps a single slot, so
|
|
17
17
|
* marking two calls in one statement would hand the first node the second's location.
|
|
18
18
|
*/
|
|
19
19
|
import { INTRINSICS, isIntrinsicName } from '../analyze/intrinsics.js';
|
|
@@ -43,7 +43,7 @@ export const markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MA
|
|
|
43
43
|
*
|
|
44
44
|
* The props object is built as getters, so nothing in it can carry a position of its own.
|
|
45
45
|
* The marker takes the object and a name-to-position map, and hands the object straight
|
|
46
|
-
* back
|
|
46
|
+
* back: devtools keeps the map, and a build without it passes the object through.
|
|
47
47
|
*/
|
|
48
48
|
export const PROPS_MARKER = '__fx_props';
|
|
49
49
|
/** `_({ get a() {…} }, {"a":[9,25]})`, or the object untouched when nothing is watching. */
|
|
@@ -149,7 +149,7 @@ export function collectSourceEdits(program, filename) {
|
|
|
149
149
|
// template pass overwrites.
|
|
150
150
|
//
|
|
151
151
|
// Only through what wraps a declaration. Anything else above it is a block or an
|
|
152
|
-
// argument list, and a statement appended there lands outside the grammar
|
|
152
|
+
// argument list, and a statement appended there lands outside the grammar ,
|
|
153
153
|
// `function Page(){}` inside `it('…', () => { … })` ended up between the `}` and the
|
|
154
154
|
// `)`, which is a syntax error in a file that compiled a moment earlier.
|
|
155
155
|
let end = node.end;
|
|
@@ -201,7 +201,7 @@ export function collectSourceEdits(program, filename) {
|
|
|
201
201
|
if (!statement)
|
|
202
202
|
return;
|
|
203
203
|
// `export const [cart] = createStore(…)` finds the declaration, which starts after the
|
|
204
|
-
// keyword
|
|
204
|
+
// keyword: a mark there splits `export` from what it exports.
|
|
205
205
|
let start = statement.start;
|
|
206
206
|
let end = statement.end;
|
|
207
207
|
for (let i = index - 1; i >= 0; i--) {
|