@fluixi/compiler 1.0.0-alpha.83 → 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 -1
- package/dist/analyze/static-graph.d.cts +102 -0
- package/dist/analyze/static-graph.mjs +793 -1
- 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 +12 -8
- 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.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.mjs +1574 -13
- package/dist/integrations.cjs +4307 -25
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.mjs +531 -17
- package/dist/ir/nodes.cjs +18 -1
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/lower/compile-template.cjs +1356 -1
- package/dist/lower/compile-template.d.cts +69 -0
- 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.map +1 -1
- package/dist/lower/jsx.js +2 -1
- 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.map +1 -1
- package/dist/lower/template.js +5 -4
- 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 -1
- package/dist/transform/source-locations.d.cts +43 -0
- 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.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-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
package/dist/integrations.mjs
CHANGED
|
@@ -1,27 +1,541 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
import {
|
|
3
|
+
INTRINSICS,
|
|
4
|
+
builtinComponentMap,
|
|
5
|
+
createComponentResolver
|
|
6
|
+
} from "./chunk-MJV3UXIL.mjs";
|
|
7
|
+
import {
|
|
8
|
+
__require
|
|
9
|
+
} from "./chunk-3YKZ4GNH.mjs";
|
|
10
|
+
|
|
11
|
+
// src/resolve/write-globals.ts
|
|
12
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { dirname, relative, sep, resolve as resolvePath } from "node:path";
|
|
14
|
+
|
|
15
|
+
// src/resolve/component-globals.ts
|
|
16
|
+
var DOM_GLOBALS = /* @__PURE__ */ new Set([
|
|
17
|
+
"Text",
|
|
18
|
+
"Image",
|
|
19
|
+
"Option",
|
|
20
|
+
"Audio",
|
|
21
|
+
"Comment",
|
|
22
|
+
"Range",
|
|
23
|
+
"Selection",
|
|
24
|
+
"Notification",
|
|
25
|
+
"Event",
|
|
26
|
+
"Document",
|
|
27
|
+
"Element",
|
|
28
|
+
"Node",
|
|
29
|
+
"Screen",
|
|
30
|
+
"Window",
|
|
31
|
+
"Location",
|
|
32
|
+
"History",
|
|
33
|
+
"Storage",
|
|
34
|
+
"Response",
|
|
35
|
+
"Request",
|
|
36
|
+
"Headers"
|
|
37
|
+
]);
|
|
38
|
+
function packageOf(specifier) {
|
|
39
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) return void 0;
|
|
40
|
+
if (/^[~@]\//.test(specifier)) return void 0;
|
|
41
|
+
const parts = specifier.split("/");
|
|
42
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
43
|
+
}
|
|
44
|
+
function namespaceAlias(module) {
|
|
45
|
+
return `_${module.replace(/[^A-Za-z0-9]/g, "_")}`;
|
|
46
|
+
}
|
|
47
|
+
function componentGlobals(rules, options = {}) {
|
|
48
|
+
const {
|
|
49
|
+
available: availableList,
|
|
50
|
+
builtins = true,
|
|
51
|
+
intrinsics = true,
|
|
52
|
+
generator = "@fluixi/compiler",
|
|
53
|
+
specifier = (module) => module
|
|
54
|
+
} = options;
|
|
55
|
+
const all = [...rules];
|
|
56
|
+
if (builtins) {
|
|
57
|
+
all.push({ components: builtinComponentMap() });
|
|
58
|
+
}
|
|
59
|
+
const resolver = createComponentResolver(all);
|
|
60
|
+
const available = availableList ? new Set(availableList) : void 0;
|
|
61
|
+
const declared = [];
|
|
62
|
+
const shadowedByDom = [];
|
|
63
|
+
const unavailable = [];
|
|
64
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const name of [...resolver.names()].sort()) {
|
|
66
|
+
const target = resolver.resolve(name);
|
|
67
|
+
if (!target) continue;
|
|
68
|
+
const pkg = packageOf(target.module);
|
|
69
|
+
if (DOM_GLOBALS.has(name)) shadowedByDom.push(name);
|
|
70
|
+
else if (available && pkg && !available.has(pkg)) unavailable.push(name);
|
|
71
|
+
else {
|
|
72
|
+
declared.push(name);
|
|
73
|
+
resolved.set(name, target);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const intrinsicModules = intrinsics ? [...new Set(Object.values(INTRINSICS).map((i) => i.module))] : [];
|
|
77
|
+
const modules = [
|
|
78
|
+
.../* @__PURE__ */ new Set([...declared.map((name) => resolved.get(name).module), ...intrinsicModules])
|
|
79
|
+
].sort();
|
|
80
|
+
const imports = modules.map(
|
|
81
|
+
(m) => `import * as ${namespaceAlias(m)} from '${specifier(m)}';`
|
|
82
|
+
);
|
|
83
|
+
const lines = declared.map((name) => {
|
|
84
|
+
const target = resolved.get(name);
|
|
85
|
+
const ns = namespaceAlias(target.module);
|
|
86
|
+
return target.export === "default" ? ` const ${name}: typeof ${ns}.default;` : ` export import ${name} = ${ns}.${target.export};`;
|
|
87
|
+
});
|
|
88
|
+
const note = shadowedByDom.length > 0 ? `//
|
|
2
89
|
// Import these explicitly — lib.dom already declares the name, so an ambient
|
|
3
90
|
// declaration cannot win:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
91
|
+
` + shadowedByDom.map((n) => {
|
|
92
|
+
const module = resolver.resolve(n)?.module;
|
|
93
|
+
return `// import { ${n} } from '${module ? specifier(module) : ""}';
|
|
94
|
+
`;
|
|
95
|
+
}).join("") : "";
|
|
96
|
+
const intrinsicLines = intrinsics ? Object.entries(INTRINSICS).map(
|
|
97
|
+
([name, intrinsic]) => ` const ${name}: typeof ${namespaceAlias(intrinsic.module)}.${intrinsic.export};`
|
|
98
|
+
) : [];
|
|
99
|
+
const patternRules = rules.filter((rule) => "match" in rule).length;
|
|
100
|
+
const patternNote = patternRules > 0 ? `//
|
|
101
|
+
// ${patternRules} pattern rule${patternRules === 1 ? "" : "s"} cannot be declared:
|
|
7
102
|
// a pattern matches unboundedly many names, so there is no list to emit. Those
|
|
8
103
|
// tags still resolve at build time; declare them by hand if the editor needs them.
|
|
9
|
-
|
|
104
|
+
` : "";
|
|
105
|
+
const source = `// GENERATED by ${generator} — do not edit.
|
|
10
106
|
//
|
|
11
107
|
// The components \`resolve\` supplies without an import. This describes what the
|
|
12
108
|
// compiler already does; it does not enable it.
|
|
13
|
-
|
|
14
|
-
${
|
|
15
|
-
`)
|
|
16
|
-
`:`
|
|
17
|
-
`)+`
|
|
109
|
+
` + note + patternNote + (imports.length > 0 ? `
|
|
110
|
+
${imports.join("\n")}
|
|
111
|
+
` : "\n") + `
|
|
18
112
|
declare global {
|
|
19
|
-
${[...
|
|
20
|
-
|
|
113
|
+
${[...lines, ...intrinsicLines].join("\n")}
|
|
114
|
+
}
|
|
115
|
+
`;
|
|
116
|
+
return { source, declared, shadowedByDom, unavailable, patternRules };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/resolve/write-globals.ts
|
|
120
|
+
var GENERATED_MARKER = "GENERATED by @fluixi/compiler";
|
|
121
|
+
var DEFAULT_GLOBALS_PATH = "fluixi.d.ts";
|
|
122
|
+
function coveredByInclude(root, target) {
|
|
123
|
+
let config;
|
|
124
|
+
try {
|
|
125
|
+
const raw = readFileSync(resolvePath(root, "tsconfig.json"), "utf8");
|
|
126
|
+
config = JSON.parse(raw.replace(/^\s*\/\/.*$/gm, ""));
|
|
127
|
+
} catch {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
if (config.extends !== void 0) return void 0;
|
|
131
|
+
if (!Array.isArray(config.include)) return true;
|
|
132
|
+
const relative2 = relativePosix(root, target);
|
|
133
|
+
return config.include.some((entry) => {
|
|
134
|
+
if (typeof entry !== "string") return false;
|
|
135
|
+
const pattern = entry.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "(?:.*/)?").replace(/\*/g, "[^/]*");
|
|
136
|
+
return new RegExp(`^${pattern}(?:/.*)?$`).test(relative2);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
function relativePosix(from, to) {
|
|
140
|
+
return relative(from, to).split(sep).join("/");
|
|
141
|
+
}
|
|
142
|
+
function forTypeScript(module, outDir, root) {
|
|
143
|
+
if (!module.startsWith("/")) return module;
|
|
144
|
+
const absolute = resolvePath(root, module.slice(1));
|
|
145
|
+
let rel = relative(outDir, absolute).split(sep).join("/");
|
|
146
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
147
|
+
return rel.replace(/\.(tsx|ts|jsx|mts|cts)$/, ".js");
|
|
148
|
+
}
|
|
149
|
+
function projectDependencies(root) {
|
|
150
|
+
try {
|
|
151
|
+
const manifest = JSON.parse(readFileSync(resolvePath(root, "package.json"), "utf8"));
|
|
152
|
+
return [
|
|
153
|
+
...Object.keys(manifest.dependencies ?? {}),
|
|
154
|
+
...Object.keys(manifest.devDependencies ?? {}),
|
|
155
|
+
...Object.keys(manifest.peerDependencies ?? {})
|
|
156
|
+
];
|
|
157
|
+
} catch {
|
|
158
|
+
return void 0;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
function writeComponentGlobals(options, root) {
|
|
162
|
+
if (options.globals === false) return { status: "skipped", reason: "disabled" };
|
|
163
|
+
const rules = options.resolve ?? [];
|
|
164
|
+
const target = resolvePath(root, options.globals ?? DEFAULT_GLOBALS_PATH);
|
|
165
|
+
let existing;
|
|
166
|
+
try {
|
|
167
|
+
existing = readFileSync(target, "utf8");
|
|
168
|
+
} catch {
|
|
169
|
+
existing = void 0;
|
|
170
|
+
}
|
|
171
|
+
if (existing !== void 0 && !existing.includes(GENERATED_MARKER)) {
|
|
172
|
+
return { status: "skipped", reason: "foreign-file", path: target };
|
|
173
|
+
}
|
|
174
|
+
const { source, declared } = componentGlobals(rules, {
|
|
175
|
+
available: projectDependencies(root),
|
|
176
|
+
specifier: (module) => forTypeScript(module, dirname(target), root)
|
|
177
|
+
});
|
|
178
|
+
if (existing === source) {
|
|
179
|
+
return {
|
|
180
|
+
status: "unchanged",
|
|
181
|
+
path: target,
|
|
182
|
+
declared: declared.length,
|
|
183
|
+
warning: warnIfUnreachable(root, target)
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
187
|
+
writeFileSync(target, source);
|
|
188
|
+
return {
|
|
189
|
+
status: "written",
|
|
190
|
+
path: target,
|
|
191
|
+
declared: declared.length,
|
|
192
|
+
warning: warnIfUnreachable(root, target)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function warnIfUnreachable(root, target) {
|
|
196
|
+
if (coveredByInclude(root, target) !== false) return void 0;
|
|
197
|
+
const relative2 = relativePosix(root, target);
|
|
198
|
+
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".`;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/integrations.ts
|
|
202
|
+
import { readdirSync, readFileSync as readFileSync2 } from "node:fs";
|
|
203
|
+
import { join as _join } from "node:path";
|
|
204
|
+
async function createBabelPlugin(options = {}) {
|
|
205
|
+
let pluginModule = null;
|
|
206
|
+
try {
|
|
207
|
+
pluginModule = await import("./babel-NRW4EFTG.mjs");
|
|
208
|
+
} catch (e) {
|
|
209
|
+
console.warn("Could not load the babel front-end:", e);
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
name: "babel-fluixi-jsx",
|
|
213
|
+
plugin: pluginModule ? pluginModule.default || pluginModule : null,
|
|
214
|
+
// Provide options mapping
|
|
215
|
+
getOptions() {
|
|
216
|
+
return {
|
|
217
|
+
importSource: options.importSource || "@fluixi/jsx",
|
|
218
|
+
development: options.development || false,
|
|
219
|
+
delegateEvents: options.delegateEvents !== false,
|
|
220
|
+
...options.format ? { format: options.format } : {},
|
|
221
|
+
// Forwarded explicitly: getOptions() is an allowlist, so an option missing
|
|
222
|
+
// here is silently dropped rather than rejected.
|
|
223
|
+
...options.resolve ? { resolve: options.resolve } : {},
|
|
224
|
+
...options.templateClone !== void 0 ? { templateClone: options.templateClone } : {},
|
|
225
|
+
...options.partialTemplates !== void 0 ? { partialTemplates: options.partialTemplates } : {},
|
|
226
|
+
...options.litTag ? { litTag: options.litTag } : {},
|
|
227
|
+
...options.signalModule ? { signalModule: options.signalModule } : {},
|
|
228
|
+
...options.controlFlowModule ? { controlFlowModule: options.controlFlowModule } : {},
|
|
229
|
+
...options.routerModule ? { routerModule: options.routerModule } : {},
|
|
230
|
+
...options.reactiveModule ? { reactiveModule: options.reactiveModule } : {}
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function createTypeScriptTransformer(options = {}) {
|
|
236
|
+
const ts = tryRequire("typescript");
|
|
237
|
+
if (!ts) {
|
|
238
|
+
console.warn("TypeScript not found, transformer unavailable");
|
|
239
|
+
return (context) => (sourceFile) => sourceFile;
|
|
240
|
+
}
|
|
241
|
+
return (context) => {
|
|
242
|
+
const visitor = (node) => {
|
|
243
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
244
|
+
return transformTSJSXNode(node, options, ts);
|
|
245
|
+
}
|
|
246
|
+
return ts.visitEachChild(node, visitor, context);
|
|
247
|
+
};
|
|
248
|
+
return (sourceFile) => {
|
|
249
|
+
return ts.visitNode(sourceFile, visitor);
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
function transformTSJSXNode(node, options, ts) {
|
|
254
|
+
return node;
|
|
21
255
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
256
|
+
function tryRequire(moduleName) {
|
|
257
|
+
try {
|
|
258
|
+
return __require(moduleName);
|
|
259
|
+
} catch (e) {
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
var RETIRED_SUBPATHS = {
|
|
264
|
+
"@fluixi/core/router-next": "is now @fluixi/core/router",
|
|
265
|
+
"@fluixi/core/rx": "is gone — import signals and effects from @fluixi/reactive, or the server primitives it resolved to under node from @fluixi/core/server"
|
|
266
|
+
};
|
|
267
|
+
function createVitePlugin(options = {}) {
|
|
268
|
+
return {
|
|
269
|
+
name: "vite-fluixi-jsx",
|
|
270
|
+
enforce: "pre",
|
|
271
|
+
config() {
|
|
272
|
+
return {
|
|
273
|
+
esbuild: {
|
|
274
|
+
jsx: "automatic",
|
|
275
|
+
jsxImportSource: options.importSource || "@fluixi/jsx"
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
},
|
|
279
|
+
// Written once per build, and on dev-server start, rather than per transform: the
|
|
280
|
+
// set of resolvable names comes from config, so nothing a file does can change it.
|
|
281
|
+
configResolved(config) {
|
|
282
|
+
const outcome = writeComponentGlobals(options, config?.root ?? process.cwd());
|
|
283
|
+
if (outcome.warning) console.warn(outcome.warning);
|
|
284
|
+
},
|
|
285
|
+
// A subpath we retired resolves to nothing, and the bundler reports that as
|
|
286
|
+
// `Missing "./x" specifier`, which names neither the replacement nor the file
|
|
287
|
+
// that asked. Answer it here, where the rename is known.
|
|
288
|
+
resolveId(id, importer) {
|
|
289
|
+
const moved = RETIRED_SUBPATHS[id];
|
|
290
|
+
if (!moved) return null;
|
|
291
|
+
throw new Error(
|
|
292
|
+
`[fluixi] ${id} ${moved}` + (importer ? `
|
|
293
|
+
imported by ${importer}` : "")
|
|
294
|
+
);
|
|
295
|
+
},
|
|
296
|
+
async transform(code, id) {
|
|
297
|
+
if (!/\.(jsx|tsx|ts)$/i.test(id)) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
if (!options.babel) return compileModule(code, id, options);
|
|
301
|
+
const babelPlugin = await createBabelPlugin(options);
|
|
302
|
+
try {
|
|
303
|
+
const babel = await import("@babel/core").catch(() => null);
|
|
304
|
+
if (!babel) {
|
|
305
|
+
throw new Error(
|
|
306
|
+
`[fluixi] @babel/core is required to compile ${id} but could not be loaded. Install it alongside @fluixi/compiler.`
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
const isTSX = /\.tsx$/.test(id);
|
|
310
|
+
const isTS = /\.ts$/.test(id);
|
|
311
|
+
const presets = [];
|
|
312
|
+
const plugins = [];
|
|
313
|
+
if (isTSX || isTS) {
|
|
314
|
+
const tsPreset = await import("@babel/preset-typescript").then((m) => m.default || m).catch(() => null);
|
|
315
|
+
if (tsPreset) {
|
|
316
|
+
presets.push([
|
|
317
|
+
tsPreset,
|
|
318
|
+
{
|
|
319
|
+
isTSX,
|
|
320
|
+
allExtensions: true,
|
|
321
|
+
// Important: preserve JSX so our plugin can transform it
|
|
322
|
+
jsxPragma: "jsx",
|
|
323
|
+
jsxPragmaFrag: "Fragment",
|
|
324
|
+
onlyRemoveTypeImports: true
|
|
325
|
+
}
|
|
326
|
+
]);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (babelPlugin && babelPlugin.plugin) {
|
|
330
|
+
plugins.push([babelPlugin.plugin, babelPlugin.getOptions()]);
|
|
331
|
+
} else {
|
|
332
|
+
console.warn("[createVitePlugin] custom babel plugin not found");
|
|
333
|
+
}
|
|
334
|
+
const result = await babel.transformAsync(code, {
|
|
335
|
+
filename: id,
|
|
336
|
+
configFile: false,
|
|
337
|
+
babelrc: false,
|
|
338
|
+
presets,
|
|
339
|
+
plugins,
|
|
340
|
+
sourceMaps: options.sourceMaps !== false
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
code: result?.code || code,
|
|
344
|
+
map: result?.map
|
|
345
|
+
};
|
|
346
|
+
} catch (e) {
|
|
347
|
+
throw e;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function marks(options, id) {
|
|
353
|
+
if (options.sourceLocations !== true) return false;
|
|
354
|
+
if (options.sourceLocationsExternal) return true;
|
|
355
|
+
if (!id || id.includes("/node_modules/")) return false;
|
|
356
|
+
const root = options.sourceRoot;
|
|
357
|
+
if (!root) return true;
|
|
358
|
+
const base = root.endsWith("/") ? root : `${root}/`;
|
|
359
|
+
return id.startsWith(base);
|
|
360
|
+
}
|
|
361
|
+
function transformOptions(options, id) {
|
|
362
|
+
return {
|
|
363
|
+
resolve: options.resolve,
|
|
364
|
+
litTag: options.litTag,
|
|
365
|
+
sourceLocations: marks(options, id),
|
|
366
|
+
sourceRoot: options.sourceRoot,
|
|
367
|
+
templateClone: options.templateClone,
|
|
368
|
+
partialTemplates: options.partialTemplates,
|
|
369
|
+
runtimeModule: options.signalModule,
|
|
370
|
+
controlFlowModule: options.controlFlowModule,
|
|
371
|
+
routerModule: options.routerModule,
|
|
372
|
+
reactiveModule: options.reactiveModule,
|
|
373
|
+
propsDestructure: options.propsDestructure
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
async function rewriteProps(code, id, options) {
|
|
377
|
+
if (options.propsDestructure === false) return code;
|
|
378
|
+
const { transformProps } = await import("./transform-BT4MMASR.mjs");
|
|
379
|
+
const result = transformProps(code, id);
|
|
380
|
+
reportDiagnostics({ propsDiagnostics: result.diagnostics }, id);
|
|
381
|
+
return result.rewritten > 0 ? result.code : code;
|
|
382
|
+
}
|
|
383
|
+
var reported = /* @__PURE__ */ new Set();
|
|
384
|
+
function reportDiagnostics(result, id) {
|
|
385
|
+
const r = result;
|
|
386
|
+
const say = (message) => {
|
|
387
|
+
const key = `${id}\0${message}`;
|
|
388
|
+
if (reported.has(key)) return;
|
|
389
|
+
reported.add(key);
|
|
390
|
+
console.warn(`[fluixi] ${id}: ${message}`);
|
|
391
|
+
};
|
|
392
|
+
for (const d of r?.unresolvedDiagnostics ?? []) say(d.message);
|
|
393
|
+
for (const d of r?.loadDiagnostics ?? []) say(d.message);
|
|
394
|
+
for (const d of r?.intrinsicDiagnostics ?? []) say(d.message);
|
|
395
|
+
for (const d of r?.propsDiagnostics ?? []) {
|
|
396
|
+
say(`\`${d.name}\` was left destructured: ${d.message}. It reads once instead of tracking.`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
async function compileModule(code, id, options) {
|
|
400
|
+
if (!options.babel) {
|
|
401
|
+
const { transformTemplates } = await import("./transform-BT4MMASR.mjs");
|
|
402
|
+
const result2 = transformTemplates(code, id, transformOptions(options, id));
|
|
403
|
+
reportDiagnostics(result2, id);
|
|
404
|
+
return result2;
|
|
405
|
+
}
|
|
406
|
+
const source = await rewriteProps(code, id, options);
|
|
407
|
+
const babel = await import("@babel/core").catch(() => null);
|
|
408
|
+
const plugin = await createBabelPlugin(options);
|
|
409
|
+
if (!babel || !plugin.plugin) {
|
|
410
|
+
throw new Error(
|
|
411
|
+
`[fluixi] babel: true needs @babel/core, which could not be loaded for ${id}. Install it, or drop the option to use the built-in compiler.`
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
const result = await babel.transformAsync(source, {
|
|
415
|
+
filename: id,
|
|
416
|
+
configFile: false,
|
|
417
|
+
babelrc: false,
|
|
418
|
+
plugins: [[plugin.plugin, plugin.getOptions()]],
|
|
419
|
+
sourceMaps: options.sourceMaps !== false
|
|
420
|
+
});
|
|
421
|
+
return result?.code ? { code: result.code, map: result.map } : null;
|
|
422
|
+
}
|
|
423
|
+
function createWebpackLoader(options = {}) {
|
|
424
|
+
return async function(source) {
|
|
425
|
+
const callback = this.async();
|
|
426
|
+
compileModule(source, this.resourcePath, options).then((result) => {
|
|
427
|
+
callback(null, result?.code, result?.map);
|
|
428
|
+
}).catch((err) => {
|
|
429
|
+
callback(err);
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
function createRollupPlugin(options = {}) {
|
|
434
|
+
return {
|
|
435
|
+
name: "rollup-fluixi-jsx",
|
|
436
|
+
async transform(code, id) {
|
|
437
|
+
if (!/\.[jt]sx?$/.test(id)) return null;
|
|
438
|
+
return compileModule(code, id, options);
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function createESBuildPlugin(options = {}) {
|
|
443
|
+
return {
|
|
444
|
+
name: "esbuild-fluixi-jsx",
|
|
445
|
+
setup(build) {
|
|
446
|
+
build.onLoad({ filter: /\.[jt]sx?$/ }, async (args) => {
|
|
447
|
+
const { readFileSync: readFileSync3 } = await import("node:fs");
|
|
448
|
+
const source = readFileSync3(args.path, "utf8");
|
|
449
|
+
try {
|
|
450
|
+
const result = await compileModule(source, args.path, options);
|
|
451
|
+
return {
|
|
452
|
+
contents: result?.code ?? source,
|
|
453
|
+
loader: args.path.endsWith("x") ? "tsx" : "ts"
|
|
454
|
+
};
|
|
455
|
+
} catch (e) {
|
|
456
|
+
return {
|
|
457
|
+
errors: [
|
|
458
|
+
{
|
|
459
|
+
text: `Transform error: ${e}`
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
var SERVER_FNS_VMOD = "virtual:fluixi-server-fns";
|
|
469
|
+
function findServerFnModules(dir, out = []) {
|
|
470
|
+
let entries;
|
|
471
|
+
try {
|
|
472
|
+
entries = readdirSync(dir, { withFileTypes: true });
|
|
473
|
+
} catch {
|
|
474
|
+
return out;
|
|
475
|
+
}
|
|
476
|
+
for (const e of entries) {
|
|
477
|
+
if (e.name === "node_modules" || e.name === "dist" || e.name.startsWith(".")) continue;
|
|
478
|
+
const full = _join(dir, e.name);
|
|
479
|
+
if (e.isDirectory()) findServerFnModules(full, out);
|
|
480
|
+
else if (/\.[jt]sx?$/.test(e.name)) {
|
|
481
|
+
try {
|
|
482
|
+
if (readFileSync2(full, "utf8").includes("use server")) out.push(full);
|
|
483
|
+
} catch {
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
return out;
|
|
488
|
+
}
|
|
489
|
+
function serverFunctionsVitePlugin(options = {}) {
|
|
490
|
+
let root = process.cwd();
|
|
491
|
+
return {
|
|
492
|
+
name: "fluixi-server-functions",
|
|
493
|
+
enforce: "pre",
|
|
494
|
+
configResolved(config) {
|
|
495
|
+
root = config.root || root;
|
|
496
|
+
},
|
|
497
|
+
resolveId(id) {
|
|
498
|
+
return id === SERVER_FNS_VMOD || id === "@fluixi/start/server-fns" ? "\0" + SERVER_FNS_VMOD : null;
|
|
499
|
+
},
|
|
500
|
+
load(id) {
|
|
501
|
+
if (id !== "\0" + SERVER_FNS_VMOD) return null;
|
|
502
|
+
const mods = findServerFnModules(_join(root, "src"));
|
|
503
|
+
const setup = `import '@fluixi/start/server-fn-setup';
|
|
504
|
+
`;
|
|
505
|
+
const imports = mods.map((m) => `import ${JSON.stringify(m)};`).join("\n");
|
|
506
|
+
const dispatcher = `
|
|
26
507
|
export { isServerFnRequest, handleServerFn } from '@fluixi/start/server-fn';
|
|
27
|
-
|
|
508
|
+
`;
|
|
509
|
+
return setup + imports + dispatcher;
|
|
510
|
+
},
|
|
511
|
+
async transform(code, id, opts) {
|
|
512
|
+
if (!/\.[jt]sx?$/.test(id)) return null;
|
|
513
|
+
if (!code.includes("use server")) return null;
|
|
514
|
+
const args = { ssr: !!opts?.ssr, filename: id, root };
|
|
515
|
+
if (options.babel) {
|
|
516
|
+
const { transformServerFunctions } = await import("./server-functions-V6D6DRIA.mjs");
|
|
517
|
+
return transformServerFunctions(code, args);
|
|
518
|
+
}
|
|
519
|
+
const { transformServerFns } = await import("./server-fns-4ZXN6DYU.mjs");
|
|
520
|
+
return transformServerFns(code, args);
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
var integrations_default = {
|
|
525
|
+
createBabelPlugin,
|
|
526
|
+
createTypeScriptTransformer,
|
|
527
|
+
createVitePlugin,
|
|
528
|
+
createWebpackLoader,
|
|
529
|
+
createRollupPlugin,
|
|
530
|
+
createESBuildPlugin
|
|
531
|
+
};
|
|
532
|
+
export {
|
|
533
|
+
createBabelPlugin,
|
|
534
|
+
createESBuildPlugin,
|
|
535
|
+
createRollupPlugin,
|
|
536
|
+
createTypeScriptTransformer,
|
|
537
|
+
createVitePlugin,
|
|
538
|
+
createWebpackLoader,
|
|
539
|
+
integrations_default as default,
|
|
540
|
+
serverFunctionsVitePlugin
|
|
541
|
+
};
|
package/dist/ir/nodes.cjs
CHANGED
|
@@ -1 +1,18 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/ir/nodes.ts
|
|
17
|
+
var nodes_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(nodes_exports);
|