@fluixi/compiler 1.0.0-alpha.83 → 1.0.0-alpha.85
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.d.ts +2 -2
- package/dist/analyze/expr-shape.js +1 -1
- 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.d.ts +7 -7
- package/dist/analyze/intrinsics.d.ts.map +1 -1
- package/dist/analyze/intrinsics.js +3 -3
- 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.d.ts +3 -3
- package/dist/analyze/props-destructure.d.ts.map +1 -1
- package/dist/analyze/props-destructure.js +4 -4
- 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.d.ts +1 -1
- package/dist/analyze/reactive-bindings.js +2 -2
- 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.d.ts +4 -4
- package/dist/analyze/reactive-expr.d.ts.map +1 -1
- package/dist/analyze/reactive-expr.js +2 -2
- 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.d.ts +1 -1
- package/dist/analyze/static-graph.d.ts.map +1 -1
- package/dist/analyze/static-graph.js +11 -11
- package/dist/analyze/static-graph.mjs +793 -1
- package/dist/babel-TGY76XJ7.mjs +636 -0
- package/dist/chunk-4PLHS2FP.mjs +158 -0
- package/dist/chunk-6DB5FXS4.mjs +1718 -0
- package/dist/chunk-F74GFKSL.mjs +16 -0
- package/dist/chunk-G6QC2WRJ.mjs +11 -0
- package/dist/chunk-RUDJDZAA.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 +1 -1
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +24 -20
- 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.d.ts +2 -2
- package/dist/codegen/contract.js +2 -2
- 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.d.ts +4 -4
- package/dist/codegen/partial-template.js +0 -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 +3 -3
- package/dist/codegen/serialize-static.js +6 -6
- 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.d.ts +2 -2
- 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.d.ts +2 -2
- package/dist/frontend/babel/build-ir.js +2 -2
- 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.d.ts +1 -1
- package/dist/frontend/babel/index.js +1 -1
- 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.d.ts +1 -1
- package/dist/frontend/babel/lower-template.js +2 -2
- 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.d.ts +5 -5
- package/dist/frontend/babel/plugin.d.ts.map +1 -1
- package/dist/frontend/babel/plugin.js +14 -14
- 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 +1595 -14
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +1575 -14
- package/dist/integrations.cjs +4312 -26
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.d.ts +9 -9
- package/dist/integrations.d.ts.map +1 -1
- package/dist/integrations.js +29 -8
- package/dist/integrations.mjs +536 -18
- package/dist/ir/nodes.cjs +18 -1
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/ir/nodes.d.ts +6 -6
- package/dist/lower/compile-template.cjs +1356 -1
- package/dist/lower/compile-template.d.cts +69 -0
- package/dist/lower/compile-template.d.ts +3 -3
- package/dist/lower/compile-template.js +1 -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 +1 -1
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +6 -5
- 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 +3 -3
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +12 -11
- 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.d.ts +2 -2
- package/dist/lower/text.d.ts.map +1 -1
- package/dist/lower/text.js +2 -2
- 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.d.ts +2 -2
- package/dist/optimize/analyze-static.js +2 -2
- 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.d.ts +3 -3
- package/dist/optimize/collapse-strategies.mjs +67 -1
- package/dist/options.cjs +33 -1
- package/dist/options.d.cts +39 -0
- package/dist/options.d.ts +2 -2
- 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.d.ts +8 -8
- package/dist/resolve/builtins.d.ts.map +1 -1
- package/dist/resolve/builtins.js +4 -4
- package/dist/resolve/builtins.mjs +53 -1
- package/dist/resolve/component-globals.cjs +234 -14
- package/dist/resolve/component-globals.d.cts +80 -0
- package/dist/resolve/component-globals.d.ts +5 -5
- package/dist/resolve/component-globals.js +10 -10
- package/dist/resolve/component-globals.mjs +211 -14
- package/dist/resolve/component-resolver.cjs +80 -1
- package/dist/resolve/component-resolver.d.cts +68 -0
- package/dist/resolve/component-resolver.d.ts +3 -3
- package/dist/resolve/component-resolver.d.ts.map +1 -1
- package/dist/resolve/component-resolver.js +3 -3
- 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.d.ts +5 -5
- package/dist/resolve/load-directive.js +6 -6
- 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.d.ts +6 -6
- package/dist/resolve/resolve-ir.d.ts.map +1 -1
- package/dist/resolve/resolve-ir.js +1 -1
- package/dist/resolve/resolve-ir.mjs +85 -1
- package/dist/resolve/write-globals.cjs +319 -14
- package/dist/resolve/write-globals.d.cts +30 -0
- package/dist/resolve/write-globals.js +2 -2
- package/dist/resolve/write-globals.mjs +298 -14
- package/dist/server-fns-ZYWQTSZU.mjs +78 -0
- package/dist/server-functions-PCERFA7A.mjs +82 -0
- package/dist/transform/bindings.cjs +71 -1
- package/dist/transform/bindings.d.cts +16 -0
- package/dist/transform/bindings.d.ts +1 -1
- package/dist/transform/bindings.js +1 -1
- 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.js +1 -1
- 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.d.ts +1 -1
- package/dist/transform/props.d.ts.map +1 -1
- package/dist/transform/props.js +4 -4
- 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.d.ts +1 -1
- package/dist/transform/server-fn-id.js +2 -2
- 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.js +3 -3
- 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.d.ts +1 -1
- package/dist/transform/source-locations.js +5 -5
- 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.d.ts +2 -2
- package/dist/transform/templates.d.ts.map +1 -1
- package/dist/transform/templates.js +7 -7
- package/dist/transform/templates.mjs +3743 -16
- package/dist/transform-RWDTQUF5.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
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ambient declarations for the components `resolve` supplies without an import.
|
|
3
|
+
*
|
|
4
|
+
* The compiler injects the import, so nothing in the source imports these, which leaves
|
|
5
|
+
* TypeScript reporting `TS2304: Cannot find name`. The code compiles and runs; the editor
|
|
6
|
+
* is unusable and `tsc` fails. These declarations describe what the compiler already
|
|
7
|
+
* does. They do not enable it.
|
|
8
|
+
*
|
|
9
|
+
* This lives next to the resolver, and takes rules rather than a flat map, because the
|
|
10
|
+
* resolver is the only thing that knows the whole picture: a UI library's components, the
|
|
11
|
+
* project's own, and the framework builtins all arrive through the same config. A
|
|
12
|
+
* component library cannot generate this on its own, it does not know what else the
|
|
13
|
+
* project resolves: which is why the generator belongs here and the library-specific CLI
|
|
14
|
+
* that predates it does not.
|
|
15
|
+
*
|
|
16
|
+
* Pure, like the resolver: rules in, source out, no filesystem. Writing the file is the
|
|
17
|
+
* caller's job (the Vite plugin does it on config resolve; a CLI can do it in CI).
|
|
18
|
+
*/
|
|
19
|
+
import { type ComponentResolverRule } from './component-resolver.cjs';
|
|
20
|
+
export interface ComponentGlobalsOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Packages the project can actually resolve: normally its declared dependencies.
|
|
23
|
+
*
|
|
24
|
+
* Declaring a component from a package the project does not depend on produces an
|
|
25
|
+
* unresolvable `import(...)`, and under the usual `skipLibCheck: true` that failure is
|
|
26
|
+
* silent: the component degrades to `any` and every prop typo type-checks, which is
|
|
27
|
+
* worse than the error it replaced. Omit to declare everything, which is only correct
|
|
28
|
+
* when every package is present.
|
|
29
|
+
*
|
|
30
|
+
* Relative and alias specifiers are never filtered, there is no package to check.
|
|
31
|
+
*/
|
|
32
|
+
available?: Iterable<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Declare the framework builtins (`Show`, `For`, `Portal`, `Router`, …) too.
|
|
35
|
+
*
|
|
36
|
+
* On by default because the compiler resolves them whether or not a rule mentions
|
|
37
|
+
* them, so declaring them is what matches reality. A real import shadows the ambient
|
|
38
|
+
* declaration, so this stays safe for code that imports them explicitly.
|
|
39
|
+
*/
|
|
40
|
+
builtins?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Declare the `$` reactive intrinsics (`$signal`, `$memo`, …).
|
|
43
|
+
*
|
|
44
|
+
* On by default, matching the compiler: it rewrites those calls whether or not
|
|
45
|
+
* anything declares them, and without the declaration the editor reports
|
|
46
|
+
* "Cannot find name '$signal'" for code that builds correctly.
|
|
47
|
+
*/
|
|
48
|
+
intrinsics?: boolean;
|
|
49
|
+
/** Attribution written into the header. */
|
|
50
|
+
generator?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Rewrite a module specifier for the file being generated.
|
|
53
|
+
*
|
|
54
|
+
* A bundler and TypeScript do not agree on every specifier: Vite resolves a
|
|
55
|
+
* root-absolute `/src/x.tsx` that TypeScript cannot see at all. The caller knows where
|
|
56
|
+
* the file will land and so is the only one able to fix that up; the generator stays
|
|
57
|
+
* pure and just asks.
|
|
58
|
+
*/
|
|
59
|
+
specifier?: (module: string) => string;
|
|
60
|
+
}
|
|
61
|
+
export interface ComponentGlobalsResult {
|
|
62
|
+
/** The `.d.ts` source to write. */
|
|
63
|
+
source: string;
|
|
64
|
+
/** Components declared. */
|
|
65
|
+
declared: string[];
|
|
66
|
+
/** Left out because `lib.dom` already claims the name. */
|
|
67
|
+
shadowedByDom: string[];
|
|
68
|
+
/** Left out because the project does not depend on their package. */
|
|
69
|
+
unavailable: string[];
|
|
70
|
+
/**
|
|
71
|
+
* Pattern rules, which have no finite name list and so cannot be declared.
|
|
72
|
+
*
|
|
73
|
+
* `Icon(.+) -> @/icons/$1` matches unboundedly many names; the resolver answers them on
|
|
74
|
+
* demand but cannot enumerate them. Those tags stay manual, and the caller is told how
|
|
75
|
+
* many rules are in that position rather than left to wonder why nothing appeared.
|
|
76
|
+
*/
|
|
77
|
+
patternRules: number;
|
|
78
|
+
}
|
|
79
|
+
/** Build the ambient `.d.ts` for the components a project's `resolve` config supplies. */
|
|
80
|
+
export declare function componentGlobals(rules: readonly ComponentResolverRule[], options?: ComponentGlobalsOptions): ComponentGlobalsResult;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Ambient declarations for the components `resolve` supplies without an import.
|
|
3
3
|
*
|
|
4
|
-
* The compiler injects the import, so nothing in the source imports these
|
|
4
|
+
* The compiler injects the import, so nothing in the source imports these, which leaves
|
|
5
5
|
* TypeScript reporting `TS2304: Cannot find name`. The code compiles and runs; the editor
|
|
6
6
|
* is unusable and `tsc` fails. These declarations describe what the compiler already
|
|
7
7
|
* does. They do not enable it.
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* This lives next to the resolver, and takes rules rather than a flat map, because the
|
|
10
10
|
* resolver is the only thing that knows the whole picture: a UI library's components, the
|
|
11
11
|
* project's own, and the framework builtins all arrive through the same config. A
|
|
12
|
-
* component library cannot generate this on its own
|
|
13
|
-
* project resolves
|
|
12
|
+
* component library cannot generate this on its own, it does not know what else the
|
|
13
|
+
* project resolves: which is why the generator belongs here and the library-specific CLI
|
|
14
14
|
* that predates it does not.
|
|
15
15
|
*
|
|
16
16
|
* Pure, like the resolver: rules in, source out, no filesystem. Writing the file is the
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { type ComponentResolverRule } from './component-resolver.js';
|
|
20
20
|
export interface ComponentGlobalsOptions {
|
|
21
21
|
/**
|
|
22
|
-
* Packages the project can actually resolve
|
|
22
|
+
* Packages the project can actually resolve: normally its declared dependencies.
|
|
23
23
|
*
|
|
24
24
|
* Declaring a component from a package the project does not depend on produces an
|
|
25
25
|
* unresolvable `import(...)`, and under the usual `skipLibCheck: true` that failure is
|
|
@@ -27,7 +27,7 @@ export interface ComponentGlobalsOptions {
|
|
|
27
27
|
* worse than the error it replaced. Omit to declare everything, which is only correct
|
|
28
28
|
* when every package is present.
|
|
29
29
|
*
|
|
30
|
-
* Relative and alias specifiers are never filtered
|
|
30
|
+
* Relative and alias specifiers are never filtered, there is no package to check.
|
|
31
31
|
*/
|
|
32
32
|
available?: Iterable<string>;
|
|
33
33
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Ambient declarations for the components `resolve` supplies without an import.
|
|
3
3
|
*
|
|
4
|
-
* The compiler injects the import, so nothing in the source imports these
|
|
4
|
+
* The compiler injects the import, so nothing in the source imports these, which leaves
|
|
5
5
|
* TypeScript reporting `TS2304: Cannot find name`. The code compiles and runs; the editor
|
|
6
6
|
* is unusable and `tsc` fails. These declarations describe what the compiler already
|
|
7
7
|
* does. They do not enable it.
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
* This lives next to the resolver, and takes rules rather than a flat map, because the
|
|
10
10
|
* resolver is the only thing that knows the whole picture: a UI library's components, the
|
|
11
11
|
* project's own, and the framework builtins all arrive through the same config. A
|
|
12
|
-
* component library cannot generate this on its own
|
|
13
|
-
* project resolves
|
|
12
|
+
* component library cannot generate this on its own, it does not know what else the
|
|
13
|
+
* project resolves: which is why the generator belongs here and the library-specific CLI
|
|
14
14
|
* that predates it does not.
|
|
15
15
|
*
|
|
16
16
|
* Pure, like the resolver: rules in, source out, no filesystem. Writing the file is the
|
|
@@ -23,7 +23,7 @@ import { INTRINSICS } from '../analyze/intrinsics.js';
|
|
|
23
23
|
* Names `lib.dom` already declares as globals.
|
|
24
24
|
*
|
|
25
25
|
* An ambient `const Text` cannot beat `lib.dom`'s `var Text`, so for these the editor
|
|
26
|
-
* would disagree with the compiler
|
|
26
|
+
* would disagree with the compiler: resolution still works at runtime, but the type
|
|
27
27
|
* shown would be the DOM node's. They are left out and reported instead, since importing
|
|
28
28
|
* them explicitly makes both agree.
|
|
29
29
|
*/
|
|
@@ -68,7 +68,7 @@ export function componentGlobals(rules, options = {}) {
|
|
|
68
68
|
const { available: availableList, builtins = true, intrinsics = true, generator = '@fluixi/compiler', specifier = (module) => module, } = options;
|
|
69
69
|
const all = [...rules];
|
|
70
70
|
if (builtins) {
|
|
71
|
-
// Appended, so an explicit rule for the same name still wins
|
|
71
|
+
// Appended, so an explicit rule for the same name still wins, the resolver is
|
|
72
72
|
// first-match, and a project retargeting `Router` should keep its own answer.
|
|
73
73
|
all.push({ components: builtinComponentMap() });
|
|
74
74
|
}
|
|
@@ -107,8 +107,8 @@ export function componentGlobals(rules, options = {}) {
|
|
|
107
107
|
// (`Button(props: ButtonProps): ComponentChild`) and go-to-definition lands on the
|
|
108
108
|
// source. Both forms keep the JSDoc; the alias also keeps the shape.
|
|
109
109
|
//
|
|
110
|
-
// A default export cannot use it
|
|
111
|
-
// `default` is a reserved word in that position
|
|
110
|
+
// A default export cannot use it: `import X = ns.default` is a syntax error, since
|
|
111
|
+
// `default` is a reserved word in that position, so those fall back to the `const`
|
|
112
112
|
// form, which types and documents correctly but renders as an anonymous arrow.
|
|
113
113
|
const lines = declared.map((name) => {
|
|
114
114
|
const target = resolved.get(name);
|
|
@@ -118,7 +118,7 @@ export function componentGlobals(rules, options = {}) {
|
|
|
118
118
|
: ` export import ${name} = ${ns}.${target.export};`;
|
|
119
119
|
});
|
|
120
120
|
const note = shadowedByDom.length > 0
|
|
121
|
-
? `//\n// Import these explicitly
|
|
121
|
+
? `//\n// Import these explicitly: lib.dom already declares the name, so an ambient\n` +
|
|
122
122
|
`// declaration cannot win:\n` +
|
|
123
123
|
shadowedByDom
|
|
124
124
|
.map((n) => {
|
|
@@ -129,7 +129,7 @@ export function componentGlobals(rules, options = {}) {
|
|
|
129
129
|
: '';
|
|
130
130
|
// `typeof ns.signal` rather than an alias: the intrinsic is a global that stands for
|
|
131
131
|
// the runtime call, so it takes the runtime's signature without claiming to be that
|
|
132
|
-
// symbol
|
|
132
|
+
// symbol: go-to-definition on `$signal` should land on what it compiles to.
|
|
133
133
|
const intrinsicLines = intrinsics
|
|
134
134
|
? Object.entries(INTRINSICS).map(([name, intrinsic]) => ` const ${name}: typeof ${namespaceAlias(intrinsic.module)}.${intrinsic.export};`)
|
|
135
135
|
: [];
|
|
@@ -139,7 +139,7 @@ export function componentGlobals(rules, options = {}) {
|
|
|
139
139
|
`// a pattern matches unboundedly many names, so there is no list to emit. Those\n` +
|
|
140
140
|
`// tags still resolve at build time; declare them by hand if the editor needs them.\n`
|
|
141
141
|
: '';
|
|
142
|
-
const source = `// GENERATED by ${generator}
|
|
142
|
+
const source = `// GENERATED by ${generator}, do not edit.\n` +
|
|
143
143
|
`//\n` +
|
|
144
144
|
`// The components \`resolve\` supplies without an import. This describes what the\n` +
|
|
145
145
|
`// compiler already does; it does not enable it.\n` +
|
|
@@ -1,22 +1,219 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// src/resolve/component-resolver.ts
|
|
2
|
+
var isMapRule = (rule) => "components" in rule;
|
|
3
|
+
function substitute(template, match) {
|
|
4
|
+
return template.replace(/\$(\d+)/g, (whole, index) => {
|
|
5
|
+
const group = match[Number(index)];
|
|
6
|
+
return group ?? whole;
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function normalise(name, entry) {
|
|
10
|
+
return typeof entry === "string" ? { module: entry, export: name } : entry;
|
|
11
|
+
}
|
|
12
|
+
function createComponentResolver(rules = []) {
|
|
13
|
+
const exact = /* @__PURE__ */ new Map();
|
|
14
|
+
const conflicts = [];
|
|
15
|
+
const patterns = [];
|
|
16
|
+
for (const rule of rules) {
|
|
17
|
+
if (!isMapRule(rule)) {
|
|
18
|
+
patterns.push(rule);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
for (const [name, entry] of Object.entries(rule.components)) {
|
|
22
|
+
const resolved = normalise(name, entry);
|
|
23
|
+
const existing = exact.get(name);
|
|
24
|
+
if (existing && existing.module !== resolved.module) {
|
|
25
|
+
const conflict = conflicts.find((c) => c.name === name);
|
|
26
|
+
if (conflict) conflict.modules.push(resolved.module);
|
|
27
|
+
else conflicts.push({ name, modules: [existing.module, resolved.module] });
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
exact.set(name, resolved);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const cache = /* @__PURE__ */ new Map();
|
|
34
|
+
const resolve = (name) => {
|
|
35
|
+
if (cache.has(name)) return cache.get(name);
|
|
36
|
+
let result = exact.get(name);
|
|
37
|
+
if (!result) {
|
|
38
|
+
for (const rule of patterns) {
|
|
39
|
+
const match = name.match(new RegExp(rule.match.source, rule.match.flags.replace("g", "")));
|
|
40
|
+
if (!match) continue;
|
|
41
|
+
result = {
|
|
42
|
+
module: substitute(rule.module, match),
|
|
43
|
+
export: rule.export ? substitute(rule.export, match) : name
|
|
44
|
+
};
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
cache.set(name, result);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
resolve,
|
|
53
|
+
names: () => [...exact.keys()],
|
|
54
|
+
conflicts: () => conflicts
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// src/resolve/builtins.ts
|
|
59
|
+
var DOM_CONTROL_FLOW = [
|
|
60
|
+
"Show",
|
|
61
|
+
"For",
|
|
62
|
+
"Index",
|
|
63
|
+
"Switch",
|
|
64
|
+
"Match",
|
|
65
|
+
"Portal",
|
|
66
|
+
"Dynamic",
|
|
67
|
+
"ErrorBoundary"
|
|
68
|
+
];
|
|
69
|
+
var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
|
|
70
|
+
var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
|
|
71
|
+
var BUILTIN_COMPONENTS = [
|
|
72
|
+
...DOM_CONTROL_FLOW,
|
|
73
|
+
...CORE_CONTROL_FLOW,
|
|
74
|
+
...ROUTER_COMPONENTS
|
|
75
|
+
];
|
|
76
|
+
var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
|
|
77
|
+
...DOM_CONTROL_FLOW,
|
|
78
|
+
...CORE_CONTROL_FLOW
|
|
79
|
+
]);
|
|
80
|
+
function builtinComponentMap(modules = {}) {
|
|
81
|
+
const {
|
|
82
|
+
controlFlowModule = "@fluixi/dom",
|
|
83
|
+
coreModule = "@fluixi/core",
|
|
84
|
+
routerModule = "@fluixi/core/router"
|
|
85
|
+
} = modules;
|
|
86
|
+
const map = {};
|
|
87
|
+
for (const name of DOM_CONTROL_FLOW) map[name] = controlFlowModule;
|
|
88
|
+
for (const name of CORE_CONTROL_FLOW) map[name] = coreModule;
|
|
89
|
+
for (const name of ROUTER_COMPONENTS) map[name] = routerModule;
|
|
90
|
+
return map;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/analyze/intrinsics.ts
|
|
94
|
+
var REACTIVE_MODULE = "@fluixi/reactive/signal";
|
|
95
|
+
var INTRINSICS = {
|
|
96
|
+
$signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
|
|
97
|
+
$memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
|
|
98
|
+
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
99
|
+
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
100
|
+
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
101
|
+
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
102
|
+
// name. Still worth having: no import to write, and when a shorter form is
|
|
103
|
+
// designed, the change is this line rather than a compiler pass.
|
|
104
|
+
$selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
105
|
+
$deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
106
|
+
// Not value constructors, but the compiler has to know them: they change what a read
|
|
107
|
+
// does. `untrack` suppresses dependency collection, which is exactly the kind of thing
|
|
108
|
+
// dependency analysis must not guess at.
|
|
109
|
+
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
110
|
+
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" }
|
|
111
|
+
};
|
|
112
|
+
var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
|
|
113
|
+
|
|
114
|
+
// src/resolve/component-globals.ts
|
|
115
|
+
var DOM_GLOBALS = /* @__PURE__ */ new Set([
|
|
116
|
+
"Text",
|
|
117
|
+
"Image",
|
|
118
|
+
"Option",
|
|
119
|
+
"Audio",
|
|
120
|
+
"Comment",
|
|
121
|
+
"Range",
|
|
122
|
+
"Selection",
|
|
123
|
+
"Notification",
|
|
124
|
+
"Event",
|
|
125
|
+
"Document",
|
|
126
|
+
"Element",
|
|
127
|
+
"Node",
|
|
128
|
+
"Screen",
|
|
129
|
+
"Window",
|
|
130
|
+
"Location",
|
|
131
|
+
"History",
|
|
132
|
+
"Storage",
|
|
133
|
+
"Response",
|
|
134
|
+
"Request",
|
|
135
|
+
"Headers"
|
|
136
|
+
]);
|
|
137
|
+
function packageOf(specifier) {
|
|
138
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) return void 0;
|
|
139
|
+
if (/^[~@]\//.test(specifier)) return void 0;
|
|
140
|
+
const parts = specifier.split("/");
|
|
141
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
142
|
+
}
|
|
143
|
+
function namespaceAlias(module) {
|
|
144
|
+
return `_${module.replace(/[^A-Za-z0-9]/g, "_")}`;
|
|
145
|
+
}
|
|
146
|
+
function componentGlobals(rules, options = {}) {
|
|
147
|
+
const {
|
|
148
|
+
available: availableList,
|
|
149
|
+
builtins = true,
|
|
150
|
+
intrinsics = true,
|
|
151
|
+
generator = "@fluixi/compiler",
|
|
152
|
+
specifier = (module) => module
|
|
153
|
+
} = options;
|
|
154
|
+
const all = [...rules];
|
|
155
|
+
if (builtins) {
|
|
156
|
+
all.push({ components: builtinComponentMap() });
|
|
157
|
+
}
|
|
158
|
+
const resolver = createComponentResolver(all);
|
|
159
|
+
const available = availableList ? new Set(availableList) : void 0;
|
|
160
|
+
const declared = [];
|
|
161
|
+
const shadowedByDom = [];
|
|
162
|
+
const unavailable = [];
|
|
163
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
164
|
+
for (const name of [...resolver.names()].sort()) {
|
|
165
|
+
const target = resolver.resolve(name);
|
|
166
|
+
if (!target) continue;
|
|
167
|
+
const pkg = packageOf(target.module);
|
|
168
|
+
if (DOM_GLOBALS.has(name)) shadowedByDom.push(name);
|
|
169
|
+
else if (available && pkg && !available.has(pkg)) unavailable.push(name);
|
|
170
|
+
else {
|
|
171
|
+
declared.push(name);
|
|
172
|
+
resolved.set(name, target);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
const intrinsicModules = intrinsics ? [...new Set(Object.values(INTRINSICS).map((i) => i.module))] : [];
|
|
176
|
+
const modules = [
|
|
177
|
+
.../* @__PURE__ */ new Set([...declared.map((name) => resolved.get(name).module), ...intrinsicModules])
|
|
178
|
+
].sort();
|
|
179
|
+
const imports = modules.map(
|
|
180
|
+
(m) => `import * as ${namespaceAlias(m)} from '${specifier(m)}';`
|
|
181
|
+
);
|
|
182
|
+
const lines = declared.map((name) => {
|
|
183
|
+
const target = resolved.get(name);
|
|
184
|
+
const ns = namespaceAlias(target.module);
|
|
185
|
+
return target.export === "default" ? ` const ${name}: typeof ${ns}.default;` : ` export import ${name} = ${ns}.${target.export};`;
|
|
186
|
+
});
|
|
187
|
+
const note = shadowedByDom.length > 0 ? `//
|
|
188
|
+
// Import these explicitly: lib.dom already declares the name, so an ambient
|
|
3
189
|
// declaration cannot win:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
190
|
+
` + shadowedByDom.map((n) => {
|
|
191
|
+
const module = resolver.resolve(n)?.module;
|
|
192
|
+
return `// import { ${n} } from '${module ? specifier(module) : ""}';
|
|
193
|
+
`;
|
|
194
|
+
}).join("") : "";
|
|
195
|
+
const intrinsicLines = intrinsics ? Object.entries(INTRINSICS).map(
|
|
196
|
+
([name, intrinsic]) => ` const ${name}: typeof ${namespaceAlias(intrinsic.module)}.${intrinsic.export};`
|
|
197
|
+
) : [];
|
|
198
|
+
const patternRules = rules.filter((rule) => "match" in rule).length;
|
|
199
|
+
const patternNote = patternRules > 0 ? `//
|
|
200
|
+
// ${patternRules} pattern rule${patternRules === 1 ? "" : "s"} cannot be declared:
|
|
7
201
|
// a pattern matches unboundedly many names, so there is no list to emit. Those
|
|
8
202
|
// tags still resolve at build time; declare them by hand if the editor needs them.
|
|
9
|
-
|
|
203
|
+
` : "";
|
|
204
|
+
const source = `// GENERATED by ${generator}, do not edit.
|
|
10
205
|
//
|
|
11
206
|
// The components \`resolve\` supplies without an import. This describes what the
|
|
12
207
|
// compiler already does; it does not enable it.
|
|
13
|
-
|
|
14
|
-
${
|
|
15
|
-
`)
|
|
16
|
-
`:`
|
|
17
|
-
`)+`
|
|
208
|
+
` + note + patternNote + (imports.length > 0 ? `
|
|
209
|
+
${imports.join("\n")}
|
|
210
|
+
` : "\n") + `
|
|
18
211
|
declare global {
|
|
19
|
-
${[...
|
|
20
|
-
|
|
212
|
+
${[...lines, ...intrinsicLines].join("\n")}
|
|
213
|
+
}
|
|
214
|
+
`;
|
|
215
|
+
return { source, declared, shadowedByDom, unavailable, patternRules };
|
|
21
216
|
}
|
|
22
|
-
|
|
217
|
+
export {
|
|
218
|
+
componentGlobals
|
|
219
|
+
};
|
|
@@ -1 +1,80 @@
|
|
|
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/resolve/component-resolver.ts
|
|
21
|
+
var component_resolver_exports = {};
|
|
22
|
+
__export(component_resolver_exports, {
|
|
23
|
+
createComponentResolver: () => createComponentResolver
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(component_resolver_exports);
|
|
26
|
+
var isMapRule = (rule) => "components" in rule;
|
|
27
|
+
function substitute(template, match) {
|
|
28
|
+
return template.replace(/\$(\d+)/g, (whole, index) => {
|
|
29
|
+
const group = match[Number(index)];
|
|
30
|
+
return group ?? whole;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function normalise(name, entry) {
|
|
34
|
+
return typeof entry === "string" ? { module: entry, export: name } : entry;
|
|
35
|
+
}
|
|
36
|
+
function createComponentResolver(rules = []) {
|
|
37
|
+
const exact = /* @__PURE__ */ new Map();
|
|
38
|
+
const conflicts = [];
|
|
39
|
+
const patterns = [];
|
|
40
|
+
for (const rule of rules) {
|
|
41
|
+
if (!isMapRule(rule)) {
|
|
42
|
+
patterns.push(rule);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
for (const [name, entry] of Object.entries(rule.components)) {
|
|
46
|
+
const resolved = normalise(name, entry);
|
|
47
|
+
const existing = exact.get(name);
|
|
48
|
+
if (existing && existing.module !== resolved.module) {
|
|
49
|
+
const conflict = conflicts.find((c) => c.name === name);
|
|
50
|
+
if (conflict) conflict.modules.push(resolved.module);
|
|
51
|
+
else conflicts.push({ name, modules: [existing.module, resolved.module] });
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
exact.set(name, resolved);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const cache = /* @__PURE__ */ new Map();
|
|
58
|
+
const resolve = (name) => {
|
|
59
|
+
if (cache.has(name)) return cache.get(name);
|
|
60
|
+
let result = exact.get(name);
|
|
61
|
+
if (!result) {
|
|
62
|
+
for (const rule of patterns) {
|
|
63
|
+
const match = name.match(new RegExp(rule.match.source, rule.match.flags.replace("g", "")));
|
|
64
|
+
if (!match) continue;
|
|
65
|
+
result = {
|
|
66
|
+
module: substitute(rule.module, match),
|
|
67
|
+
export: rule.export ? substitute(rule.export, match) : name
|
|
68
|
+
};
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
cache.set(name, result);
|
|
73
|
+
return result;
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
resolve,
|
|
77
|
+
names: () => [...exact.keys()],
|
|
78
|
+
conflicts: () => conflicts
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time component resolution.
|
|
3
|
+
*
|
|
4
|
+
* An unbound capitalised tag in a template is a name the compiler can resolve to a
|
|
5
|
+
* module, instead of an import the author has to write. The framework already does
|
|
6
|
+
* this for `Suspense`/`Portal`/`Router`, but through a hardcoded name set inside the
|
|
7
|
+
* Babel plugin: which cannot be extended by a UI library or an app, and cannot be
|
|
8
|
+
* configured per project.
|
|
9
|
+
*
|
|
10
|
+
* This is the configurable version of the same idea. It is deliberately a pure
|
|
11
|
+
* `name -> { module, export }` function with no filesystem access and no Babel
|
|
12
|
+
* dependency, because three separate consumers need exactly the same answer:
|
|
13
|
+
*
|
|
14
|
+
* - the compiler, to inject the import;
|
|
15
|
+
* - the TS plugin, to synthesise the import so hover/go-to-definition/rename work;
|
|
16
|
+
* - a codemod, to materialise imports back into source.
|
|
17
|
+
*
|
|
18
|
+
* Keeping resolution pure is what lets those three agree. Anything requiring the
|
|
19
|
+
* filesystem (directory conventions) belongs in a rule *builder* that produces a map,
|
|
20
|
+
* not in the resolver itself.
|
|
21
|
+
*/
|
|
22
|
+
/** Where a resolved component comes from. */
|
|
23
|
+
export interface ResolvedComponent {
|
|
24
|
+
module: string;
|
|
25
|
+
/** The export name, or `default`. */
|
|
26
|
+
export: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* An explicit name -> module map. This is what a component library ships
|
|
30
|
+
* (`Button -> @fluixi-ui/button`), generated from its own package list rather than
|
|
31
|
+
* hand-maintained.
|
|
32
|
+
*/
|
|
33
|
+
export interface ComponentMapRule {
|
|
34
|
+
components: Record<string, string | ResolvedComponent>;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A pattern rule. `$1`-style references in `module`/`export` are substituted from the
|
|
38
|
+
* match groups, so one rule can cover a family (`Icon(.+) -> @/icons/$1`).
|
|
39
|
+
*/
|
|
40
|
+
export interface ComponentPatternRule {
|
|
41
|
+
match: RegExp;
|
|
42
|
+
module: string;
|
|
43
|
+
/** Defaults to the tag name; use `'default'` for file-per-component layouts. */
|
|
44
|
+
export?: string;
|
|
45
|
+
}
|
|
46
|
+
export type ComponentResolverRule = ComponentMapRule | ComponentPatternRule;
|
|
47
|
+
/** Two rules claiming the same name: reported rather than silently first-wins. */
|
|
48
|
+
export interface ResolverConflict {
|
|
49
|
+
name: string;
|
|
50
|
+
modules: string[];
|
|
51
|
+
}
|
|
52
|
+
export interface ComponentResolver {
|
|
53
|
+
/** `undefined` when no rule claims the name. */
|
|
54
|
+
resolve: (name: string) => ResolvedComponent | undefined;
|
|
55
|
+
/** Every name the resolver can answer, for editor completion. */
|
|
56
|
+
names: () => string[];
|
|
57
|
+
/** Names claimed by more than one rule with different targets. */
|
|
58
|
+
conflicts: () => ResolverConflict[];
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Build a resolver from rules, in order.
|
|
62
|
+
*
|
|
63
|
+
* Map rules are flattened up front so lookup is a plain object read, resolution runs
|
|
64
|
+
* once per component reference per compile, so it sits on the hot path of every build.
|
|
65
|
+
* Pattern rules are tried afterwards, in declaration order, and only when no map rule
|
|
66
|
+
* matched: an explicit entry should always beat a pattern.
|
|
67
|
+
*/
|
|
68
|
+
export declare function createComponentResolver(rules?: readonly ComponentResolverRule[]): ComponentResolver;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* An unbound capitalised tag in a template is a name the compiler can resolve to a
|
|
5
5
|
* module, instead of an import the author has to write. The framework already does
|
|
6
6
|
* this for `Suspense`/`Portal`/`Router`, but through a hardcoded name set inside the
|
|
7
|
-
* Babel plugin
|
|
7
|
+
* Babel plugin: which cannot be extended by a UI library or an app, and cannot be
|
|
8
8
|
* configured per project.
|
|
9
9
|
*
|
|
10
10
|
* This is the configurable version of the same idea. It is deliberately a pure
|
|
@@ -44,7 +44,7 @@ export interface ComponentPatternRule {
|
|
|
44
44
|
export?: string;
|
|
45
45
|
}
|
|
46
46
|
export type ComponentResolverRule = ComponentMapRule | ComponentPatternRule;
|
|
47
|
-
/** Two rules claiming the same name
|
|
47
|
+
/** Two rules claiming the same name: reported rather than silently first-wins. */
|
|
48
48
|
export interface ResolverConflict {
|
|
49
49
|
name: string;
|
|
50
50
|
modules: string[];
|
|
@@ -60,7 +60,7 @@ export interface ComponentResolver {
|
|
|
60
60
|
/**
|
|
61
61
|
* Build a resolver from rules, in order.
|
|
62
62
|
*
|
|
63
|
-
* Map rules are flattened up front so lookup is a plain object read
|
|
63
|
+
* Map rules are flattened up front so lookup is a plain object read, resolution runs
|
|
64
64
|
* once per component reference per compile, so it sits on the hot path of every build.
|
|
65
65
|
* Pattern rules are tried afterwards, in declaration order, and only when no map rule
|
|
66
66
|
* matched: an explicit entry should always beat a pattern.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-resolver.d.ts","sourceRoot":"","sources":["../../src/resolve/component-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC;CACxD;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG,oBAAoB,CAAC;AAE5E,
|
|
1
|
+
{"version":3,"file":"component-resolver.d.ts","sourceRoot":"","sources":["../../src/resolve/component-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,qCAAqC;IACrC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,iBAAiB,CAAC,CAAC;CACxD;AAED;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,qBAAqB,GAAG,gBAAgB,GAAG,oBAAoB,CAAC;AAE5E,kFAAkF;AAClF,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,gDAAgD;IAChD,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,iBAAiB,GAAG,SAAS,CAAC;IACzD,iEAAiE;IACjE,KAAK,EAAE,MAAM,MAAM,EAAE,CAAC;IACtB,kEAAkE;IAClE,SAAS,EAAE,MAAM,gBAAgB,EAAE,CAAC;CACrC;AAiBD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,KAAK,GAAE,SAAS,qBAAqB,EAAO,GAC3C,iBAAiB,CAwDnB"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* An unbound capitalised tag in a template is a name the compiler can resolve to a
|
|
5
5
|
* module, instead of an import the author has to write. The framework already does
|
|
6
6
|
* this for `Suspense`/`Portal`/`Router`, but through a hardcoded name set inside the
|
|
7
|
-
* Babel plugin
|
|
7
|
+
* Babel plugin: which cannot be extended by a UI library or an app, and cannot be
|
|
8
8
|
* configured per project.
|
|
9
9
|
*
|
|
10
10
|
* This is the configurable version of the same idea. It is deliberately a pure
|
|
@@ -33,7 +33,7 @@ function normalise(name, entry) {
|
|
|
33
33
|
/**
|
|
34
34
|
* Build a resolver from rules, in order.
|
|
35
35
|
*
|
|
36
|
-
* Map rules are flattened up front so lookup is a plain object read
|
|
36
|
+
* Map rules are flattened up front so lookup is a plain object read, resolution runs
|
|
37
37
|
* once per component reference per compile, so it sits on the hot path of every build.
|
|
38
38
|
* Pattern rules are tried afterwards, in declaration order, and only when no map rule
|
|
39
39
|
* matched: an explicit entry should always beat a pattern.
|
|
@@ -54,7 +54,7 @@ export function createComponentResolver(rules = []) {
|
|
|
54
54
|
// Ambiguity is the failure mode that actually happens once a map holds
|
|
55
55
|
// ~80 common words (Card, Table, Text, Link). Silently taking the first
|
|
56
56
|
// rule would compile a working import of the wrong component, which is
|
|
57
|
-
// far worse to debug than a build error
|
|
57
|
+
// far worse to debug than a build error: so it is recorded and reported.
|
|
58
58
|
const conflict = conflicts.find((c) => c.name === name);
|
|
59
59
|
if (conflict)
|
|
60
60
|
conflict.modules.push(resolved.module);
|