@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,22 +1,306 @@
|
|
|
1
|
-
|
|
1
|
+
// src/resolve/write-globals.ts
|
|
2
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, relative, sep, resolve as resolvePath } from "node:path";
|
|
4
|
+
|
|
5
|
+
// src/resolve/component-resolver.ts
|
|
6
|
+
var isMapRule = (rule) => "components" in rule;
|
|
7
|
+
function substitute(template, match) {
|
|
8
|
+
return template.replace(/\$(\d+)/g, (whole, index) => {
|
|
9
|
+
const group = match[Number(index)];
|
|
10
|
+
return group ?? whole;
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
function normalise(name, entry) {
|
|
14
|
+
return typeof entry === "string" ? { module: entry, export: name } : entry;
|
|
15
|
+
}
|
|
16
|
+
function createComponentResolver(rules = []) {
|
|
17
|
+
const exact = /* @__PURE__ */ new Map();
|
|
18
|
+
const conflicts = [];
|
|
19
|
+
const patterns = [];
|
|
20
|
+
for (const rule of rules) {
|
|
21
|
+
if (!isMapRule(rule)) {
|
|
22
|
+
patterns.push(rule);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
for (const [name, entry] of Object.entries(rule.components)) {
|
|
26
|
+
const resolved = normalise(name, entry);
|
|
27
|
+
const existing = exact.get(name);
|
|
28
|
+
if (existing && existing.module !== resolved.module) {
|
|
29
|
+
const conflict = conflicts.find((c) => c.name === name);
|
|
30
|
+
if (conflict) conflict.modules.push(resolved.module);
|
|
31
|
+
else conflicts.push({ name, modules: [existing.module, resolved.module] });
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
exact.set(name, resolved);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const cache = /* @__PURE__ */ new Map();
|
|
38
|
+
const resolve = (name) => {
|
|
39
|
+
if (cache.has(name)) return cache.get(name);
|
|
40
|
+
let result = exact.get(name);
|
|
41
|
+
if (!result) {
|
|
42
|
+
for (const rule of patterns) {
|
|
43
|
+
const match = name.match(new RegExp(rule.match.source, rule.match.flags.replace("g", "")));
|
|
44
|
+
if (!match) continue;
|
|
45
|
+
result = {
|
|
46
|
+
module: substitute(rule.module, match),
|
|
47
|
+
export: rule.export ? substitute(rule.export, match) : name
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
cache.set(name, result);
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
return {
|
|
56
|
+
resolve,
|
|
57
|
+
names: () => [...exact.keys()],
|
|
58
|
+
conflicts: () => conflicts
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// src/resolve/builtins.ts
|
|
63
|
+
var DOM_CONTROL_FLOW = [
|
|
64
|
+
"Show",
|
|
65
|
+
"For",
|
|
66
|
+
"Index",
|
|
67
|
+
"Switch",
|
|
68
|
+
"Match",
|
|
69
|
+
"Portal",
|
|
70
|
+
"Dynamic",
|
|
71
|
+
"ErrorBoundary"
|
|
72
|
+
];
|
|
73
|
+
var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
|
|
74
|
+
var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
|
|
75
|
+
var BUILTIN_COMPONENTS = [
|
|
76
|
+
...DOM_CONTROL_FLOW,
|
|
77
|
+
...CORE_CONTROL_FLOW,
|
|
78
|
+
...ROUTER_COMPONENTS
|
|
79
|
+
];
|
|
80
|
+
var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
|
|
81
|
+
...DOM_CONTROL_FLOW,
|
|
82
|
+
...CORE_CONTROL_FLOW
|
|
83
|
+
]);
|
|
84
|
+
function builtinComponentMap(modules = {}) {
|
|
85
|
+
const {
|
|
86
|
+
controlFlowModule = "@fluixi/dom",
|
|
87
|
+
coreModule = "@fluixi/core",
|
|
88
|
+
routerModule = "@fluixi/core/router"
|
|
89
|
+
} = modules;
|
|
90
|
+
const map = {};
|
|
91
|
+
for (const name of DOM_CONTROL_FLOW) map[name] = controlFlowModule;
|
|
92
|
+
for (const name of CORE_CONTROL_FLOW) map[name] = coreModule;
|
|
93
|
+
for (const name of ROUTER_COMPONENTS) map[name] = routerModule;
|
|
94
|
+
return map;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/analyze/intrinsics.ts
|
|
98
|
+
var REACTIVE_MODULE = "@fluixi/reactive/signal";
|
|
99
|
+
var INTRINSICS = {
|
|
100
|
+
$signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
|
|
101
|
+
$memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
|
|
102
|
+
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
103
|
+
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
104
|
+
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
105
|
+
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
106
|
+
// name. Still worth having — no import to write — and when a shorter form is
|
|
107
|
+
// designed, the change is this line rather than a compiler pass.
|
|
108
|
+
$selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
109
|
+
$deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
110
|
+
// Not value constructors, but the compiler has to know them: they change what a read
|
|
111
|
+
// does. `untrack` suppresses dependency collection, which is exactly the kind of thing
|
|
112
|
+
// dependency analysis must not guess at.
|
|
113
|
+
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
114
|
+
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" }
|
|
115
|
+
};
|
|
116
|
+
var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
|
|
117
|
+
|
|
118
|
+
// src/resolve/component-globals.ts
|
|
119
|
+
var DOM_GLOBALS = /* @__PURE__ */ new Set([
|
|
120
|
+
"Text",
|
|
121
|
+
"Image",
|
|
122
|
+
"Option",
|
|
123
|
+
"Audio",
|
|
124
|
+
"Comment",
|
|
125
|
+
"Range",
|
|
126
|
+
"Selection",
|
|
127
|
+
"Notification",
|
|
128
|
+
"Event",
|
|
129
|
+
"Document",
|
|
130
|
+
"Element",
|
|
131
|
+
"Node",
|
|
132
|
+
"Screen",
|
|
133
|
+
"Window",
|
|
134
|
+
"Location",
|
|
135
|
+
"History",
|
|
136
|
+
"Storage",
|
|
137
|
+
"Response",
|
|
138
|
+
"Request",
|
|
139
|
+
"Headers"
|
|
140
|
+
]);
|
|
141
|
+
function packageOf(specifier) {
|
|
142
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) return void 0;
|
|
143
|
+
if (/^[~@]\//.test(specifier)) return void 0;
|
|
144
|
+
const parts = specifier.split("/");
|
|
145
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
146
|
+
}
|
|
147
|
+
function namespaceAlias(module) {
|
|
148
|
+
return `_${module.replace(/[^A-Za-z0-9]/g, "_")}`;
|
|
149
|
+
}
|
|
150
|
+
function componentGlobals(rules, options = {}) {
|
|
151
|
+
const {
|
|
152
|
+
available: availableList,
|
|
153
|
+
builtins = true,
|
|
154
|
+
intrinsics = true,
|
|
155
|
+
generator = "@fluixi/compiler",
|
|
156
|
+
specifier = (module) => module
|
|
157
|
+
} = options;
|
|
158
|
+
const all = [...rules];
|
|
159
|
+
if (builtins) {
|
|
160
|
+
all.push({ components: builtinComponentMap() });
|
|
161
|
+
}
|
|
162
|
+
const resolver = createComponentResolver(all);
|
|
163
|
+
const available = availableList ? new Set(availableList) : void 0;
|
|
164
|
+
const declared = [];
|
|
165
|
+
const shadowedByDom = [];
|
|
166
|
+
const unavailable = [];
|
|
167
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
168
|
+
for (const name of [...resolver.names()].sort()) {
|
|
169
|
+
const target = resolver.resolve(name);
|
|
170
|
+
if (!target) continue;
|
|
171
|
+
const pkg = packageOf(target.module);
|
|
172
|
+
if (DOM_GLOBALS.has(name)) shadowedByDom.push(name);
|
|
173
|
+
else if (available && pkg && !available.has(pkg)) unavailable.push(name);
|
|
174
|
+
else {
|
|
175
|
+
declared.push(name);
|
|
176
|
+
resolved.set(name, target);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const intrinsicModules = intrinsics ? [...new Set(Object.values(INTRINSICS).map((i) => i.module))] : [];
|
|
180
|
+
const modules = [
|
|
181
|
+
.../* @__PURE__ */ new Set([...declared.map((name) => resolved.get(name).module), ...intrinsicModules])
|
|
182
|
+
].sort();
|
|
183
|
+
const imports = modules.map(
|
|
184
|
+
(m) => `import * as ${namespaceAlias(m)} from '${specifier(m)}';`
|
|
185
|
+
);
|
|
186
|
+
const lines = declared.map((name) => {
|
|
187
|
+
const target = resolved.get(name);
|
|
188
|
+
const ns = namespaceAlias(target.module);
|
|
189
|
+
return target.export === "default" ? ` const ${name}: typeof ${ns}.default;` : ` export import ${name} = ${ns}.${target.export};`;
|
|
190
|
+
});
|
|
191
|
+
const note = shadowedByDom.length > 0 ? `//
|
|
2
192
|
// Import these explicitly — lib.dom already declares the name, so an ambient
|
|
3
193
|
// declaration cannot win:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
194
|
+
` + shadowedByDom.map((n) => {
|
|
195
|
+
const module = resolver.resolve(n)?.module;
|
|
196
|
+
return `// import { ${n} } from '${module ? specifier(module) : ""}';
|
|
197
|
+
`;
|
|
198
|
+
}).join("") : "";
|
|
199
|
+
const intrinsicLines = intrinsics ? Object.entries(INTRINSICS).map(
|
|
200
|
+
([name, intrinsic]) => ` const ${name}: typeof ${namespaceAlias(intrinsic.module)}.${intrinsic.export};`
|
|
201
|
+
) : [];
|
|
202
|
+
const patternRules = rules.filter((rule) => "match" in rule).length;
|
|
203
|
+
const patternNote = patternRules > 0 ? `//
|
|
204
|
+
// ${patternRules} pattern rule${patternRules === 1 ? "" : "s"} cannot be declared:
|
|
7
205
|
// a pattern matches unboundedly many names, so there is no list to emit. Those
|
|
8
206
|
// tags still resolve at build time; declare them by hand if the editor needs them.
|
|
9
|
-
|
|
207
|
+
` : "";
|
|
208
|
+
const source = `// GENERATED by ${generator} — do not edit.
|
|
10
209
|
//
|
|
11
210
|
// The components \`resolve\` supplies without an import. This describes what the
|
|
12
211
|
// compiler already does; it does not enable it.
|
|
13
|
-
|
|
14
|
-
${
|
|
15
|
-
`)
|
|
16
|
-
`:`
|
|
17
|
-
`)+`
|
|
212
|
+
` + note + patternNote + (imports.length > 0 ? `
|
|
213
|
+
${imports.join("\n")}
|
|
214
|
+
` : "\n") + `
|
|
18
215
|
declare global {
|
|
19
|
-
${[...
|
|
20
|
-
|
|
216
|
+
${[...lines, ...intrinsicLines].join("\n")}
|
|
217
|
+
}
|
|
218
|
+
`;
|
|
219
|
+
return { source, declared, shadowedByDom, unavailable, patternRules };
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// src/resolve/write-globals.ts
|
|
223
|
+
var GENERATED_MARKER = "GENERATED by @fluixi/compiler";
|
|
224
|
+
var DEFAULT_GLOBALS_PATH = "fluixi.d.ts";
|
|
225
|
+
function coveredByInclude(root, target) {
|
|
226
|
+
let config;
|
|
227
|
+
try {
|
|
228
|
+
const raw = readFileSync(resolvePath(root, "tsconfig.json"), "utf8");
|
|
229
|
+
config = JSON.parse(raw.replace(/^\s*\/\/.*$/gm, ""));
|
|
230
|
+
} catch {
|
|
231
|
+
return void 0;
|
|
232
|
+
}
|
|
233
|
+
if (config.extends !== void 0) return void 0;
|
|
234
|
+
if (!Array.isArray(config.include)) return true;
|
|
235
|
+
const relative2 = relativePosix(root, target);
|
|
236
|
+
return config.include.some((entry) => {
|
|
237
|
+
if (typeof entry !== "string") return false;
|
|
238
|
+
const pattern = entry.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "(?:.*/)?").replace(/\*/g, "[^/]*");
|
|
239
|
+
return new RegExp(`^${pattern}(?:/.*)?$`).test(relative2);
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
function relativePosix(from, to) {
|
|
243
|
+
return relative(from, to).split(sep).join("/");
|
|
244
|
+
}
|
|
245
|
+
function forTypeScript(module, outDir, root) {
|
|
246
|
+
if (!module.startsWith("/")) return module;
|
|
247
|
+
const absolute = resolvePath(root, module.slice(1));
|
|
248
|
+
let rel = relative(outDir, absolute).split(sep).join("/");
|
|
249
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
250
|
+
return rel.replace(/\.(tsx|ts|jsx|mts|cts)$/, ".js");
|
|
251
|
+
}
|
|
252
|
+
function projectDependencies(root) {
|
|
253
|
+
try {
|
|
254
|
+
const manifest = JSON.parse(readFileSync(resolvePath(root, "package.json"), "utf8"));
|
|
255
|
+
return [
|
|
256
|
+
...Object.keys(manifest.dependencies ?? {}),
|
|
257
|
+
...Object.keys(manifest.devDependencies ?? {}),
|
|
258
|
+
...Object.keys(manifest.peerDependencies ?? {})
|
|
259
|
+
];
|
|
260
|
+
} catch {
|
|
261
|
+
return void 0;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function writeComponentGlobals(options, root) {
|
|
265
|
+
if (options.globals === false) return { status: "skipped", reason: "disabled" };
|
|
266
|
+
const rules = options.resolve ?? [];
|
|
267
|
+
const target = resolvePath(root, options.globals ?? DEFAULT_GLOBALS_PATH);
|
|
268
|
+
let existing;
|
|
269
|
+
try {
|
|
270
|
+
existing = readFileSync(target, "utf8");
|
|
271
|
+
} catch {
|
|
272
|
+
existing = void 0;
|
|
273
|
+
}
|
|
274
|
+
if (existing !== void 0 && !existing.includes(GENERATED_MARKER)) {
|
|
275
|
+
return { status: "skipped", reason: "foreign-file", path: target };
|
|
276
|
+
}
|
|
277
|
+
const { source, declared } = componentGlobals(rules, {
|
|
278
|
+
available: projectDependencies(root),
|
|
279
|
+
specifier: (module) => forTypeScript(module, dirname(target), root)
|
|
280
|
+
});
|
|
281
|
+
if (existing === source) {
|
|
282
|
+
return {
|
|
283
|
+
status: "unchanged",
|
|
284
|
+
path: target,
|
|
285
|
+
declared: declared.length,
|
|
286
|
+
warning: warnIfUnreachable(root, target)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
290
|
+
writeFileSync(target, source);
|
|
291
|
+
return {
|
|
292
|
+
status: "written",
|
|
293
|
+
path: target,
|
|
294
|
+
declared: declared.length,
|
|
295
|
+
warning: warnIfUnreachable(root, target)
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function warnIfUnreachable(root, target) {
|
|
299
|
+
if (coveredByInclude(root, target) !== false) return void 0;
|
|
300
|
+
const relative2 = relativePosix(root, target);
|
|
301
|
+
return `[fluixi] ${relative2} is not covered by "include" in tsconfig.json, so TypeScript will ignore it and every resolved component stays "Cannot find name". Add "${relative2}" to "include".`;
|
|
21
302
|
}
|
|
22
|
-
|
|
303
|
+
export {
|
|
304
|
+
DEFAULT_GLOBALS_PATH,
|
|
305
|
+
writeComponentGlobals
|
|
306
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
import {
|
|
3
|
+
MagicString
|
|
4
|
+
} from "./chunk-R2VHAZAX.mjs";
|
|
5
|
+
import {
|
|
6
|
+
serverFnId
|
|
7
|
+
} from "./chunk-FSSWUXUR.mjs";
|
|
8
|
+
import "./chunk-3YKZ4GNH.mjs";
|
|
9
|
+
|
|
10
|
+
// src/transform/server-fns.ts
|
|
11
|
+
import { parse } from "@babel/parser";
|
|
12
|
+
var RUNTIME = "@fluixi/start/server-fn";
|
|
13
|
+
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
14
|
+
"FunctionDeclaration",
|
|
15
|
+
"FunctionExpression",
|
|
16
|
+
"ArrowFunctionExpression"
|
|
17
|
+
]);
|
|
18
|
+
function directive(node) {
|
|
19
|
+
if (!FUNCTION_TYPES.has(node.type)) return null;
|
|
20
|
+
const body = node.body;
|
|
21
|
+
if (!body || body.type !== "BlockStatement") return null;
|
|
22
|
+
for (const d of body.directives ?? []) {
|
|
23
|
+
if (d.value?.value === "use server") return d;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function findServerFns(node, out) {
|
|
28
|
+
if (!node || typeof node !== "object") return;
|
|
29
|
+
if (Array.isArray(node)) {
|
|
30
|
+
for (const child of node) findServerFns(child, out);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (typeof node.type === "string") {
|
|
34
|
+
const found = directive(node);
|
|
35
|
+
if (found) {
|
|
36
|
+
out.push({ fn: node, directive: found });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
for (const key of Object.keys(node)) {
|
|
41
|
+
if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
|
|
42
|
+
findServerFns(node[key], out);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function transformServerFns(code, options) {
|
|
46
|
+
if (!code.includes("use server")) return null;
|
|
47
|
+
const ast = parse(code, {
|
|
48
|
+
sourceType: "module",
|
|
49
|
+
plugins: ["jsx", "typescript"],
|
|
50
|
+
errorRecovery: true
|
|
51
|
+
});
|
|
52
|
+
const found = [];
|
|
53
|
+
findServerFns(ast.program, found);
|
|
54
|
+
if (found.length === 0) return null;
|
|
55
|
+
const helper = options.ssr ? "$$registerServerFn" : "$$createServerReference";
|
|
56
|
+
const out = new MagicString(code);
|
|
57
|
+
found.forEach(({ fn, directive: dir }, index) => {
|
|
58
|
+
const id = serverFnId(options.filename, options.root, index);
|
|
59
|
+
const declaration = fn.type === "FunctionDeclaration";
|
|
60
|
+
if (!options.ssr) {
|
|
61
|
+
const stub = `${helper}(${JSON.stringify(id)})`;
|
|
62
|
+
out.overwrite(fn.start, fn.end, declaration ? `const ${fn.id.name} = ${stub};` : stub);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
out.remove(dir.start, dir.end);
|
|
66
|
+
out.appendLeft(fn.start, declaration ? `const ${fn.id.name} = ${helper}(${JSON.stringify(id)}, ` : `${helper}(${JSON.stringify(id)}, `);
|
|
67
|
+
out.appendRight(fn.end, declaration ? ");" : ")");
|
|
68
|
+
});
|
|
69
|
+
out.prepend(`import { ${helper} } from ${JSON.stringify(options.runtimeModule ?? RUNTIME)};
|
|
70
|
+
`);
|
|
71
|
+
return {
|
|
72
|
+
code: out.toString(),
|
|
73
|
+
map: out.generateMap({ source: options.filename, includeContent: true, hires: true })
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
transformServerFns
|
|
78
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
import {
|
|
3
|
+
serverFnId
|
|
4
|
+
} from "./chunk-FSSWUXUR.mjs";
|
|
5
|
+
import "./chunk-3YKZ4GNH.mjs";
|
|
6
|
+
|
|
7
|
+
// src/frontend/babel/server-functions.ts
|
|
8
|
+
import { transformSync } from "@babel/core";
|
|
9
|
+
var RUNTIME = "@fluixi/start/server-fn";
|
|
10
|
+
function serverFunctionsBabelPlugin({ types: t }) {
|
|
11
|
+
return {
|
|
12
|
+
name: "fluixi-server-functions",
|
|
13
|
+
visitor: {
|
|
14
|
+
Program: {
|
|
15
|
+
enter(_path, state) {
|
|
16
|
+
state.fxIndex = 0;
|
|
17
|
+
state.fxUsed = null;
|
|
18
|
+
},
|
|
19
|
+
exit(path, state) {
|
|
20
|
+
if (!state.fxUsed) return;
|
|
21
|
+
path.unshiftContainer(
|
|
22
|
+
"body",
|
|
23
|
+
t.importDeclaration(
|
|
24
|
+
[t.importSpecifier(t.identifier(state.fxUsed), t.identifier(state.fxUsed))],
|
|
25
|
+
t.stringLiteral(state.opts.runtimeModule || RUNTIME)
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression": (path, state) => {
|
|
31
|
+
const body = path.node.body;
|
|
32
|
+
if (!t.isBlockStatement(body)) return;
|
|
33
|
+
const dirs = body.directives || [];
|
|
34
|
+
const di = dirs.findIndex((d) => d.value.value === "use server");
|
|
35
|
+
if (di < 0) return;
|
|
36
|
+
body.directives.splice(di, 1);
|
|
37
|
+
const id = serverFnId(
|
|
38
|
+
state.opts.filename || state.filename || "unknown",
|
|
39
|
+
state.opts.root,
|
|
40
|
+
state.fxIndex++
|
|
41
|
+
);
|
|
42
|
+
const ssr = !!state.opts.ssr;
|
|
43
|
+
const helper = ssr ? "$$registerServerFn" : "$$createServerReference";
|
|
44
|
+
state.fxUsed = helper;
|
|
45
|
+
const replacement = ssr ? t.callExpression(t.identifier(helper), [
|
|
46
|
+
t.stringLiteral(id),
|
|
47
|
+
path.isFunctionDeclaration() ? t.functionExpression(
|
|
48
|
+
null,
|
|
49
|
+
path.node.params,
|
|
50
|
+
body,
|
|
51
|
+
path.node.generator,
|
|
52
|
+
path.node.async
|
|
53
|
+
) : path.node
|
|
54
|
+
]) : t.callExpression(t.identifier(helper), [t.stringLiteral(id)]);
|
|
55
|
+
if (path.isFunctionDeclaration()) {
|
|
56
|
+
path.replaceWith(
|
|
57
|
+
t.variableDeclaration("const", [t.variableDeclarator(path.node.id, replacement)])
|
|
58
|
+
);
|
|
59
|
+
} else {
|
|
60
|
+
path.replaceWith(replacement);
|
|
61
|
+
}
|
|
62
|
+
path.skip();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function transformServerFunctions(code, opts) {
|
|
68
|
+
if (!code.includes("use server")) return null;
|
|
69
|
+
const result = transformSync(code, {
|
|
70
|
+
filename: opts.filename,
|
|
71
|
+
configFile: false,
|
|
72
|
+
babelrc: false,
|
|
73
|
+
sourceMaps: true,
|
|
74
|
+
parserOpts: { plugins: ["typescript", "jsx"] },
|
|
75
|
+
plugins: [[serverFunctionsBabelPlugin, opts]]
|
|
76
|
+
});
|
|
77
|
+
if (!result?.code) return null;
|
|
78
|
+
return { code: result.code, map: result.map };
|
|
79
|
+
}
|
|
80
|
+
export {
|
|
81
|
+
transformServerFunctions
|
|
82
|
+
};
|
|
@@ -1 +1,71 @@
|
|
|
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/bindings.ts
|
|
21
|
+
var bindings_exports = {};
|
|
22
|
+
__export(bindings_exports, {
|
|
23
|
+
moduleBindings: () => moduleBindings
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(bindings_exports);
|
|
26
|
+
function patternNames(node, out) {
|
|
27
|
+
if (!node) return;
|
|
28
|
+
switch (node.type) {
|
|
29
|
+
case "Identifier":
|
|
30
|
+
out.add(node.name);
|
|
31
|
+
return;
|
|
32
|
+
case "ObjectPattern":
|
|
33
|
+
for (const p of node.properties) {
|
|
34
|
+
if (p.type === "RestElement") patternNames(p.argument, out);
|
|
35
|
+
else patternNames(p.value, out);
|
|
36
|
+
}
|
|
37
|
+
return;
|
|
38
|
+
case "ArrayPattern":
|
|
39
|
+
for (const e of node.elements) patternNames(e, out);
|
|
40
|
+
return;
|
|
41
|
+
case "AssignmentPattern":
|
|
42
|
+
patternNames(node.left, out);
|
|
43
|
+
return;
|
|
44
|
+
case "RestElement":
|
|
45
|
+
patternNames(node.argument, out);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function declared(node, out) {
|
|
50
|
+
switch (node.type) {
|
|
51
|
+
case "ImportDeclaration":
|
|
52
|
+
for (const s of node.specifiers) patternNames(s.local, out);
|
|
53
|
+
return;
|
|
54
|
+
case "VariableDeclaration":
|
|
55
|
+
for (const d of node.declarations) patternNames(d.id, out);
|
|
56
|
+
return;
|
|
57
|
+
case "FunctionDeclaration":
|
|
58
|
+
case "ClassDeclaration":
|
|
59
|
+
patternNames(node.id, out);
|
|
60
|
+
return;
|
|
61
|
+
case "ExportNamedDeclaration":
|
|
62
|
+
case "ExportDefaultDeclaration":
|
|
63
|
+
if (node.declaration) declared(node.declaration, out);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function moduleBindings(program) {
|
|
68
|
+
const names = /* @__PURE__ */ new Set();
|
|
69
|
+
for (const statement of program.body) declared(statement, names);
|
|
70
|
+
return names;
|
|
71
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names bound at module scope.
|
|
3
|
+
*
|
|
4
|
+
* Injected imports are skipped when the name already exists, so a file with its
|
|
5
|
+
* own `Show` keeps it. Only module scope matters: a `const insert = …` inside a
|
|
6
|
+
* function shadows our import there but cannot collide with it, which is the same
|
|
7
|
+
* answer `path.scope.hasBinding` gives on the Program path.
|
|
8
|
+
*
|
|
9
|
+
* Missing a binding emits a duplicate declaration — a syntax error. Reporting one
|
|
10
|
+
* that isn't there drops an import the code needs. Both are loud, neither is
|
|
11
|
+
* subtle, and the corpus in bindings.spec.ts covers the patterns that bind.
|
|
12
|
+
*/
|
|
13
|
+
/** Collect the names bound at the top level of a parsed module. */
|
|
14
|
+
export declare function moduleBindings(program: {
|
|
15
|
+
body: unknown[];
|
|
16
|
+
}): Set<string>;
|
|
@@ -1 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
// src/transform/bindings.ts
|
|
2
|
+
function patternNames(node, out) {
|
|
3
|
+
if (!node) return;
|
|
4
|
+
switch (node.type) {
|
|
5
|
+
case "Identifier":
|
|
6
|
+
out.add(node.name);
|
|
7
|
+
return;
|
|
8
|
+
case "ObjectPattern":
|
|
9
|
+
for (const p of node.properties) {
|
|
10
|
+
if (p.type === "RestElement") patternNames(p.argument, out);
|
|
11
|
+
else patternNames(p.value, out);
|
|
12
|
+
}
|
|
13
|
+
return;
|
|
14
|
+
case "ArrayPattern":
|
|
15
|
+
for (const e of node.elements) patternNames(e, out);
|
|
16
|
+
return;
|
|
17
|
+
case "AssignmentPattern":
|
|
18
|
+
patternNames(node.left, out);
|
|
19
|
+
return;
|
|
20
|
+
case "RestElement":
|
|
21
|
+
patternNames(node.argument, out);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function declared(node, out) {
|
|
26
|
+
switch (node.type) {
|
|
27
|
+
case "ImportDeclaration":
|
|
28
|
+
for (const s of node.specifiers) patternNames(s.local, out);
|
|
29
|
+
return;
|
|
30
|
+
case "VariableDeclaration":
|
|
31
|
+
for (const d of node.declarations) patternNames(d.id, out);
|
|
32
|
+
return;
|
|
33
|
+
case "FunctionDeclaration":
|
|
34
|
+
case "ClassDeclaration":
|
|
35
|
+
patternNames(node.id, out);
|
|
36
|
+
return;
|
|
37
|
+
case "ExportNamedDeclaration":
|
|
38
|
+
case "ExportDefaultDeclaration":
|
|
39
|
+
if (node.declaration) declared(node.declaration, out);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
function moduleBindings(program) {
|
|
44
|
+
const names = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const statement of program.body) declared(statement, names);
|
|
46
|
+
return names;
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
moduleBindings
|
|
50
|
+
};
|