@fluixi/compiler 1.0.0-alpha.100
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/LICENSE +21 -0
- package/README.md +131 -0
- package/dist/analyze/expr-shape.cjs +62 -0
- package/dist/analyze/expr-shape.d.cts +14 -0
- package/dist/analyze/expr-shape.d.ts +15 -0
- package/dist/analyze/expr-shape.d.ts.map +1 -0
- package/dist/analyze/expr-shape.js +37 -0
- package/dist/analyze/expr-shape.mjs +41 -0
- package/dist/analyze/intrinsics.cjs +112 -0
- package/dist/analyze/intrinsics.d.cts +80 -0
- package/dist/analyze/intrinsics.d.ts +81 -0
- package/dist/analyze/intrinsics.d.ts.map +1 -0
- package/dist/analyze/intrinsics.js +126 -0
- package/dist/analyze/intrinsics.mjs +91 -0
- 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 -0
- package/dist/analyze/props-destructure.d.cts +83 -0
- package/dist/analyze/props-destructure.d.ts +84 -0
- package/dist/analyze/props-destructure.d.ts.map +1 -0
- package/dist/analyze/props-destructure.js +272 -0
- package/dist/analyze/props-destructure.mjs +205 -0
- package/dist/analyze/reactive-bindings.cjs +210 -0
- package/dist/analyze/reactive-bindings.d.cts +42 -0
- package/dist/analyze/reactive-bindings.d.ts +43 -0
- package/dist/analyze/reactive-bindings.d.ts.map +1 -0
- package/dist/analyze/reactive-bindings.js +191 -0
- package/dist/analyze/reactive-bindings.mjs +187 -0
- package/dist/analyze/reactive-expr.cjs +38 -0
- package/dist/analyze/reactive-expr.d.cts +38 -0
- package/dist/analyze/reactive-expr.d.ts +39 -0
- package/dist/analyze/reactive-expr.d.ts.map +1 -0
- package/dist/analyze/reactive-expr.js +31 -0
- package/dist/analyze/reactive-expr.mjs +17 -0
- package/dist/analyze/static-graph.cjs +831 -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 +871 -0
- package/dist/analyze/static-graph.mjs +813 -0
- package/dist/babel-I6BUWUCU.mjs +636 -0
- package/dist/chunk-3AICWNF7.mjs +92 -0
- package/dist/chunk-6CWJWGE2.mjs +2170 -0
- package/dist/chunk-C3XPDB4Y.mjs +16 -0
- package/dist/chunk-GX5XV6Z7.mjs +190 -0
- package/dist/chunk-HXEXPWJ2.mjs +999 -0
- package/dist/chunk-NU3W67UZ.mjs +584 -0
- package/dist/chunk-SKAVY75W.mjs +11 -0
- package/dist/codegen/backend.cjs +18 -0
- package/dist/codegen/backend.d.cts +35 -0
- package/dist/codegen/backend.d.ts +36 -0
- package/dist/codegen/backend.d.ts.map +1 -0
- package/dist/codegen/backend.js +1 -0
- package/dist/codegen/backend.mjs +0 -0
- package/dist/codegen/backends/imperative.cjs +577 -0
- package/dist/codegen/backends/imperative.d.cts +11 -0
- package/dist/codegen/backends/imperative.d.ts +12 -0
- package/dist/codegen/backends/imperative.d.ts.map +1 -0
- package/dist/codegen/backends/imperative.js +362 -0
- package/dist/codegen/backends/imperative.mjs +554 -0
- package/dist/codegen/contract.cjs +52 -0
- package/dist/codegen/contract.d.cts +24 -0
- package/dist/codegen/contract.d.ts +25 -0
- package/dist/codegen/contract.d.ts.map +1 -0
- package/dist/codegen/contract.js +30 -0
- package/dist/codegen/contract.mjs +31 -0
- package/dist/codegen/partial-template.cjs +176 -0
- package/dist/codegen/partial-template.d.cts +61 -0
- package/dist/codegen/partial-template.d.ts +62 -0
- package/dist/codegen/partial-template.d.ts.map +1 -0
- package/dist/codegen/partial-template.js +0 -0
- package/dist/codegen/partial-template.mjs +153 -0
- package/dist/codegen/serialize-static.cjs +125 -0
- package/dist/codegen/serialize-static.d.cts +38 -0
- package/dist/codegen/serialize-static.d.ts +39 -0
- package/dist/codegen/serialize-static.d.ts.map +1 -0
- package/dist/codegen/serialize-static.js +165 -0
- package/dist/codegen/serialize-static.mjs +104 -0
- package/dist/frontend/babel/build-ir-lit.cjs +1933 -0
- package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
- package/dist/frontend/babel/build-ir-lit.d.ts +27 -0
- package/dist/frontend/babel/build-ir-lit.d.ts.map +1 -0
- package/dist/frontend/babel/build-ir-lit.js +13 -0
- package/dist/frontend/babel/build-ir-lit.mjs +1902 -0
- package/dist/frontend/babel/build-ir.cjs +1948 -0
- package/dist/frontend/babel/build-ir.d.cts +35 -0
- package/dist/frontend/babel/build-ir.d.ts +36 -0
- package/dist/frontend/babel/build-ir.d.ts.map +1 -0
- package/dist/frontend/babel/build-ir.js +124 -0
- package/dist/frontend/babel/build-ir.mjs +1919 -0
- package/dist/frontend/babel/index.cjs +2610 -0
- package/dist/frontend/babel/index.d.cts +33 -0
- package/dist/frontend/babel/index.d.ts +34 -0
- package/dist/frontend/babel/index.d.ts.map +1 -0
- package/dist/frontend/babel/index.js +65 -0
- package/dist/frontend/babel/index.mjs +2580 -0
- package/dist/frontend/babel/lower-template.cjs +1931 -0
- package/dist/frontend/babel/lower-template.d.cts +23 -0
- package/dist/frontend/babel/lower-template.d.ts +24 -0
- package/dist/frontend/babel/lower-template.d.ts.map +1 -0
- package/dist/frontend/babel/lower-template.js +64 -0
- package/dist/frontend/babel/lower-template.mjs +1902 -0
- package/dist/frontend/babel/plugin.cjs +2556 -0
- package/dist/frontend/babel/plugin.d.cts +95 -0
- package/dist/frontend/babel/plugin.d.ts +96 -0
- package/dist/frontend/babel/plugin.d.ts.map +1 -0
- package/dist/frontend/babel/plugin.js +523 -0
- package/dist/frontend/babel/plugin.mjs +2527 -0
- package/dist/frontend/babel/server-functions.cjs +110 -0
- package/dist/frontend/babel/server-functions.d.cts +10 -0
- package/dist/frontend/babel/server-functions.d.ts +11 -0
- package/dist/frontend/babel/server-functions.d.ts.map +1 -0
- package/dist/frontend/babel/server-functions.js +81 -0
- package/dist/frontend/babel/server-functions.mjs +89 -0
- package/dist/frontend/babel/types.cjs +18 -0
- package/dist/frontend/babel/types.d.cts +33 -0
- package/dist/frontend/babel/types.d.ts +34 -0
- package/dist/frontend/babel/types.d.ts.map +1 -0
- package/dist/frontend/babel/types.js +1 -0
- package/dist/frontend/babel/types.mjs +0 -0
- package/dist/frontend/types.cjs +18 -0
- package/dist/frontend/types.d.cts +25 -0
- package/dist/frontend/types.d.ts +26 -0
- package/dist/frontend/types.d.ts.map +1 -0
- package/dist/frontend/types.js +1 -0
- package/dist/frontend/types.mjs +0 -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 +1957 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +38 -0
- package/dist/index.mjs +1949 -0
- package/dist/integrations.cjs +5705 -0
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.d.ts +216 -0
- package/dist/integrations.d.ts.map +1 -0
- package/dist/integrations.js +566 -0
- package/dist/integrations.mjs +810 -0
- package/dist/ir/nodes.cjs +18 -0
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/ir/nodes.d.ts +169 -0
- package/dist/ir/nodes.d.ts.map +1 -0
- package/dist/ir/nodes.js +1 -0
- package/dist/ir/nodes.mjs +0 -0
- package/dist/lower/compile-template.cjs +1670 -0
- package/dist/lower/compile-template.d.cts +82 -0
- package/dist/lower/compile-template.d.ts +83 -0
- package/dist/lower/compile-template.d.ts.map +1 -0
- package/dist/lower/compile-template.js +79 -0
- package/dist/lower/compile-template.mjs +1662 -0
- package/dist/lower/entities.cjs +288 -0
- package/dist/lower/entities.d.cts +1 -0
- package/dist/lower/entities.d.ts +2 -0
- package/dist/lower/entities.d.ts.map +1 -0
- package/dist/lower/entities.js +54 -0
- package/dist/lower/entities.mjs +267 -0
- package/dist/lower/jsx.cjs +1101 -0
- package/dist/lower/jsx.d.cts +33 -0
- package/dist/lower/jsx.d.ts +34 -0
- package/dist/lower/jsx.d.ts.map +1 -0
- package/dist/lower/jsx.js +414 -0
- package/dist/lower/jsx.mjs +1078 -0
- package/dist/lower/template.cjs +1354 -0
- package/dist/lower/template.d.cts +53 -0
- package/dist/lower/template.d.ts +54 -0
- package/dist/lower/template.d.ts.map +1 -0
- package/dist/lower/template.js +542 -0
- package/dist/lower/template.mjs +1335 -0
- package/dist/lower/text.cjs +42 -0
- package/dist/lower/text.d.cts +10 -0
- package/dist/lower/text.d.ts +11 -0
- package/dist/lower/text.d.ts.map +1 -0
- package/dist/lower/text.js +31 -0
- package/dist/lower/text.mjs +21 -0
- package/dist/optimize/analyze-static.cjs +112 -0
- package/dist/optimize/analyze-static.d.cts +39 -0
- package/dist/optimize/analyze-static.d.ts +40 -0
- package/dist/optimize/analyze-static.d.ts.map +1 -0
- package/dist/optimize/analyze-static.js +131 -0
- package/dist/optimize/analyze-static.mjs +91 -0
- package/dist/optimize/collapse-strategies.cjs +90 -0
- package/dist/optimize/collapse-strategies.d.cts +30 -0
- package/dist/optimize/collapse-strategies.d.ts +31 -0
- package/dist/optimize/collapse-strategies.d.ts.map +1 -0
- package/dist/optimize/collapse-strategies.js +33 -0
- package/dist/optimize/collapse-strategies.mjs +67 -0
- package/dist/options.cjs +33 -0
- package/dist/options.d.cts +39 -0
- package/dist/options.d.ts +40 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +8 -0
- package/dist/options.mjs +12 -0
- package/dist/resolve/builtins.cjs +73 -0
- package/dist/resolve/builtins.d.cts +68 -0
- package/dist/resolve/builtins.d.ts +69 -0
- package/dist/resolve/builtins.d.ts.map +1 -0
- package/dist/resolve/builtins.js +64 -0
- package/dist/resolve/builtins.mjs +53 -0
- package/dist/resolve/component-globals.cjs +272 -0
- package/dist/resolve/component-globals.d.cts +88 -0
- package/dist/resolve/component-globals.d.ts +89 -0
- package/dist/resolve/component-globals.d.ts.map +1 -0
- package/dist/resolve/component-globals.js +160 -0
- package/dist/resolve/component-globals.mjs +249 -0
- package/dist/resolve/component-resolver.cjs +80 -0
- package/dist/resolve/component-resolver.d.cts +68 -0
- package/dist/resolve/component-resolver.d.ts +69 -0
- package/dist/resolve/component-resolver.d.ts.map +1 -0
- package/dist/resolve/component-resolver.js +95 -0
- package/dist/resolve/component-resolver.mjs +59 -0
- package/dist/resolve/load-directive.cjs +93 -0
- package/dist/resolve/load-directive.d.cts +53 -0
- package/dist/resolve/load-directive.d.ts +54 -0
- package/dist/resolve/load-directive.d.ts.map +1 -0
- package/dist/resolve/load-directive.js +93 -0
- package/dist/resolve/load-directive.mjs +72 -0
- package/dist/resolve/resolve-ir.cjs +108 -0
- package/dist/resolve/resolve-ir.d.cts +53 -0
- package/dist/resolve/resolve-ir.d.ts +54 -0
- package/dist/resolve/resolve-ir.d.ts.map +1 -0
- package/dist/resolve/resolve-ir.js +58 -0
- package/dist/resolve/resolve-ir.mjs +85 -0
- package/dist/resolve/write-globals.cjs +383 -0
- package/dist/resolve/write-globals.d.cts +36 -0
- package/dist/resolve/write-globals.d.ts +37 -0
- package/dist/resolve/write-globals.d.ts.map +1 -0
- package/dist/resolve/write-globals.js +169 -0
- package/dist/resolve/write-globals.mjs +362 -0
- package/dist/server-fns-VZLHMQTC.mjs +79 -0
- package/dist/server-functions-UAZKOLZW.mjs +82 -0
- package/dist/transform/bindings.cjs +71 -0
- package/dist/transform/bindings.d.cts +16 -0
- package/dist/transform/bindings.d.ts +17 -0
- package/dist/transform/bindings.d.ts.map +1 -0
- package/dist/transform/bindings.js +69 -0
- package/dist/transform/bindings.mjs +50 -0
- package/dist/transform/index.cjs +3837 -0
- package/dist/transform/index.d.cts +15 -0
- package/dist/transform/index.d.ts +16 -0
- package/dist/transform/index.d.ts.map +1 -0
- package/dist/transform/index.js +12 -0
- package/dist/transform/index.mjs +4882 -0
- package/dist/transform/intrinsics.cjs +261 -0
- package/dist/transform/intrinsics.d.cts +33 -0
- package/dist/transform/intrinsics.d.ts +34 -0
- package/dist/transform/intrinsics.d.ts.map +1 -0
- package/dist/transform/intrinsics.js +120 -0
- package/dist/transform/intrinsics.mjs +238 -0
- package/dist/transform/props.cjs +441 -0
- package/dist/transform/props.d.cts +45 -0
- package/dist/transform/props.d.ts +46 -0
- package/dist/transform/props.d.ts.map +1 -0
- package/dist/transform/props.js +221 -0
- package/dist/transform/props.mjs +1487 -0
- package/dist/transform/server-fn-id.cjs +35 -0
- package/dist/transform/server-fn-id.d.cts +9 -0
- package/dist/transform/server-fn-id.d.ts +10 -0
- package/dist/transform/server-fn-id.d.ts.map +1 -0
- package/dist/transform/server-fn-id.js +18 -0
- package/dist/transform/server-fn-id.mjs +14 -0
- package/dist/transform/server-fns.cjs +114 -0
- package/dist/transform/server-fns.d.cts +12 -0
- package/dist/transform/server-fns.d.ts +13 -0
- package/dist/transform/server-fns.d.ts.map +1 -0
- package/dist/transform/server-fns.js +94 -0
- package/dist/transform/server-fns.mjs +1160 -0
- package/dist/transform/source-locations.cjs +393 -0
- package/dist/transform/source-locations.d.cts +48 -0
- package/dist/transform/source-locations.d.ts +49 -0
- package/dist/transform/source-locations.d.ts.map +1 -0
- package/dist/transform/source-locations.js +303 -0
- package/dist/transform/source-locations.mjs +370 -0
- package/dist/transform/styles.cjs +606 -0
- package/dist/transform/styles.d.cts +237 -0
- package/dist/transform/styles.d.ts +238 -0
- package/dist/transform/styles.d.ts.map +1 -0
- package/dist/transform/styles.js +743 -0
- package/dist/transform/styles.mjs +671 -0
- package/dist/transform/templates.cjs +3806 -0
- package/dist/transform/templates.d.cts +82 -0
- package/dist/transform/templates.d.ts +83 -0
- package/dist/transform/templates.d.ts.map +1 -0
- package/dist/transform/templates.js +613 -0
- package/dist/transform/templates.mjs +4852 -0
- package/dist/transform-3W45L3EA.mjs +951 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/dist/vite-styles.cjs +223 -0
- package/dist/vite-styles.d.cts +68 -0
- package/dist/vite-styles.d.ts +69 -0
- package/dist/vite-styles.d.ts.map +1 -0
- package/dist/vite-styles.js +241 -0
- package/dist/vite-styles.mjs +214 -0
- package/package.json +141 -0
|
@@ -0,0 +1,71 @@
|
|
|
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>;
|
|
@@ -0,0 +1,17 @@
|
|
|
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>;
|
|
17
|
+
//# sourceMappingURL=bindings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bindings.d.ts","sourceRoot":"","sources":["../../src/transform/bindings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoDH,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAIxE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
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
|
+
/** Every name a destructuring pattern (or plain identifier) introduces. */
|
|
14
|
+
function patternNames(node, out) {
|
|
15
|
+
if (!node)
|
|
16
|
+
return;
|
|
17
|
+
switch (node.type) {
|
|
18
|
+
case 'Identifier':
|
|
19
|
+
out.add(node.name);
|
|
20
|
+
return;
|
|
21
|
+
case 'ObjectPattern':
|
|
22
|
+
for (const p of node.properties) {
|
|
23
|
+
if (p.type === 'RestElement')
|
|
24
|
+
patternNames(p.argument, out);
|
|
25
|
+
else
|
|
26
|
+
patternNames(p.value, out);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
case 'ArrayPattern':
|
|
30
|
+
for (const e of node.elements)
|
|
31
|
+
patternNames(e, out);
|
|
32
|
+
return;
|
|
33
|
+
case 'AssignmentPattern':
|
|
34
|
+
patternNames(node.left, out);
|
|
35
|
+
return;
|
|
36
|
+
case 'RestElement':
|
|
37
|
+
patternNames(node.argument, out);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function declared(node, out) {
|
|
42
|
+
switch (node.type) {
|
|
43
|
+
case 'ImportDeclaration':
|
|
44
|
+
for (const s of node.specifiers)
|
|
45
|
+
patternNames(s.local, out);
|
|
46
|
+
return;
|
|
47
|
+
case 'VariableDeclaration':
|
|
48
|
+
for (const d of node.declarations)
|
|
49
|
+
patternNames(d.id, out);
|
|
50
|
+
return;
|
|
51
|
+
case 'FunctionDeclaration':
|
|
52
|
+
case 'ClassDeclaration':
|
|
53
|
+
patternNames(node.id, out);
|
|
54
|
+
return;
|
|
55
|
+
case 'ExportNamedDeclaration':
|
|
56
|
+
case 'ExportDefaultDeclaration':
|
|
57
|
+
// `export const x = 1` / `export function f() {}` bind too.
|
|
58
|
+
if (node.declaration)
|
|
59
|
+
declared(node.declaration, out);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/** Collect the names bound at the top level of a parsed module. */
|
|
64
|
+
export function moduleBindings(program) {
|
|
65
|
+
const names = new Set();
|
|
66
|
+
for (const statement of program.body)
|
|
67
|
+
declared(statement, names);
|
|
68
|
+
return names;
|
|
69
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
};
|