@fluixi/compiler 1.0.0-alpha.82 → 1.0.0-alpha.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyze/expr-shape.cjs +62 -1
- package/dist/analyze/expr-shape.d.cts +14 -0
- package/dist/analyze/expr-shape.mjs +41 -1
- package/dist/analyze/intrinsics.cjs +80 -1
- package/dist/analyze/intrinsics.d.cts +66 -0
- package/dist/analyze/intrinsics.mjs +59 -1
- package/dist/analyze/paren.cjs +134 -0
- package/dist/analyze/paren.d.cts +23 -0
- package/dist/analyze/paren.d.ts +24 -0
- package/dist/analyze/paren.d.ts.map +1 -0
- package/dist/analyze/paren.js +168 -0
- package/dist/analyze/paren.mjs +113 -0
- package/dist/analyze/props-destructure.cjs +226 -1
- package/dist/analyze/props-destructure.d.cts +83 -0
- package/dist/analyze/props-destructure.mjs +205 -1
- package/dist/analyze/reactive-bindings.cjs +190 -1
- package/dist/analyze/reactive-bindings.d.cts +42 -0
- package/dist/analyze/reactive-bindings.mjs +167 -1
- package/dist/analyze/reactive-expr.cjs +38 -1
- package/dist/analyze/reactive-expr.d.cts +38 -0
- package/dist/analyze/reactive-expr.mjs +17 -1
- package/dist/analyze/static-graph.cjs +811 -0
- package/dist/analyze/static-graph.d.cts +102 -0
- package/dist/analyze/static-graph.d.ts +103 -0
- package/dist/analyze/static-graph.d.ts.map +1 -0
- package/dist/analyze/static-graph.js +869 -0
- package/dist/analyze/static-graph.mjs +793 -0
- package/dist/babel-NRW4EFTG.mjs +636 -0
- package/dist/chunk-3YKZ4GNH.mjs +11 -0
- package/dist/chunk-EZR7NZOY.mjs +1718 -0
- package/dist/chunk-FSSWUXUR.mjs +16 -0
- package/dist/chunk-MJV3UXIL.mjs +158 -0
- package/dist/chunk-R2VHAZAX.mjs +1078 -0
- package/dist/codegen/backend.cjs +18 -1
- package/dist/codegen/backend.d.cts +35 -0
- package/dist/codegen/backends/imperative.cjs +542 -1
- package/dist/codegen/backends/imperative.d.cts +11 -0
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +68 -13
- package/dist/codegen/backends/imperative.mjs +519 -1
- package/dist/codegen/contract.cjs +52 -1
- package/dist/codegen/contract.d.cts +24 -0
- package/dist/codegen/contract.mjs +31 -1
- package/dist/codegen/partial-template.cjs +176 -1
- package/dist/codegen/partial-template.d.cts +61 -0
- package/dist/codegen/partial-template.mjs +153 -1
- package/dist/codegen/serialize-static.cjs +125 -1
- package/dist/codegen/serialize-static.d.cts +38 -0
- package/dist/codegen/serialize-static.d.ts +16 -0
- package/dist/codegen/serialize-static.d.ts.map +1 -1
- package/dist/codegen/serialize-static.js +25 -0
- package/dist/codegen/serialize-static.mjs +104 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
- package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
- package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
- package/dist/frontend/babel/build-ir.cjs +1524 -1
- package/dist/frontend/babel/build-ir.d.cts +35 -0
- package/dist/frontend/babel/build-ir.mjs +1495 -1
- package/dist/frontend/babel/index.cjs +2186 -1
- package/dist/frontend/babel/index.d.cts +33 -0
- package/dist/frontend/babel/index.mjs +2156 -1
- package/dist/frontend/babel/lower-template.cjs +1507 -1
- package/dist/frontend/babel/lower-template.d.cts +23 -0
- package/dist/frontend/babel/lower-template.mjs +1478 -1
- package/dist/frontend/babel/plugin.cjs +2132 -1
- package/dist/frontend/babel/plugin.d.cts +95 -0
- package/dist/frontend/babel/plugin.mjs +2103 -1
- package/dist/frontend/babel/server-functions.cjs +110 -1
- package/dist/frontend/babel/server-functions.d.cts +10 -0
- package/dist/frontend/babel/server-functions.mjs +89 -1
- package/dist/frontend/babel/types.cjs +18 -1
- package/dist/frontend/babel/types.d.cts +33 -0
- package/dist/frontend/types.cjs +18 -1
- package/dist/frontend/types.d.cts +25 -0
- package/dist/frontend/vocabulary.cjs +98 -0
- package/dist/frontend/vocabulary.d.cts +79 -0
- package/dist/frontend/vocabulary.d.ts +80 -0
- package/dist/frontend/vocabulary.d.ts.map +1 -0
- package/dist/frontend/vocabulary.js +124 -0
- package/dist/frontend/vocabulary.mjs +77 -0
- package/dist/index.cjs +1594 -13
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.mjs +1574 -13
- package/dist/integrations.cjs +4307 -25
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.d.ts +16 -0
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +21 -2
- package/dist/integrations.mjs +531 -17
- package/dist/ir/nodes.cjs +18 -1
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/ir/nodes.d.ts +46 -0
- package/dist/ir/nodes.d.ts.map +1 -1
- package/dist/lower/compile-template.cjs +1356 -1
- package/dist/lower/compile-template.d.cts +69 -0
- package/dist/lower/compile-template.d.ts +12 -0
- package/dist/lower/compile-template.d.ts.map +1 -1
- package/dist/lower/compile-template.js +5 -1
- package/dist/lower/compile-template.mjs +1336 -1
- package/dist/lower/jsx.cjs +529 -1
- package/dist/lower/jsx.d.cts +25 -0
- package/dist/lower/jsx.d.ts +2 -0
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +27 -4
- package/dist/lower/jsx.mjs +506 -1
- package/dist/lower/template.cjs +1061 -1
- package/dist/lower/template.d.cts +53 -0
- package/dist/lower/template.d.ts +14 -1
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +106 -19
- package/dist/lower/template.mjs +1042 -1
- package/dist/lower/text.cjs +42 -1
- package/dist/lower/text.d.cts +10 -0
- package/dist/lower/text.mjs +21 -1
- package/dist/optimize/analyze-static.cjs +112 -1
- package/dist/optimize/analyze-static.d.cts +39 -0
- package/dist/optimize/analyze-static.mjs +91 -1
- package/dist/optimize/collapse-strategies.cjs +90 -1
- package/dist/optimize/collapse-strategies.d.cts +30 -0
- package/dist/optimize/collapse-strategies.mjs +67 -1
- package/dist/options.cjs +33 -1
- package/dist/options.d.cts +39 -0
- package/dist/options.mjs +12 -1
- package/dist/resolve/builtins.cjs +73 -1
- package/dist/resolve/builtins.d.cts +68 -0
- package/dist/resolve/builtins.mjs +53 -1
- package/dist/resolve/component-globals.cjs +233 -13
- package/dist/resolve/component-globals.d.cts +80 -0
- package/dist/resolve/component-globals.mjs +210 -13
- package/dist/resolve/component-resolver.cjs +80 -1
- package/dist/resolve/component-resolver.d.cts +68 -0
- package/dist/resolve/component-resolver.mjs +59 -1
- package/dist/resolve/load-directive.cjs +93 -1
- package/dist/resolve/load-directive.d.cts +53 -0
- package/dist/resolve/load-directive.mjs +72 -1
- package/dist/resolve/resolve-ir.cjs +108 -1
- package/dist/resolve/resolve-ir.d.cts +53 -0
- package/dist/resolve/resolve-ir.mjs +85 -1
- package/dist/resolve/write-globals.cjs +318 -13
- package/dist/resolve/write-globals.d.cts +30 -0
- package/dist/resolve/write-globals.mjs +297 -13
- package/dist/server-fns-4ZXN6DYU.mjs +78 -0
- package/dist/server-functions-V6D6DRIA.mjs +82 -0
- package/dist/transform/bindings.cjs +71 -1
- package/dist/transform/bindings.d.cts +16 -0
- package/dist/transform/bindings.mjs +50 -1
- package/dist/transform/index.cjs +2732 -8
- package/dist/transform/index.d.cts +15 -0
- package/dist/transform/index.mjs +3773 -17
- package/dist/transform/intrinsics.cjs +216 -3
- package/dist/transform/intrinsics.d.cts +21 -0
- package/dist/transform/intrinsics.mjs +193 -3
- package/dist/transform/props.cjs +441 -3
- package/dist/transform/props.d.cts +45 -0
- package/dist/transform/props.mjs +1482 -12
- package/dist/transform/server-fn-id.cjs +35 -1
- package/dist/transform/server-fn-id.d.cts +9 -0
- package/dist/transform/server-fn-id.mjs +14 -1
- package/dist/transform/server-fns.cjs +114 -2
- package/dist/transform/server-fns.d.cts +12 -0
- package/dist/transform/server-fns.mjs +1155 -11
- package/dist/transform/source-locations.cjs +330 -0
- package/dist/transform/source-locations.d.cts +43 -0
- package/dist/transform/source-locations.d.ts +44 -0
- package/dist/transform/source-locations.d.ts.map +1 -0
- package/dist/transform/source-locations.js +238 -0
- package/dist/transform/source-locations.mjs +307 -0
- package/dist/transform/templates.cjs +2701 -7
- package/dist/transform/templates.d.cts +69 -0
- package/dist/transform/templates.d.ts +12 -4
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +72 -7
- package/dist/transform/templates.mjs +3743 -16
- package/dist/transform-BT4MMASR.mjs +893 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/dist/babel-4JUDAR2G.mjs +0 -1
- package/dist/chunk-3SAEGOMQ.mjs +0 -1
- package/dist/chunk-IBRM4W7I.mjs +0 -10
- package/dist/chunk-OHHZCYIQ.mjs +0 -1
- package/dist/chunk-PVR2SN3B.mjs +0 -1
- package/dist/chunk-QUIYULS2.mjs +0 -1
- package/dist/chunk-YR3SAEO7.mjs +0 -1
- package/dist/server-fns-6QM243HC.mjs +0 -2
- package/dist/server-functions-E3LKCZ4R.mjs +0 -1
- package/dist/transform-5WC4FWJE.mjs +0 -8
|
@@ -1,3 +1,216 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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/intrinsics.ts
|
|
21
|
+
var intrinsics_exports = {};
|
|
22
|
+
__export(intrinsics_exports, {
|
|
23
|
+
collectIntrinsicEdits: () => collectIntrinsicEdits,
|
|
24
|
+
intrinsicImports: () => intrinsicImports
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(intrinsics_exports);
|
|
27
|
+
|
|
28
|
+
// src/analyze/intrinsics.ts
|
|
29
|
+
var REACTIVE_MODULE = "@fluixi/reactive/signal";
|
|
30
|
+
var INTRINSICS = {
|
|
31
|
+
$signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
|
|
32
|
+
$memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
|
|
33
|
+
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
34
|
+
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
35
|
+
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
36
|
+
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
37
|
+
// name. Still worth having — no import to write — and when a shorter form is
|
|
38
|
+
// designed, the change is this line rather than a compiler pass.
|
|
39
|
+
$selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
40
|
+
$deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
41
|
+
// Not value constructors, but the compiler has to know them: they change what a read
|
|
42
|
+
// does. `untrack` suppresses dependency collection, which is exactly the kind of thing
|
|
43
|
+
// dependency analysis must not guess at.
|
|
44
|
+
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
45
|
+
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" }
|
|
46
|
+
};
|
|
47
|
+
var RUNTIME_PRIMITIVES = {
|
|
48
|
+
signal: "signal-handle",
|
|
49
|
+
memo: "memo-handle",
|
|
50
|
+
effect: "effect",
|
|
51
|
+
store: "store-handle",
|
|
52
|
+
createSignal: ["signal-accessor", "signal-setter"],
|
|
53
|
+
createMemo: "memo-accessor",
|
|
54
|
+
createEffect: "effect",
|
|
55
|
+
createRenderEffect: "effect",
|
|
56
|
+
createStore: "reactive-object",
|
|
57
|
+
resource: "resource-handle",
|
|
58
|
+
createResource: "reactive-object",
|
|
59
|
+
createSelector: "memo-accessor",
|
|
60
|
+
createDeferred: "memo-accessor"
|
|
61
|
+
};
|
|
62
|
+
var PRIMITIVE_MODULES = [
|
|
63
|
+
"@fluixi/reactive",
|
|
64
|
+
"@fluixi/reactive/signal",
|
|
65
|
+
"@fluixi/reactive/store",
|
|
66
|
+
"@fluixi/core"
|
|
67
|
+
];
|
|
68
|
+
var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
|
|
69
|
+
function isIntrinsicName(name) {
|
|
70
|
+
return Object.prototype.hasOwnProperty.call(INTRINSICS, name);
|
|
71
|
+
}
|
|
72
|
+
function isPrimitiveModule(source) {
|
|
73
|
+
return PRIMITIVE_MODULES.includes(source);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/analyze/reactive-bindings.ts
|
|
77
|
+
function patternNames(node, out) {
|
|
78
|
+
if (!node) return;
|
|
79
|
+
switch (node.type) {
|
|
80
|
+
case "Identifier":
|
|
81
|
+
out.add(node.name);
|
|
82
|
+
return;
|
|
83
|
+
case "ObjectPattern":
|
|
84
|
+
for (const p of node.properties ?? []) {
|
|
85
|
+
if (p.type === "RestElement") patternNames(p.argument, out);
|
|
86
|
+
else patternNames(p.value, out);
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
case "ArrayPattern":
|
|
90
|
+
for (const e of node.elements ?? []) patternNames(e, out);
|
|
91
|
+
return;
|
|
92
|
+
case "AssignmentPattern":
|
|
93
|
+
patternNames(node.left, out);
|
|
94
|
+
return;
|
|
95
|
+
case "RestElement":
|
|
96
|
+
patternNames(node.argument, out);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function walk(root, visit) {
|
|
101
|
+
if (!root || typeof root !== "object" || typeof root.type !== "string") return;
|
|
102
|
+
visit(root);
|
|
103
|
+
for (const key of Object.keys(root)) {
|
|
104
|
+
if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
|
|
105
|
+
const value = root[key];
|
|
106
|
+
if (Array.isArray(value)) for (const item of value) walk(item, visit);
|
|
107
|
+
else if (value && typeof value === "object") walk(value, visit);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function calledPrimitive(node, bindings) {
|
|
111
|
+
if (node.type !== "CallExpression") return void 0;
|
|
112
|
+
const callee = node.callee;
|
|
113
|
+
if (callee?.type !== "Identifier") return void 0;
|
|
114
|
+
const name = callee.name;
|
|
115
|
+
const imported = bindings.primitives.get(name);
|
|
116
|
+
if (imported) return imported;
|
|
117
|
+
const intrinsic = INTRINSICS[name];
|
|
118
|
+
if (intrinsic && !bindings.shadowed.has(name)) return intrinsic.returns;
|
|
119
|
+
return void 0;
|
|
120
|
+
}
|
|
121
|
+
function classify(id, returns, kinds) {
|
|
122
|
+
if (Array.isArray(returns)) {
|
|
123
|
+
if (id.type === "ArrayPattern") {
|
|
124
|
+
id.elements.forEach((element, index) => {
|
|
125
|
+
const kind = returns[index];
|
|
126
|
+
if (element?.type === "Identifier" && kind) kinds.set(element.name, kind);
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (id.type === "Identifier") kinds.set(id.name, returns);
|
|
132
|
+
}
|
|
133
|
+
function resolveReactiveBindings(program) {
|
|
134
|
+
const bindings = { kinds: /* @__PURE__ */ new Map(), primitives: /* @__PURE__ */ new Map(), shadowed: /* @__PURE__ */ new Set() };
|
|
135
|
+
const root = program;
|
|
136
|
+
walk(root, (node) => {
|
|
137
|
+
const names = /* @__PURE__ */ new Set();
|
|
138
|
+
if (node.type === "VariableDeclarator") patternNames(node.id, names);
|
|
139
|
+
else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") patternNames(node.id, names);
|
|
140
|
+
else if (node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") patternNames(node.local, names);
|
|
141
|
+
else if (node.type === "ImportSpecifier") patternNames(node.local, names);
|
|
142
|
+
else if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration") {
|
|
143
|
+
for (const p of node.params ?? []) patternNames(p, names);
|
|
144
|
+
}
|
|
145
|
+
for (const name of names) if (INTRINSICS[name]) bindings.shadowed.add(name);
|
|
146
|
+
});
|
|
147
|
+
for (const statement of root.body ?? []) {
|
|
148
|
+
if (statement.type !== "ImportDeclaration") continue;
|
|
149
|
+
if (!isPrimitiveModule(statement.source?.value)) continue;
|
|
150
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
151
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
152
|
+
const importedNode = specifier.imported;
|
|
153
|
+
const imported = importedNode.type === "Identifier" ? importedNode.name : importedNode.value;
|
|
154
|
+
const returns = RUNTIME_PRIMITIVES[imported];
|
|
155
|
+
if (returns) bindings.primitives.set(specifier.local.name, returns);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
walk(root, (node) => {
|
|
159
|
+
if (node.type !== "VariableDeclarator" || !node.init) return;
|
|
160
|
+
const returns = calledPrimitive(node.init, bindings);
|
|
161
|
+
if (returns) classify(node.id, returns, bindings.kinds);
|
|
162
|
+
});
|
|
163
|
+
return bindings;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/transform/intrinsics.ts
|
|
167
|
+
function walk2(root, visit) {
|
|
168
|
+
if (!root || typeof root !== "object" || typeof root.type !== "string") return;
|
|
169
|
+
visit(root);
|
|
170
|
+
for (const key of Object.keys(root)) {
|
|
171
|
+
if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
|
|
172
|
+
const value = root[key];
|
|
173
|
+
if (Array.isArray(value)) for (const item of value) walk2(item, visit);
|
|
174
|
+
else if (value && typeof value === "object") walk2(value, visit);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function collectIntrinsicEdits(program) {
|
|
178
|
+
const edits = [];
|
|
179
|
+
const diagnostics = [];
|
|
180
|
+
const imports = /* @__PURE__ */ new Map();
|
|
181
|
+
const reported = /* @__PURE__ */ new Set();
|
|
182
|
+
const { shadowed } = resolveReactiveBindings(program);
|
|
183
|
+
walk2(program, (node) => {
|
|
184
|
+
if (node.type !== "CallExpression") return;
|
|
185
|
+
const callee = node.callee;
|
|
186
|
+
if (callee?.type !== "Identifier") return;
|
|
187
|
+
const name = callee.name;
|
|
188
|
+
if (!isIntrinsicName(name)) return;
|
|
189
|
+
if (shadowed.has(name)) {
|
|
190
|
+
if (!reported.has(name)) {
|
|
191
|
+
reported.add(name);
|
|
192
|
+
diagnostics.push({
|
|
193
|
+
name,
|
|
194
|
+
message: `${name} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,
|
|
195
|
+
start: callee.start
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const intrinsic = INTRINSICS[name];
|
|
201
|
+
edits.push({ start: callee.start, end: callee.end, code: intrinsic.export });
|
|
202
|
+
const forModule = imports.get(intrinsic.module) ?? /* @__PURE__ */ new Set();
|
|
203
|
+
forModule.add(intrinsic.export);
|
|
204
|
+
imports.set(intrinsic.module, forModule);
|
|
205
|
+
});
|
|
206
|
+
return { edits, diagnostics, imports };
|
|
207
|
+
}
|
|
208
|
+
function intrinsicImports(result, bound) {
|
|
209
|
+
const lines = [];
|
|
210
|
+
for (const [module2, names] of [...result.imports].sort(([a], [b]) => a.localeCompare(b))) {
|
|
211
|
+
const wanted = [...names].filter((name) => !bound.has(name)).sort();
|
|
212
|
+
if (wanted.length) lines.push(`import { ${wanted.join(", ")} } from ${JSON.stringify(module2)};`);
|
|
213
|
+
}
|
|
214
|
+
return lines.length ? `${lines.join("\n")}
|
|
215
|
+
` : "";
|
|
216
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface IntrinsicEdit {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
code: string;
|
|
5
|
+
}
|
|
6
|
+
export interface IntrinsicDiagnostic {
|
|
7
|
+
/** The `$` name the module bound itself. */
|
|
8
|
+
name: string;
|
|
9
|
+
message: string;
|
|
10
|
+
start: number;
|
|
11
|
+
}
|
|
12
|
+
export interface IntrinsicsResult {
|
|
13
|
+
edits: IntrinsicEdit[];
|
|
14
|
+
diagnostics: IntrinsicDiagnostic[];
|
|
15
|
+
/** Runtime exports the rewritten code needs, by module. */
|
|
16
|
+
imports: Map<string, Set<string>>;
|
|
17
|
+
}
|
|
18
|
+
/** Find the `$` calls in a module and say what they compile to. */
|
|
19
|
+
export declare function collectIntrinsicEdits(program: unknown): IntrinsicsResult;
|
|
20
|
+
/** The import statements a result needs, minus anything the module already binds. */
|
|
21
|
+
export declare function intrinsicImports(result: IntrinsicsResult, bound: Set<string>): string;
|
|
@@ -1,3 +1,193 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
// src/analyze/intrinsics.ts
|
|
2
|
+
var REACTIVE_MODULE = "@fluixi/reactive/signal";
|
|
3
|
+
var INTRINSICS = {
|
|
4
|
+
$signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
|
|
5
|
+
$memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
|
|
6
|
+
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
7
|
+
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
8
|
+
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
9
|
+
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
10
|
+
// name. Still worth having — no import to write — and when a shorter form is
|
|
11
|
+
// designed, the change is this line rather than a compiler pass.
|
|
12
|
+
$selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
13
|
+
$deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
14
|
+
// Not value constructors, but the compiler has to know them: they change what a read
|
|
15
|
+
// does. `untrack` suppresses dependency collection, which is exactly the kind of thing
|
|
16
|
+
// dependency analysis must not guess at.
|
|
17
|
+
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
18
|
+
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" }
|
|
19
|
+
};
|
|
20
|
+
var RUNTIME_PRIMITIVES = {
|
|
21
|
+
signal: "signal-handle",
|
|
22
|
+
memo: "memo-handle",
|
|
23
|
+
effect: "effect",
|
|
24
|
+
store: "store-handle",
|
|
25
|
+
createSignal: ["signal-accessor", "signal-setter"],
|
|
26
|
+
createMemo: "memo-accessor",
|
|
27
|
+
createEffect: "effect",
|
|
28
|
+
createRenderEffect: "effect",
|
|
29
|
+
createStore: "reactive-object",
|
|
30
|
+
resource: "resource-handle",
|
|
31
|
+
createResource: "reactive-object",
|
|
32
|
+
createSelector: "memo-accessor",
|
|
33
|
+
createDeferred: "memo-accessor"
|
|
34
|
+
};
|
|
35
|
+
var PRIMITIVE_MODULES = [
|
|
36
|
+
"@fluixi/reactive",
|
|
37
|
+
"@fluixi/reactive/signal",
|
|
38
|
+
"@fluixi/reactive/store",
|
|
39
|
+
"@fluixi/core"
|
|
40
|
+
];
|
|
41
|
+
var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
|
|
42
|
+
function isIntrinsicName(name) {
|
|
43
|
+
return Object.prototype.hasOwnProperty.call(INTRINSICS, name);
|
|
44
|
+
}
|
|
45
|
+
function isPrimitiveModule(source) {
|
|
46
|
+
return PRIMITIVE_MODULES.includes(source);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/analyze/reactive-bindings.ts
|
|
50
|
+
function patternNames(node, out) {
|
|
51
|
+
if (!node) return;
|
|
52
|
+
switch (node.type) {
|
|
53
|
+
case "Identifier":
|
|
54
|
+
out.add(node.name);
|
|
55
|
+
return;
|
|
56
|
+
case "ObjectPattern":
|
|
57
|
+
for (const p of node.properties ?? []) {
|
|
58
|
+
if (p.type === "RestElement") patternNames(p.argument, out);
|
|
59
|
+
else patternNames(p.value, out);
|
|
60
|
+
}
|
|
61
|
+
return;
|
|
62
|
+
case "ArrayPattern":
|
|
63
|
+
for (const e of node.elements ?? []) patternNames(e, out);
|
|
64
|
+
return;
|
|
65
|
+
case "AssignmentPattern":
|
|
66
|
+
patternNames(node.left, out);
|
|
67
|
+
return;
|
|
68
|
+
case "RestElement":
|
|
69
|
+
patternNames(node.argument, out);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function walk(root, visit) {
|
|
74
|
+
if (!root || typeof root !== "object" || typeof root.type !== "string") return;
|
|
75
|
+
visit(root);
|
|
76
|
+
for (const key of Object.keys(root)) {
|
|
77
|
+
if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
|
|
78
|
+
const value = root[key];
|
|
79
|
+
if (Array.isArray(value)) for (const item of value) walk(item, visit);
|
|
80
|
+
else if (value && typeof value === "object") walk(value, visit);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function calledPrimitive(node, bindings) {
|
|
84
|
+
if (node.type !== "CallExpression") return void 0;
|
|
85
|
+
const callee = node.callee;
|
|
86
|
+
if (callee?.type !== "Identifier") return void 0;
|
|
87
|
+
const name = callee.name;
|
|
88
|
+
const imported = bindings.primitives.get(name);
|
|
89
|
+
if (imported) return imported;
|
|
90
|
+
const intrinsic = INTRINSICS[name];
|
|
91
|
+
if (intrinsic && !bindings.shadowed.has(name)) return intrinsic.returns;
|
|
92
|
+
return void 0;
|
|
93
|
+
}
|
|
94
|
+
function classify(id, returns, kinds) {
|
|
95
|
+
if (Array.isArray(returns)) {
|
|
96
|
+
if (id.type === "ArrayPattern") {
|
|
97
|
+
id.elements.forEach((element, index) => {
|
|
98
|
+
const kind = returns[index];
|
|
99
|
+
if (element?.type === "Identifier" && kind) kinds.set(element.name, kind);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (id.type === "Identifier") kinds.set(id.name, returns);
|
|
105
|
+
}
|
|
106
|
+
function resolveReactiveBindings(program) {
|
|
107
|
+
const bindings = { kinds: /* @__PURE__ */ new Map(), primitives: /* @__PURE__ */ new Map(), shadowed: /* @__PURE__ */ new Set() };
|
|
108
|
+
const root = program;
|
|
109
|
+
walk(root, (node) => {
|
|
110
|
+
const names = /* @__PURE__ */ new Set();
|
|
111
|
+
if (node.type === "VariableDeclarator") patternNames(node.id, names);
|
|
112
|
+
else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") patternNames(node.id, names);
|
|
113
|
+
else if (node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") patternNames(node.local, names);
|
|
114
|
+
else if (node.type === "ImportSpecifier") patternNames(node.local, names);
|
|
115
|
+
else if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration") {
|
|
116
|
+
for (const p of node.params ?? []) patternNames(p, names);
|
|
117
|
+
}
|
|
118
|
+
for (const name of names) if (INTRINSICS[name]) bindings.shadowed.add(name);
|
|
119
|
+
});
|
|
120
|
+
for (const statement of root.body ?? []) {
|
|
121
|
+
if (statement.type !== "ImportDeclaration") continue;
|
|
122
|
+
if (!isPrimitiveModule(statement.source?.value)) continue;
|
|
123
|
+
for (const specifier of statement.specifiers ?? []) {
|
|
124
|
+
if (specifier.type !== "ImportSpecifier") continue;
|
|
125
|
+
const importedNode = specifier.imported;
|
|
126
|
+
const imported = importedNode.type === "Identifier" ? importedNode.name : importedNode.value;
|
|
127
|
+
const returns = RUNTIME_PRIMITIVES[imported];
|
|
128
|
+
if (returns) bindings.primitives.set(specifier.local.name, returns);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
walk(root, (node) => {
|
|
132
|
+
if (node.type !== "VariableDeclarator" || !node.init) return;
|
|
133
|
+
const returns = calledPrimitive(node.init, bindings);
|
|
134
|
+
if (returns) classify(node.id, returns, bindings.kinds);
|
|
135
|
+
});
|
|
136
|
+
return bindings;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// src/transform/intrinsics.ts
|
|
140
|
+
function walk2(root, visit) {
|
|
141
|
+
if (!root || typeof root !== "object" || typeof root.type !== "string") return;
|
|
142
|
+
visit(root);
|
|
143
|
+
for (const key of Object.keys(root)) {
|
|
144
|
+
if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
|
|
145
|
+
const value = root[key];
|
|
146
|
+
if (Array.isArray(value)) for (const item of value) walk2(item, visit);
|
|
147
|
+
else if (value && typeof value === "object") walk2(value, visit);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function collectIntrinsicEdits(program) {
|
|
151
|
+
const edits = [];
|
|
152
|
+
const diagnostics = [];
|
|
153
|
+
const imports = /* @__PURE__ */ new Map();
|
|
154
|
+
const reported = /* @__PURE__ */ new Set();
|
|
155
|
+
const { shadowed } = resolveReactiveBindings(program);
|
|
156
|
+
walk2(program, (node) => {
|
|
157
|
+
if (node.type !== "CallExpression") return;
|
|
158
|
+
const callee = node.callee;
|
|
159
|
+
if (callee?.type !== "Identifier") return;
|
|
160
|
+
const name = callee.name;
|
|
161
|
+
if (!isIntrinsicName(name)) return;
|
|
162
|
+
if (shadowed.has(name)) {
|
|
163
|
+
if (!reported.has(name)) {
|
|
164
|
+
reported.add(name);
|
|
165
|
+
diagnostics.push({
|
|
166
|
+
name,
|
|
167
|
+
message: `${name} is reserved for the compiler, and this module binds it. The call keeps your binding's meaning; rename it to use the intrinsic.`,
|
|
168
|
+
start: callee.start
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const intrinsic = INTRINSICS[name];
|
|
174
|
+
edits.push({ start: callee.start, end: callee.end, code: intrinsic.export });
|
|
175
|
+
const forModule = imports.get(intrinsic.module) ?? /* @__PURE__ */ new Set();
|
|
176
|
+
forModule.add(intrinsic.export);
|
|
177
|
+
imports.set(intrinsic.module, forModule);
|
|
178
|
+
});
|
|
179
|
+
return { edits, diagnostics, imports };
|
|
180
|
+
}
|
|
181
|
+
function intrinsicImports(result, bound) {
|
|
182
|
+
const lines = [];
|
|
183
|
+
for (const [module, names] of [...result.imports].sort(([a], [b]) => a.localeCompare(b))) {
|
|
184
|
+
const wanted = [...names].filter((name) => !bound.has(name)).sort();
|
|
185
|
+
if (wanted.length) lines.push(`import { ${wanted.join(", ")} } from ${JSON.stringify(module)};`);
|
|
186
|
+
}
|
|
187
|
+
return lines.length ? `${lines.join("\n")}
|
|
188
|
+
` : "";
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
collectIntrinsicEdits,
|
|
192
|
+
intrinsicImports
|
|
193
|
+
};
|