@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 +1,110 @@
|
|
|
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/frontend/babel/server-functions.ts
|
|
21
|
+
var server_functions_exports = {};
|
|
22
|
+
__export(server_functions_exports, {
|
|
23
|
+
transformServerFunctions: () => transformServerFunctions
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(server_functions_exports);
|
|
26
|
+
var import_core = require("@babel/core");
|
|
27
|
+
|
|
28
|
+
// src/transform/server-fn-id.ts
|
|
29
|
+
function hash(s) {
|
|
30
|
+
let h = 5381;
|
|
31
|
+
for (let i = 0; i < s.length; i++) h = h * 33 ^ s.charCodeAt(i);
|
|
32
|
+
return (h >>> 0).toString(16);
|
|
33
|
+
}
|
|
34
|
+
function serverFnId(filename, root, index) {
|
|
35
|
+
const rel = (filename || "unknown").replace(root ? root + "/" : "", "");
|
|
36
|
+
return `${hash(rel)}:${index}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/frontend/babel/server-functions.ts
|
|
40
|
+
var RUNTIME = "@fluixi/start/server-fn";
|
|
41
|
+
function serverFunctionsBabelPlugin({ types: t }) {
|
|
42
|
+
return {
|
|
43
|
+
name: "fluixi-server-functions",
|
|
44
|
+
visitor: {
|
|
45
|
+
Program: {
|
|
46
|
+
enter(_path, state) {
|
|
47
|
+
state.fxIndex = 0;
|
|
48
|
+
state.fxUsed = null;
|
|
49
|
+
},
|
|
50
|
+
exit(path, state) {
|
|
51
|
+
if (!state.fxUsed) return;
|
|
52
|
+
path.unshiftContainer(
|
|
53
|
+
"body",
|
|
54
|
+
t.importDeclaration(
|
|
55
|
+
[t.importSpecifier(t.identifier(state.fxUsed), t.identifier(state.fxUsed))],
|
|
56
|
+
t.stringLiteral(state.opts.runtimeModule || RUNTIME)
|
|
57
|
+
)
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression": (path, state) => {
|
|
62
|
+
const body = path.node.body;
|
|
63
|
+
if (!t.isBlockStatement(body)) return;
|
|
64
|
+
const dirs = body.directives || [];
|
|
65
|
+
const di = dirs.findIndex((d) => d.value.value === "use server");
|
|
66
|
+
if (di < 0) return;
|
|
67
|
+
body.directives.splice(di, 1);
|
|
68
|
+
const id = serverFnId(
|
|
69
|
+
state.opts.filename || state.filename || "unknown",
|
|
70
|
+
state.opts.root,
|
|
71
|
+
state.fxIndex++
|
|
72
|
+
);
|
|
73
|
+
const ssr = !!state.opts.ssr;
|
|
74
|
+
const helper = ssr ? "$$registerServerFn" : "$$createServerReference";
|
|
75
|
+
state.fxUsed = helper;
|
|
76
|
+
const replacement = ssr ? t.callExpression(t.identifier(helper), [
|
|
77
|
+
t.stringLiteral(id),
|
|
78
|
+
path.isFunctionDeclaration() ? t.functionExpression(
|
|
79
|
+
null,
|
|
80
|
+
path.node.params,
|
|
81
|
+
body,
|
|
82
|
+
path.node.generator,
|
|
83
|
+
path.node.async
|
|
84
|
+
) : path.node
|
|
85
|
+
]) : t.callExpression(t.identifier(helper), [t.stringLiteral(id)]);
|
|
86
|
+
if (path.isFunctionDeclaration()) {
|
|
87
|
+
path.replaceWith(
|
|
88
|
+
t.variableDeclaration("const", [t.variableDeclarator(path.node.id, replacement)])
|
|
89
|
+
);
|
|
90
|
+
} else {
|
|
91
|
+
path.replaceWith(replacement);
|
|
92
|
+
}
|
|
93
|
+
path.skip();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function transformServerFunctions(code, opts) {
|
|
99
|
+
if (!code.includes("use server")) return null;
|
|
100
|
+
const result = (0, import_core.transformSync)(code, {
|
|
101
|
+
filename: opts.filename,
|
|
102
|
+
configFile: false,
|
|
103
|
+
babelrc: false,
|
|
104
|
+
sourceMaps: true,
|
|
105
|
+
parserOpts: { plugins: ["typescript", "jsx"] },
|
|
106
|
+
plugins: [[serverFunctionsBabelPlugin, opts]]
|
|
107
|
+
});
|
|
108
|
+
if (!result?.code) return null;
|
|
109
|
+
return { code: result.code, map: result.map };
|
|
110
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ServerFnTransformOptions {
|
|
2
|
+
ssr: boolean;
|
|
3
|
+
filename: string;
|
|
4
|
+
root?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Returns `{ code, map }`, or null when the source has no `"use server"`. */
|
|
7
|
+
export declare function transformServerFunctions(code: string, opts: ServerFnTransformOptions): {
|
|
8
|
+
code: string;
|
|
9
|
+
map: any;
|
|
10
|
+
} | null;
|
|
@@ -1 +1,89 @@
|
|
|
1
|
-
|
|
1
|
+
// src/frontend/babel/server-functions.ts
|
|
2
|
+
import { transformSync } from "@babel/core";
|
|
3
|
+
|
|
4
|
+
// src/transform/server-fn-id.ts
|
|
5
|
+
function hash(s) {
|
|
6
|
+
let h = 5381;
|
|
7
|
+
for (let i = 0; i < s.length; i++) h = h * 33 ^ s.charCodeAt(i);
|
|
8
|
+
return (h >>> 0).toString(16);
|
|
9
|
+
}
|
|
10
|
+
function serverFnId(filename, root, index) {
|
|
11
|
+
const rel = (filename || "unknown").replace(root ? root + "/" : "", "");
|
|
12
|
+
return `${hash(rel)}:${index}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// src/frontend/babel/server-functions.ts
|
|
16
|
+
var RUNTIME = "@fluixi/start/server-fn";
|
|
17
|
+
function serverFunctionsBabelPlugin({ types: t }) {
|
|
18
|
+
return {
|
|
19
|
+
name: "fluixi-server-functions",
|
|
20
|
+
visitor: {
|
|
21
|
+
Program: {
|
|
22
|
+
enter(_path, state) {
|
|
23
|
+
state.fxIndex = 0;
|
|
24
|
+
state.fxUsed = null;
|
|
25
|
+
},
|
|
26
|
+
exit(path, state) {
|
|
27
|
+
if (!state.fxUsed) return;
|
|
28
|
+
path.unshiftContainer(
|
|
29
|
+
"body",
|
|
30
|
+
t.importDeclaration(
|
|
31
|
+
[t.importSpecifier(t.identifier(state.fxUsed), t.identifier(state.fxUsed))],
|
|
32
|
+
t.stringLiteral(state.opts.runtimeModule || RUNTIME)
|
|
33
|
+
)
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"FunctionDeclaration|FunctionExpression|ArrowFunctionExpression": (path, state) => {
|
|
38
|
+
const body = path.node.body;
|
|
39
|
+
if (!t.isBlockStatement(body)) return;
|
|
40
|
+
const dirs = body.directives || [];
|
|
41
|
+
const di = dirs.findIndex((d) => d.value.value === "use server");
|
|
42
|
+
if (di < 0) return;
|
|
43
|
+
body.directives.splice(di, 1);
|
|
44
|
+
const id = serverFnId(
|
|
45
|
+
state.opts.filename || state.filename || "unknown",
|
|
46
|
+
state.opts.root,
|
|
47
|
+
state.fxIndex++
|
|
48
|
+
);
|
|
49
|
+
const ssr = !!state.opts.ssr;
|
|
50
|
+
const helper = ssr ? "$$registerServerFn" : "$$createServerReference";
|
|
51
|
+
state.fxUsed = helper;
|
|
52
|
+
const replacement = ssr ? t.callExpression(t.identifier(helper), [
|
|
53
|
+
t.stringLiteral(id),
|
|
54
|
+
path.isFunctionDeclaration() ? t.functionExpression(
|
|
55
|
+
null,
|
|
56
|
+
path.node.params,
|
|
57
|
+
body,
|
|
58
|
+
path.node.generator,
|
|
59
|
+
path.node.async
|
|
60
|
+
) : path.node
|
|
61
|
+
]) : t.callExpression(t.identifier(helper), [t.stringLiteral(id)]);
|
|
62
|
+
if (path.isFunctionDeclaration()) {
|
|
63
|
+
path.replaceWith(
|
|
64
|
+
t.variableDeclaration("const", [t.variableDeclarator(path.node.id, replacement)])
|
|
65
|
+
);
|
|
66
|
+
} else {
|
|
67
|
+
path.replaceWith(replacement);
|
|
68
|
+
}
|
|
69
|
+
path.skip();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function transformServerFunctions(code, opts) {
|
|
75
|
+
if (!code.includes("use server")) return null;
|
|
76
|
+
const result = transformSync(code, {
|
|
77
|
+
filename: opts.filename,
|
|
78
|
+
configFile: false,
|
|
79
|
+
babelrc: false,
|
|
80
|
+
sourceMaps: true,
|
|
81
|
+
parserOpts: { plugins: ["typescript", "jsx"] },
|
|
82
|
+
plugins: [[serverFunctionsBabelPlugin, opts]]
|
|
83
|
+
});
|
|
84
|
+
if (!result?.code) return null;
|
|
85
|
+
return { code: result.code, map: result.map };
|
|
86
|
+
}
|
|
87
|
+
export {
|
|
88
|
+
transformServerFunctions
|
|
89
|
+
};
|
|
@@ -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/frontend/babel/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { types as t } from '@babel/core';
|
|
2
|
+
export type JSXElement = t.JSXElement;
|
|
3
|
+
export type JSXFragment = t.JSXFragment;
|
|
4
|
+
export type JSXExpressionContainer = t.JSXExpressionContainer;
|
|
5
|
+
export type JSXSpreadAttribute = t.JSXSpreadAttribute;
|
|
6
|
+
export type JSXAttribute = t.JSXAttribute;
|
|
7
|
+
export type JSXText = t.JSXText;
|
|
8
|
+
export type JSXSpreadChild = t.JSXSpreadChild;
|
|
9
|
+
export type JSXEmptyExpression = t.JSXEmptyExpression;
|
|
10
|
+
export type Expression = t.Expression;
|
|
11
|
+
export type Identifier = t.Identifier;
|
|
12
|
+
export type StringLiteral = t.StringLiteral;
|
|
13
|
+
export type CallExpression = t.CallExpression;
|
|
14
|
+
export type MemberExpression = t.MemberExpression;
|
|
15
|
+
export type ObjectProperty = t.ObjectProperty;
|
|
16
|
+
export type ObjectExpression = t.ObjectExpression;
|
|
17
|
+
export type ArrowFunctionExpression = t.ArrowFunctionExpression;
|
|
18
|
+
export type Program = t.Program;
|
|
19
|
+
export type JSXOpeningElement = t.JSXOpeningElement;
|
|
20
|
+
export type JSXClosingElement = t.JSXClosingElement;
|
|
21
|
+
export type JSXIdentifier = t.JSXIdentifier;
|
|
22
|
+
export type JSXMemberExpression = t.JSXMemberExpression;
|
|
23
|
+
export type JSXNamespacedName = t.JSXNamespacedName;
|
|
24
|
+
export interface TransformState {
|
|
25
|
+
opts: {
|
|
26
|
+
runtime: 'automatic' | 'classic';
|
|
27
|
+
importSource: string;
|
|
28
|
+
development: boolean;
|
|
29
|
+
pragma: string;
|
|
30
|
+
pragmaFrag: string;
|
|
31
|
+
signalDetection: boolean;
|
|
32
|
+
};
|
|
33
|
+
}
|
package/dist/frontend/types.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/frontend/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CompilerOptions } from '../options.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* A front-end adapter parses source (TS/JSX) and runs the Fluixi JSX transform
|
|
4
|
+
* for one module, producing code (and a source map). Front-ends are the swap
|
|
5
|
+
* point at the *parsing* end of the pipeline, mirroring CodegenBackend at the
|
|
6
|
+
* emit end:
|
|
7
|
+
*
|
|
8
|
+
* FrontEnd (babel now, swc later) -> IR -> CodegenBackend -> code
|
|
9
|
+
*
|
|
10
|
+
* The babel front-end (frontend/babel) is the reference implementation. An SWC
|
|
11
|
+
* front-end would implement this same interface (see the compiler README for the
|
|
12
|
+
* feasibility notes).
|
|
13
|
+
*/
|
|
14
|
+
export interface FrontEndResult {
|
|
15
|
+
code: string;
|
|
16
|
+
map?: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface FrontEnd {
|
|
19
|
+
/** stable id, e.g. 'babel' | 'swc' */
|
|
20
|
+
name: string;
|
|
21
|
+
/** file extensions this front-end can handle, e.g. ['.tsx', '.jsx', '.ts'] */
|
|
22
|
+
extensions: readonly string[];
|
|
23
|
+
/** parse + transform a single module */
|
|
24
|
+
transform(code: string, filename: string, options: CompilerOptions): FrontEndResult | Promise<FrontEndResult>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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/frontend/vocabulary.ts
|
|
21
|
+
var vocabulary_exports = {};
|
|
22
|
+
__export(vocabulary_exports, {
|
|
23
|
+
DIALECT_DIVERGENT: () => DIALECT_DIVERGENT,
|
|
24
|
+
ESTREE_ALIASES: () => ESTREE_ALIASES,
|
|
25
|
+
JSX_NODES: () => JSX_NODES,
|
|
26
|
+
PARSER_AGNOSTIC_DIRS: () => PARSER_AGNOSTIC_DIRS,
|
|
27
|
+
SHARED_NODES: () => SHARED_NODES,
|
|
28
|
+
VOCABULARY: () => VOCABULARY
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(vocabulary_exports);
|
|
31
|
+
var DIALECT_DIVERGENT = {
|
|
32
|
+
StringLiteral: { estree: "Literal" },
|
|
33
|
+
NumericLiteral: { estree: "Literal" },
|
|
34
|
+
BooleanLiteral: { estree: "Literal" },
|
|
35
|
+
NullLiteral: { estree: "Literal" },
|
|
36
|
+
BigIntLiteral: { estree: "Literal" },
|
|
37
|
+
RegExpLiteral: { estree: "Literal" },
|
|
38
|
+
ObjectProperty: { estree: "Property" }
|
|
39
|
+
};
|
|
40
|
+
var ESTREE_ALIASES = {
|
|
41
|
+
Literal: { note: "ESTree collapses the babel literal family into this" },
|
|
42
|
+
Property: { note: "ESTree spelling of ObjectProperty" }
|
|
43
|
+
};
|
|
44
|
+
var JSX_NODES = {
|
|
45
|
+
JSXElement: {},
|
|
46
|
+
JSXFragment: {},
|
|
47
|
+
JSXOpeningElement: {},
|
|
48
|
+
JSXAttribute: {},
|
|
49
|
+
JSXSpreadAttribute: {},
|
|
50
|
+
JSXSpreadChild: {},
|
|
51
|
+
JSXExpressionContainer: {},
|
|
52
|
+
JSXEmptyExpression: { note: "an empty container, and a JSX comment" },
|
|
53
|
+
JSXIdentifier: {},
|
|
54
|
+
JSXMemberExpression: { note: "a dotted tag, read through code()" },
|
|
55
|
+
JSXNamespacedName: { note: "carries the directive prefixes: use:, on:, class:" },
|
|
56
|
+
JSXText: {}
|
|
57
|
+
};
|
|
58
|
+
var SHARED_NODES = {
|
|
59
|
+
ArrayExpression: {},
|
|
60
|
+
ArrayPattern: {},
|
|
61
|
+
ArrowFunctionExpression: {},
|
|
62
|
+
AssignmentExpression: {},
|
|
63
|
+
AssignmentPattern: {},
|
|
64
|
+
BinaryExpression: {},
|
|
65
|
+
BlockStatement: {},
|
|
66
|
+
CallExpression: {},
|
|
67
|
+
CatchClause: { note: "introduces a binding, so scope tracking has to see it" },
|
|
68
|
+
ClassDeclaration: {},
|
|
69
|
+
ClassExpression: {},
|
|
70
|
+
ConditionalExpression: {},
|
|
71
|
+
ExportDefaultDeclaration: {},
|
|
72
|
+
ExportNamedDeclaration: {},
|
|
73
|
+
FunctionDeclaration: {},
|
|
74
|
+
FunctionExpression: {},
|
|
75
|
+
Identifier: {},
|
|
76
|
+
ImportDeclaration: {},
|
|
77
|
+
ImportDefaultSpecifier: {},
|
|
78
|
+
ImportNamespaceSpecifier: {},
|
|
79
|
+
ImportSpecifier: {},
|
|
80
|
+
LogicalExpression: {},
|
|
81
|
+
MemberExpression: {},
|
|
82
|
+
ObjectExpression: {},
|
|
83
|
+
ObjectPattern: {},
|
|
84
|
+
RestElement: {},
|
|
85
|
+
SpreadElement: {},
|
|
86
|
+
TaggedTemplateExpression: { note: "html`` and svg``" },
|
|
87
|
+
TemplateLiteral: {},
|
|
88
|
+
UnaryExpression: {},
|
|
89
|
+
UpdateExpression: {},
|
|
90
|
+
VariableDeclarator: {}
|
|
91
|
+
};
|
|
92
|
+
var VOCABULARY = {
|
|
93
|
+
...DIALECT_DIVERGENT,
|
|
94
|
+
...ESTREE_ALIASES,
|
|
95
|
+
...JSX_NODES,
|
|
96
|
+
...SHARED_NODES
|
|
97
|
+
};
|
|
98
|
+
var PARSER_AGNOSTIC_DIRS = ["lower", "analyze", "optimize", "resolve", "codegen"];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The node-type names the parser-agnostic layer is allowed to branch on.
|
|
3
|
+
*
|
|
4
|
+
* `lower/`, `analyze/`, `optimize/`, `resolve/` and `codegen/` never import a
|
|
5
|
+
* parser. They declare `interface Node { type: string }`, read `node.type`, and
|
|
6
|
+
* ask the caller for an expression's source through `code(node)`. That makes the
|
|
7
|
+
* layer parser-agnostic in architecture while leaving it coupled to one parser's
|
|
8
|
+
* *vocabulary*: the spelling of those type names, which differs by dialect.
|
|
9
|
+
*
|
|
10
|
+
* Until this file existed the vocabulary was convention. Nothing wrote it down,
|
|
11
|
+
* so a second front-end had no definition of done and the current one could add a
|
|
12
|
+
* name without anyone noticing. It has grown from the 35 names counted in
|
|
13
|
+
* COMPILER-AUDIT §14.3 to the 53 below.
|
|
14
|
+
*
|
|
15
|
+
* ## Dialects
|
|
16
|
+
*
|
|
17
|
+
* Babel is the reference spelling because the babel front-end is the reference
|
|
18
|
+
* implementation. ESTree (acorn, oxc) collapses the literal family into `Literal`
|
|
19
|
+
* and calls an object entry `Property`; SWC renames more widely and carries
|
|
20
|
+
* `span` instead of `loc`. A second front-end is therefore an adapter: rename at
|
|
21
|
+
* the boundary and supply `code(node)`, which a span-carrying parser does better
|
|
22
|
+
* than babel, since it can slice the original text instead of reprinting it.
|
|
23
|
+
*
|
|
24
|
+
* ## The span convention
|
|
25
|
+
*
|
|
26
|
+
* Positions are read as `node.loc.start.line` (1-based) and
|
|
27
|
+
* `node.loc.start.column` (0-based). Nothing in this layer reads byte offsets;
|
|
28
|
+
* source text arrives through `code(node)`, so a front-end is free to back that
|
|
29
|
+
* with offsets, a printer, or anything else.
|
|
30
|
+
*
|
|
31
|
+
* ## What this file does not cover
|
|
32
|
+
*
|
|
33
|
+
* Names, not field reads. `vocabulary.spec.ts` fails on a name that is not listed
|
|
34
|
+
* here, which catches a front-end porting gap at the point it is introduced. It
|
|
35
|
+
* cannot see that some branch started reading `node.optional`, and adding that
|
|
36
|
+
* would mean tracking property access through the narrowed type, which the spec
|
|
37
|
+
* deliberately does not attempt.
|
|
38
|
+
*/
|
|
39
|
+
/** Every front-end produces nodes of at least this shape. */
|
|
40
|
+
export interface Node {
|
|
41
|
+
type: string;
|
|
42
|
+
loc?: {
|
|
43
|
+
start?: {
|
|
44
|
+
line?: number;
|
|
45
|
+
column?: number;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
[field: string]: unknown;
|
|
49
|
+
}
|
|
50
|
+
export interface VocabularyEntry {
|
|
51
|
+
/** The ESTree spelling, when acorn and oxc disagree with babel. */
|
|
52
|
+
estree?: string;
|
|
53
|
+
/** Why the name is here, where that is not obvious from the name. */
|
|
54
|
+
note?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Names whose ESTree spelling differs. These are the porting hazards: a front-end
|
|
58
|
+
* swap that misses one produces a layer that silently stops recognising a
|
|
59
|
+
* construct rather than failing.
|
|
60
|
+
*/
|
|
61
|
+
export declare const DIALECT_DIVERGENT: Record<string, VocabularyEntry>;
|
|
62
|
+
/**
|
|
63
|
+
* The ESTree spellings the layer already accepts alongside the babel ones.
|
|
64
|
+
*
|
|
65
|
+
* Three sites handle both today (`lower/jsx.ts`, `analyze/props-destructure.ts`,
|
|
66
|
+
* `analyze/expr-shape.ts`) and three do not: `analyze/static-graph.ts` tests
|
|
67
|
+
* `StringLiteral` at one site and `ObjectProperty` at two, with no `Literal` or
|
|
68
|
+
* `Property` branch beside them. Those three are the known gap, and they are why
|
|
69
|
+
* this file lists the pairs rather than assuming the layer is already portable.
|
|
70
|
+
*/
|
|
71
|
+
export declare const ESTREE_ALIASES: Record<string, VocabularyEntry>;
|
|
72
|
+
/** JSX. acorn-jsx keeps babel's names; SWC does not. */
|
|
73
|
+
export declare const JSX_NODES: Record<string, VocabularyEntry>;
|
|
74
|
+
/** Names spelled the same in babel and ESTree. */
|
|
75
|
+
export declare const SHARED_NODES: Record<string, VocabularyEntry>;
|
|
76
|
+
/** Every name the parser-agnostic layer may branch on. */
|
|
77
|
+
export declare const VOCABULARY: Record<string, VocabularyEntry>;
|
|
78
|
+
/** The directories that must not branch on anything outside `VOCABULARY`. */
|
|
79
|
+
export declare const PARSER_AGNOSTIC_DIRS: readonly ["lower", "analyze", "optimize", "resolve", "codegen"];
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The node-type names the parser-agnostic layer is allowed to branch on.
|
|
3
|
+
*
|
|
4
|
+
* `lower/`, `analyze/`, `optimize/`, `resolve/` and `codegen/` never import a
|
|
5
|
+
* parser. They declare `interface Node { type: string }`, read `node.type`, and
|
|
6
|
+
* ask the caller for an expression's source through `code(node)`. That makes the
|
|
7
|
+
* layer parser-agnostic in architecture while leaving it coupled to one parser's
|
|
8
|
+
* *vocabulary*: the spelling of those type names, which differs by dialect.
|
|
9
|
+
*
|
|
10
|
+
* Until this file existed the vocabulary was convention. Nothing wrote it down,
|
|
11
|
+
* so a second front-end had no definition of done and the current one could add a
|
|
12
|
+
* name without anyone noticing. It has grown from the 35 names counted in
|
|
13
|
+
* COMPILER-AUDIT §14.3 to the 53 below.
|
|
14
|
+
*
|
|
15
|
+
* ## Dialects
|
|
16
|
+
*
|
|
17
|
+
* Babel is the reference spelling because the babel front-end is the reference
|
|
18
|
+
* implementation. ESTree (acorn, oxc) collapses the literal family into `Literal`
|
|
19
|
+
* and calls an object entry `Property`; SWC renames more widely and carries
|
|
20
|
+
* `span` instead of `loc`. A second front-end is therefore an adapter: rename at
|
|
21
|
+
* the boundary and supply `code(node)`, which a span-carrying parser does better
|
|
22
|
+
* than babel, since it can slice the original text instead of reprinting it.
|
|
23
|
+
*
|
|
24
|
+
* ## The span convention
|
|
25
|
+
*
|
|
26
|
+
* Positions are read as `node.loc.start.line` (1-based) and
|
|
27
|
+
* `node.loc.start.column` (0-based). Nothing in this layer reads byte offsets;
|
|
28
|
+
* source text arrives through `code(node)`, so a front-end is free to back that
|
|
29
|
+
* with offsets, a printer, or anything else.
|
|
30
|
+
*
|
|
31
|
+
* ## What this file does not cover
|
|
32
|
+
*
|
|
33
|
+
* Names, not field reads. `vocabulary.spec.ts` fails on a name that is not listed
|
|
34
|
+
* here, which catches a front-end porting gap at the point it is introduced. It
|
|
35
|
+
* cannot see that some branch started reading `node.optional`, and adding that
|
|
36
|
+
* would mean tracking property access through the narrowed type, which the spec
|
|
37
|
+
* deliberately does not attempt.
|
|
38
|
+
*/
|
|
39
|
+
/** Every front-end produces nodes of at least this shape. */
|
|
40
|
+
export interface Node {
|
|
41
|
+
type: string;
|
|
42
|
+
loc?: {
|
|
43
|
+
start?: {
|
|
44
|
+
line?: number;
|
|
45
|
+
column?: number;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
[field: string]: unknown;
|
|
49
|
+
}
|
|
50
|
+
export interface VocabularyEntry {
|
|
51
|
+
/** The ESTree spelling, when acorn and oxc disagree with babel. */
|
|
52
|
+
estree?: string;
|
|
53
|
+
/** Why the name is here, where that is not obvious from the name. */
|
|
54
|
+
note?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Names whose ESTree spelling differs. These are the porting hazards: a front-end
|
|
58
|
+
* swap that misses one produces a layer that silently stops recognising a
|
|
59
|
+
* construct rather than failing.
|
|
60
|
+
*/
|
|
61
|
+
export declare const DIALECT_DIVERGENT: Record<string, VocabularyEntry>;
|
|
62
|
+
/**
|
|
63
|
+
* The ESTree spellings the layer already accepts alongside the babel ones.
|
|
64
|
+
*
|
|
65
|
+
* Three sites handle both today (`lower/jsx.ts`, `analyze/props-destructure.ts`,
|
|
66
|
+
* `analyze/expr-shape.ts`) and three do not: `analyze/static-graph.ts` tests
|
|
67
|
+
* `StringLiteral` at one site and `ObjectProperty` at two, with no `Literal` or
|
|
68
|
+
* `Property` branch beside them. Those three are the known gap, and they are why
|
|
69
|
+
* this file lists the pairs rather than assuming the layer is already portable.
|
|
70
|
+
*/
|
|
71
|
+
export declare const ESTREE_ALIASES: Record<string, VocabularyEntry>;
|
|
72
|
+
/** JSX. acorn-jsx keeps babel's names; SWC does not. */
|
|
73
|
+
export declare const JSX_NODES: Record<string, VocabularyEntry>;
|
|
74
|
+
/** Names spelled the same in babel and ESTree. */
|
|
75
|
+
export declare const SHARED_NODES: Record<string, VocabularyEntry>;
|
|
76
|
+
/** Every name the parser-agnostic layer may branch on. */
|
|
77
|
+
export declare const VOCABULARY: Record<string, VocabularyEntry>;
|
|
78
|
+
/** The directories that must not branch on anything outside `VOCABULARY`. */
|
|
79
|
+
export declare const PARSER_AGNOSTIC_DIRS: readonly ["lower", "analyze", "optimize", "resolve", "codegen"];
|
|
80
|
+
//# sourceMappingURL=vocabulary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocabulary.d.ts","sourceRoot":"","sources":["../../src/frontend/vocabulary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AAEH,6DAA6D;AAC7D,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAC;YAAC,MAAM,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;IACrD,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,eAAe;IAC9B,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAQ7D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAG1D,CAAC;AAEF,wDAAwD;AACxD,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAarD,CAAC;AAEF,kDAAkD;AAClD,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAiCxD,CAAC;AAEF,0DAA0D;AAC1D,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAKtD,CAAC;AAEF,6EAA6E;AAC7E,eAAO,MAAM,oBAAoB,iEAAkE,CAAC"}
|