@fluixi/compiler 1.0.0-alpha.83 → 1.0.0-alpha.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyze/expr-shape.cjs +62 -1
- package/dist/analyze/expr-shape.d.cts +14 -0
- package/dist/analyze/expr-shape.mjs +41 -1
- package/dist/analyze/intrinsics.cjs +80 -1
- package/dist/analyze/intrinsics.d.cts +66 -0
- package/dist/analyze/intrinsics.mjs +59 -1
- package/dist/analyze/paren.cjs +134 -0
- package/dist/analyze/paren.d.cts +23 -0
- package/dist/analyze/paren.d.ts +24 -0
- package/dist/analyze/paren.d.ts.map +1 -0
- package/dist/analyze/paren.js +168 -0
- package/dist/analyze/paren.mjs +113 -0
- package/dist/analyze/props-destructure.cjs +226 -1
- package/dist/analyze/props-destructure.d.cts +83 -0
- package/dist/analyze/props-destructure.mjs +205 -1
- package/dist/analyze/reactive-bindings.cjs +190 -1
- package/dist/analyze/reactive-bindings.d.cts +42 -0
- package/dist/analyze/reactive-bindings.mjs +167 -1
- package/dist/analyze/reactive-expr.cjs +38 -1
- package/dist/analyze/reactive-expr.d.cts +38 -0
- package/dist/analyze/reactive-expr.mjs +17 -1
- package/dist/analyze/static-graph.cjs +811 -1
- package/dist/analyze/static-graph.d.cts +102 -0
- package/dist/analyze/static-graph.mjs +793 -1
- package/dist/babel-NRW4EFTG.mjs +636 -0
- package/dist/chunk-3YKZ4GNH.mjs +11 -0
- package/dist/chunk-EZR7NZOY.mjs +1718 -0
- package/dist/chunk-FSSWUXUR.mjs +16 -0
- package/dist/chunk-MJV3UXIL.mjs +158 -0
- package/dist/chunk-R2VHAZAX.mjs +1078 -0
- package/dist/codegen/backend.cjs +18 -1
- package/dist/codegen/backend.d.cts +35 -0
- package/dist/codegen/backends/imperative.cjs +542 -1
- package/dist/codegen/backends/imperative.d.cts +11 -0
- package/dist/codegen/backends/imperative.d.ts.map +1 -1
- package/dist/codegen/backends/imperative.js +12 -8
- package/dist/codegen/backends/imperative.mjs +519 -1
- package/dist/codegen/contract.cjs +52 -1
- package/dist/codegen/contract.d.cts +24 -0
- package/dist/codegen/contract.mjs +31 -1
- package/dist/codegen/partial-template.cjs +176 -1
- package/dist/codegen/partial-template.d.cts +61 -0
- package/dist/codegen/partial-template.mjs +153 -1
- package/dist/codegen/serialize-static.cjs +125 -1
- package/dist/codegen/serialize-static.d.cts +38 -0
- package/dist/codegen/serialize-static.mjs +104 -1
- package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
- package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
- package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
- package/dist/frontend/babel/build-ir.cjs +1524 -1
- package/dist/frontend/babel/build-ir.d.cts +35 -0
- package/dist/frontend/babel/build-ir.mjs +1495 -1
- package/dist/frontend/babel/index.cjs +2186 -1
- package/dist/frontend/babel/index.d.cts +33 -0
- package/dist/frontend/babel/index.mjs +2156 -1
- package/dist/frontend/babel/lower-template.cjs +1507 -1
- package/dist/frontend/babel/lower-template.d.cts +23 -0
- package/dist/frontend/babel/lower-template.mjs +1478 -1
- package/dist/frontend/babel/plugin.cjs +2132 -1
- package/dist/frontend/babel/plugin.d.cts +95 -0
- package/dist/frontend/babel/plugin.mjs +2103 -1
- package/dist/frontend/babel/server-functions.cjs +110 -1
- package/dist/frontend/babel/server-functions.d.cts +10 -0
- package/dist/frontend/babel/server-functions.mjs +89 -1
- package/dist/frontend/babel/types.cjs +18 -1
- package/dist/frontend/babel/types.d.cts +33 -0
- package/dist/frontend/types.cjs +18 -1
- package/dist/frontend/types.d.cts +25 -0
- package/dist/frontend/vocabulary.cjs +98 -0
- package/dist/frontend/vocabulary.d.cts +79 -0
- package/dist/frontend/vocabulary.d.ts +80 -0
- package/dist/frontend/vocabulary.d.ts.map +1 -0
- package/dist/frontend/vocabulary.js +124 -0
- package/dist/frontend/vocabulary.mjs +77 -0
- package/dist/index.cjs +1594 -13
- package/dist/index.d.cts +27 -0
- package/dist/index.mjs +1574 -13
- package/dist/integrations.cjs +4307 -25
- package/dist/integrations.d.cts +215 -0
- package/dist/integrations.mjs +531 -17
- package/dist/ir/nodes.cjs +18 -1
- package/dist/ir/nodes.d.cts +168 -0
- package/dist/lower/compile-template.cjs +1356 -1
- package/dist/lower/compile-template.d.cts +69 -0
- package/dist/lower/compile-template.mjs +1336 -1
- package/dist/lower/jsx.cjs +529 -1
- package/dist/lower/jsx.d.cts +25 -0
- package/dist/lower/jsx.d.ts.map +1 -1
- package/dist/lower/jsx.js +2 -1
- package/dist/lower/jsx.mjs +506 -1
- package/dist/lower/template.cjs +1061 -1
- package/dist/lower/template.d.cts +53 -0
- package/dist/lower/template.d.ts.map +1 -1
- package/dist/lower/template.js +5 -4
- package/dist/lower/template.mjs +1042 -1
- package/dist/lower/text.cjs +42 -1
- package/dist/lower/text.d.cts +10 -0
- package/dist/lower/text.mjs +21 -1
- package/dist/optimize/analyze-static.cjs +112 -1
- package/dist/optimize/analyze-static.d.cts +39 -0
- package/dist/optimize/analyze-static.mjs +91 -1
- package/dist/optimize/collapse-strategies.cjs +90 -1
- package/dist/optimize/collapse-strategies.d.cts +30 -0
- package/dist/optimize/collapse-strategies.mjs +67 -1
- package/dist/options.cjs +33 -1
- package/dist/options.d.cts +39 -0
- package/dist/options.mjs +12 -1
- package/dist/resolve/builtins.cjs +73 -1
- package/dist/resolve/builtins.d.cts +68 -0
- package/dist/resolve/builtins.mjs +53 -1
- package/dist/resolve/component-globals.cjs +233 -13
- package/dist/resolve/component-globals.d.cts +80 -0
- package/dist/resolve/component-globals.mjs +210 -13
- package/dist/resolve/component-resolver.cjs +80 -1
- package/dist/resolve/component-resolver.d.cts +68 -0
- package/dist/resolve/component-resolver.mjs +59 -1
- package/dist/resolve/load-directive.cjs +93 -1
- package/dist/resolve/load-directive.d.cts +53 -0
- package/dist/resolve/load-directive.mjs +72 -1
- package/dist/resolve/resolve-ir.cjs +108 -1
- package/dist/resolve/resolve-ir.d.cts +53 -0
- package/dist/resolve/resolve-ir.mjs +85 -1
- package/dist/resolve/write-globals.cjs +318 -13
- package/dist/resolve/write-globals.d.cts +30 -0
- package/dist/resolve/write-globals.mjs +297 -13
- package/dist/server-fns-4ZXN6DYU.mjs +78 -0
- package/dist/server-functions-V6D6DRIA.mjs +82 -0
- package/dist/transform/bindings.cjs +71 -1
- package/dist/transform/bindings.d.cts +16 -0
- package/dist/transform/bindings.mjs +50 -1
- package/dist/transform/index.cjs +2732 -8
- package/dist/transform/index.d.cts +15 -0
- package/dist/transform/index.mjs +3773 -17
- package/dist/transform/intrinsics.cjs +216 -3
- package/dist/transform/intrinsics.d.cts +21 -0
- package/dist/transform/intrinsics.mjs +193 -3
- package/dist/transform/props.cjs +441 -3
- package/dist/transform/props.d.cts +45 -0
- package/dist/transform/props.mjs +1482 -12
- package/dist/transform/server-fn-id.cjs +35 -1
- package/dist/transform/server-fn-id.d.cts +9 -0
- package/dist/transform/server-fn-id.mjs +14 -1
- package/dist/transform/server-fns.cjs +114 -2
- package/dist/transform/server-fns.d.cts +12 -0
- package/dist/transform/server-fns.mjs +1155 -11
- package/dist/transform/source-locations.cjs +330 -1
- package/dist/transform/source-locations.d.cts +43 -0
- package/dist/transform/source-locations.mjs +307 -1
- package/dist/transform/templates.cjs +2701 -7
- package/dist/transform/templates.d.cts +69 -0
- package/dist/transform/templates.mjs +3743 -16
- package/dist/transform-BT4MMASR.mjs +893 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -1
- package/package.json +6 -5
- package/dist/babel-VXKH6MRQ.mjs +0 -1
- package/dist/chunk-3SAEGOMQ.mjs +0 -1
- package/dist/chunk-5KMMN5QP.mjs +0 -1
- package/dist/chunk-IBRM4W7I.mjs +0 -10
- package/dist/chunk-OHHZCYIQ.mjs +0 -1
- package/dist/chunk-YKZ54NVE.mjs +0 -1
- package/dist/server-fns-6QM243HC.mjs +0 -2
- package/dist/server-functions-E3LKCZ4R.mjs +0 -1
- package/dist/transform-C4ZXRVGP.mjs +0 -8
|
@@ -1 +1,73 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/resolve/builtins.ts
|
|
22
|
+
var builtins_exports = {};
|
|
23
|
+
__export(builtins_exports, {
|
|
24
|
+
BUILTIN_COMPONENTS: () => BUILTIN_COMPONENTS,
|
|
25
|
+
CORE_CONTROL_FLOW: () => CORE_CONTROL_FLOW,
|
|
26
|
+
DOM_CONTROL_FLOW: () => DOM_CONTROL_FLOW,
|
|
27
|
+
RESERVED_COMPONENTS: () => RESERVED_COMPONENTS,
|
|
28
|
+
ROUTER_COMPONENTS: () => ROUTER_COMPONENTS,
|
|
29
|
+
builtinComponentMap: () => builtinComponentMap,
|
|
30
|
+
builtinComponents: () => builtinComponents,
|
|
31
|
+
routerComponents: () => routerComponents
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(builtins_exports);
|
|
34
|
+
var DOM_CONTROL_FLOW = [
|
|
35
|
+
"Show",
|
|
36
|
+
"For",
|
|
37
|
+
"Index",
|
|
38
|
+
"Switch",
|
|
39
|
+
"Match",
|
|
40
|
+
"Portal",
|
|
41
|
+
"Dynamic",
|
|
42
|
+
"ErrorBoundary"
|
|
43
|
+
];
|
|
44
|
+
var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
|
|
45
|
+
var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
|
|
46
|
+
var BUILTIN_COMPONENTS = [
|
|
47
|
+
...DOM_CONTROL_FLOW,
|
|
48
|
+
...CORE_CONTROL_FLOW,
|
|
49
|
+
...ROUTER_COMPONENTS
|
|
50
|
+
];
|
|
51
|
+
var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
|
|
52
|
+
...DOM_CONTROL_FLOW,
|
|
53
|
+
...CORE_CONTROL_FLOW
|
|
54
|
+
]);
|
|
55
|
+
function builtinComponentMap(modules = {}) {
|
|
56
|
+
const {
|
|
57
|
+
controlFlowModule = "@fluixi/dom",
|
|
58
|
+
coreModule = "@fluixi/core",
|
|
59
|
+
routerModule = "@fluixi/core/router"
|
|
60
|
+
} = modules;
|
|
61
|
+
const map = {};
|
|
62
|
+
for (const name of DOM_CONTROL_FLOW) map[name] = controlFlowModule;
|
|
63
|
+
for (const name of CORE_CONTROL_FLOW) map[name] = coreModule;
|
|
64
|
+
for (const name of ROUTER_COMPONENTS) map[name] = routerModule;
|
|
65
|
+
return map;
|
|
66
|
+
}
|
|
67
|
+
function builtinComponents(modules = {}) {
|
|
68
|
+
return { components: builtinComponentMap(modules) };
|
|
69
|
+
}
|
|
70
|
+
function routerComponents(routerModule) {
|
|
71
|
+
const module2 = routerModule ?? "@fluixi/core/router";
|
|
72
|
+
return { components: Object.fromEntries(ROUTER_COMPONENTS.map((n) => [n, module2])) };
|
|
73
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The components the compiler supplies without an import, as data.
|
|
3
|
+
*
|
|
4
|
+
* Two different things have always been bundled into one hardcoded `Set` per group:
|
|
5
|
+
* *which module a name comes from*, and *whether the name has special lowering*. Only
|
|
6
|
+
* the first is interesting outside the compiler, and every tool needs it — the TS
|
|
7
|
+
* plugin, to resolve `<Show>` for hover and go-to-definition; the language server, to
|
|
8
|
+
* complete and validate tags inside `` html`…` ``; a codemod, to materialise imports.
|
|
9
|
+
* Having no published source, `@fluixi/ts-plugin` duplicated the list and pinned it
|
|
10
|
+
* with a test that fails when the two drift.
|
|
11
|
+
*
|
|
12
|
+
* So the names live here, shaped as {@link ComponentMapRule} so they compose with
|
|
13
|
+
* user-configured `resolve` rules, and the compiler keeps its own sets for the parts
|
|
14
|
+
* that are genuinely about codegen.
|
|
15
|
+
*
|
|
16
|
+
* The split matters: control-flow names cannot become ordinary rules. `Show`, `For`,
|
|
17
|
+
* `Index` and `Match` read a reactive *value* prop inside their own tracking scope, so
|
|
18
|
+
* the compiler emits that prop as a getter — without it `each={items()}` snapshots once
|
|
19
|
+
* and never updates. They are also exempted from `createMemo` wrapping and may be
|
|
20
|
+
* replaced outright by `optimizeControlFlowComponent`. A rule only injects an import,
|
|
21
|
+
* so converting them would keep the import and silently drop the reactivity.
|
|
22
|
+
*
|
|
23
|
+
* Router components have no such behaviour — every reference to them in the plugin is
|
|
24
|
+
* import plumbing — so they are a plain rule.
|
|
25
|
+
*/
|
|
26
|
+
import type { ComponentMapRule } from './component-resolver.cjs';
|
|
27
|
+
/** Where the built-in groups come from when the host does not override the module. */
|
|
28
|
+
export interface BuiltinModules {
|
|
29
|
+
/** Control flow that lives in the DOM package. Default `@fluixi/dom`. */
|
|
30
|
+
controlFlowModule?: string;
|
|
31
|
+
/** Control flow that only exists in core. Default `@fluixi/core`. */
|
|
32
|
+
coreModule?: string;
|
|
33
|
+
/** Router components. Default `@fluixi/core/router`. */
|
|
34
|
+
routerModule?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Control flow lowered against the DOM runtime. */
|
|
37
|
+
export declare const DOM_CONTROL_FLOW: readonly ["Show", "For", "Index", "Switch", "Match", "Portal", "Dynamic", "ErrorBoundary"];
|
|
38
|
+
/** Control flow that only `@fluixi/core` exports — importing it from dom resolves to nothing. */
|
|
39
|
+
export declare const CORE_CONTROL_FLOW: readonly ["Suspense", "SuspenseList", "Await"];
|
|
40
|
+
/**
|
|
41
|
+
* Router components.
|
|
42
|
+
*
|
|
43
|
+
* `Routes` is not a component (routing is `<Router routes={…}>`) and `lazy` is a call
|
|
44
|
+
* rather than a tag, so neither can be supplied this way.
|
|
45
|
+
*/
|
|
46
|
+
export declare const ROUTER_COMPONENTS: readonly ["Router", "Outlet", "Redirect", "Link"];
|
|
47
|
+
/** Every name the compiler supplies without an import. */
|
|
48
|
+
export declare const BUILTIN_COMPONENTS: readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* Names whose meaning is fixed by the compiler and cannot be reassigned by a rule.
|
|
51
|
+
*
|
|
52
|
+
* A rule naming one of these is a silent no-op — the compiler matches the built-in
|
|
53
|
+
* first and the tag renders control flow instead of the intended component, with no
|
|
54
|
+
* error. Rule authors should check against this set and report rather than emit.
|
|
55
|
+
*/
|
|
56
|
+
export declare const RESERVED_COMPONENTS: ReadonlySet<string>;
|
|
57
|
+
/** Name → module for every built-in, honouring host module overrides. */
|
|
58
|
+
export declare function builtinComponentMap(modules?: BuiltinModules): Record<string, string>;
|
|
59
|
+
/**
|
|
60
|
+
* The built-ins as a resolver rule, for tools that want one uniform lookup.
|
|
61
|
+
*
|
|
62
|
+
* Note this is the *naming* half only. Feeding it to the compiler would not make
|
|
63
|
+
* control flow work through resolution — the compiler still recognises those names
|
|
64
|
+
* itself, for the codegen reasons above.
|
|
65
|
+
*/
|
|
66
|
+
export declare function builtinComponents(modules?: BuiltinModules): ComponentMapRule;
|
|
67
|
+
/** Just the router group as a rule — the one group that is purely an import. */
|
|
68
|
+
export declare function routerComponents(routerModule?: string): ComponentMapRule;
|
|
@@ -1 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
/*! @fluixi/compiler v1.0.0-alpha.84 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
|
|
2
|
+
|
|
3
|
+
// src/resolve/builtins.ts
|
|
4
|
+
var DOM_CONTROL_FLOW = [
|
|
5
|
+
"Show",
|
|
6
|
+
"For",
|
|
7
|
+
"Index",
|
|
8
|
+
"Switch",
|
|
9
|
+
"Match",
|
|
10
|
+
"Portal",
|
|
11
|
+
"Dynamic",
|
|
12
|
+
"ErrorBoundary"
|
|
13
|
+
];
|
|
14
|
+
var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
|
|
15
|
+
var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
|
|
16
|
+
var BUILTIN_COMPONENTS = [
|
|
17
|
+
...DOM_CONTROL_FLOW,
|
|
18
|
+
...CORE_CONTROL_FLOW,
|
|
19
|
+
...ROUTER_COMPONENTS
|
|
20
|
+
];
|
|
21
|
+
var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
|
|
22
|
+
...DOM_CONTROL_FLOW,
|
|
23
|
+
...CORE_CONTROL_FLOW
|
|
24
|
+
]);
|
|
25
|
+
function builtinComponentMap(modules = {}) {
|
|
26
|
+
const {
|
|
27
|
+
controlFlowModule = "@fluixi/dom",
|
|
28
|
+
coreModule = "@fluixi/core",
|
|
29
|
+
routerModule = "@fluixi/core/router"
|
|
30
|
+
} = modules;
|
|
31
|
+
const map = {};
|
|
32
|
+
for (const name of DOM_CONTROL_FLOW) map[name] = controlFlowModule;
|
|
33
|
+
for (const name of CORE_CONTROL_FLOW) map[name] = coreModule;
|
|
34
|
+
for (const name of ROUTER_COMPONENTS) map[name] = routerModule;
|
|
35
|
+
return map;
|
|
36
|
+
}
|
|
37
|
+
function builtinComponents(modules = {}) {
|
|
38
|
+
return { components: builtinComponentMap(modules) };
|
|
39
|
+
}
|
|
40
|
+
function routerComponents(routerModule) {
|
|
41
|
+
const module = routerModule ?? "@fluixi/core/router";
|
|
42
|
+
return { components: Object.fromEntries(ROUTER_COMPONENTS.map((n) => [n, module])) };
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
BUILTIN_COMPONENTS,
|
|
46
|
+
CORE_CONTROL_FLOW,
|
|
47
|
+
DOM_CONTROL_FLOW,
|
|
48
|
+
RESERVED_COMPONENTS,
|
|
49
|
+
ROUTER_COMPONENTS,
|
|
50
|
+
builtinComponentMap,
|
|
51
|
+
builtinComponents,
|
|
52
|
+
routerComponents
|
|
53
|
+
};
|
|
@@ -1,22 +1,242 @@
|
|
|
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-globals.ts
|
|
21
|
+
var component_globals_exports = {};
|
|
22
|
+
__export(component_globals_exports, {
|
|
23
|
+
componentGlobals: () => componentGlobals
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(component_globals_exports);
|
|
26
|
+
|
|
27
|
+
// src/resolve/component-resolver.ts
|
|
28
|
+
var isMapRule = (rule) => "components" in rule;
|
|
29
|
+
function substitute(template, match) {
|
|
30
|
+
return template.replace(/\$(\d+)/g, (whole, index) => {
|
|
31
|
+
const group = match[Number(index)];
|
|
32
|
+
return group ?? whole;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function normalise(name, entry) {
|
|
36
|
+
return typeof entry === "string" ? { module: entry, export: name } : entry;
|
|
37
|
+
}
|
|
38
|
+
function createComponentResolver(rules = []) {
|
|
39
|
+
const exact = /* @__PURE__ */ new Map();
|
|
40
|
+
const conflicts = [];
|
|
41
|
+
const patterns = [];
|
|
42
|
+
for (const rule of rules) {
|
|
43
|
+
if (!isMapRule(rule)) {
|
|
44
|
+
patterns.push(rule);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
for (const [name, entry] of Object.entries(rule.components)) {
|
|
48
|
+
const resolved = normalise(name, entry);
|
|
49
|
+
const existing = exact.get(name);
|
|
50
|
+
if (existing && existing.module !== resolved.module) {
|
|
51
|
+
const conflict = conflicts.find((c) => c.name === name);
|
|
52
|
+
if (conflict) conflict.modules.push(resolved.module);
|
|
53
|
+
else conflicts.push({ name, modules: [existing.module, resolved.module] });
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
exact.set(name, resolved);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const cache = /* @__PURE__ */ new Map();
|
|
60
|
+
const resolve = (name) => {
|
|
61
|
+
if (cache.has(name)) return cache.get(name);
|
|
62
|
+
let result = exact.get(name);
|
|
63
|
+
if (!result) {
|
|
64
|
+
for (const rule of patterns) {
|
|
65
|
+
const match = name.match(new RegExp(rule.match.source, rule.match.flags.replace("g", "")));
|
|
66
|
+
if (!match) continue;
|
|
67
|
+
result = {
|
|
68
|
+
module: substitute(rule.module, match),
|
|
69
|
+
export: rule.export ? substitute(rule.export, match) : name
|
|
70
|
+
};
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
cache.set(name, result);
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
return {
|
|
78
|
+
resolve,
|
|
79
|
+
names: () => [...exact.keys()],
|
|
80
|
+
conflicts: () => conflicts
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// src/resolve/builtins.ts
|
|
85
|
+
var DOM_CONTROL_FLOW = [
|
|
86
|
+
"Show",
|
|
87
|
+
"For",
|
|
88
|
+
"Index",
|
|
89
|
+
"Switch",
|
|
90
|
+
"Match",
|
|
91
|
+
"Portal",
|
|
92
|
+
"Dynamic",
|
|
93
|
+
"ErrorBoundary"
|
|
94
|
+
];
|
|
95
|
+
var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
|
|
96
|
+
var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
|
|
97
|
+
var BUILTIN_COMPONENTS = [
|
|
98
|
+
...DOM_CONTROL_FLOW,
|
|
99
|
+
...CORE_CONTROL_FLOW,
|
|
100
|
+
...ROUTER_COMPONENTS
|
|
101
|
+
];
|
|
102
|
+
var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
|
|
103
|
+
...DOM_CONTROL_FLOW,
|
|
104
|
+
...CORE_CONTROL_FLOW
|
|
105
|
+
]);
|
|
106
|
+
function builtinComponentMap(modules = {}) {
|
|
107
|
+
const {
|
|
108
|
+
controlFlowModule = "@fluixi/dom",
|
|
109
|
+
coreModule = "@fluixi/core",
|
|
110
|
+
routerModule = "@fluixi/core/router"
|
|
111
|
+
} = modules;
|
|
112
|
+
const map = {};
|
|
113
|
+
for (const name of DOM_CONTROL_FLOW) map[name] = controlFlowModule;
|
|
114
|
+
for (const name of CORE_CONTROL_FLOW) map[name] = coreModule;
|
|
115
|
+
for (const name of ROUTER_COMPONENTS) map[name] = routerModule;
|
|
116
|
+
return map;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/analyze/intrinsics.ts
|
|
120
|
+
var REACTIVE_MODULE = "@fluixi/reactive/signal";
|
|
121
|
+
var INTRINSICS = {
|
|
122
|
+
$signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
|
|
123
|
+
$memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
|
|
124
|
+
$effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
|
|
125
|
+
$store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
|
|
126
|
+
$resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
|
|
127
|
+
// No short runtime form for these yet, so the intrinsic stands for the `create*`
|
|
128
|
+
// name. Still worth having — no import to write — and when a shorter form is
|
|
129
|
+
// designed, the change is this line rather than a compiler pass.
|
|
130
|
+
$selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
131
|
+
$deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
|
|
132
|
+
// Not value constructors, but the compiler has to know them: they change what a read
|
|
133
|
+
// does. `untrack` suppresses dependency collection, which is exactly the kind of thing
|
|
134
|
+
// dependency analysis must not guess at.
|
|
135
|
+
$untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
|
|
136
|
+
$untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" }
|
|
137
|
+
};
|
|
138
|
+
var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
|
|
139
|
+
|
|
140
|
+
// src/resolve/component-globals.ts
|
|
141
|
+
var DOM_GLOBALS = /* @__PURE__ */ new Set([
|
|
142
|
+
"Text",
|
|
143
|
+
"Image",
|
|
144
|
+
"Option",
|
|
145
|
+
"Audio",
|
|
146
|
+
"Comment",
|
|
147
|
+
"Range",
|
|
148
|
+
"Selection",
|
|
149
|
+
"Notification",
|
|
150
|
+
"Event",
|
|
151
|
+
"Document",
|
|
152
|
+
"Element",
|
|
153
|
+
"Node",
|
|
154
|
+
"Screen",
|
|
155
|
+
"Window",
|
|
156
|
+
"Location",
|
|
157
|
+
"History",
|
|
158
|
+
"Storage",
|
|
159
|
+
"Response",
|
|
160
|
+
"Request",
|
|
161
|
+
"Headers"
|
|
162
|
+
]);
|
|
163
|
+
function packageOf(specifier) {
|
|
164
|
+
if (specifier.startsWith(".") || specifier.startsWith("/")) return void 0;
|
|
165
|
+
if (/^[~@]\//.test(specifier)) return void 0;
|
|
166
|
+
const parts = specifier.split("/");
|
|
167
|
+
return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
|
|
168
|
+
}
|
|
169
|
+
function namespaceAlias(module2) {
|
|
170
|
+
return `_${module2.replace(/[^A-Za-z0-9]/g, "_")}`;
|
|
171
|
+
}
|
|
172
|
+
function componentGlobals(rules, options = {}) {
|
|
173
|
+
const {
|
|
174
|
+
available: availableList,
|
|
175
|
+
builtins = true,
|
|
176
|
+
intrinsics = true,
|
|
177
|
+
generator = "@fluixi/compiler",
|
|
178
|
+
specifier = (module2) => module2
|
|
179
|
+
} = options;
|
|
180
|
+
const all = [...rules];
|
|
181
|
+
if (builtins) {
|
|
182
|
+
all.push({ components: builtinComponentMap() });
|
|
183
|
+
}
|
|
184
|
+
const resolver = createComponentResolver(all);
|
|
185
|
+
const available = availableList ? new Set(availableList) : void 0;
|
|
186
|
+
const declared = [];
|
|
187
|
+
const shadowedByDom = [];
|
|
188
|
+
const unavailable = [];
|
|
189
|
+
const resolved = /* @__PURE__ */ new Map();
|
|
190
|
+
for (const name of [...resolver.names()].sort()) {
|
|
191
|
+
const target = resolver.resolve(name);
|
|
192
|
+
if (!target) continue;
|
|
193
|
+
const pkg = packageOf(target.module);
|
|
194
|
+
if (DOM_GLOBALS.has(name)) shadowedByDom.push(name);
|
|
195
|
+
else if (available && pkg && !available.has(pkg)) unavailable.push(name);
|
|
196
|
+
else {
|
|
197
|
+
declared.push(name);
|
|
198
|
+
resolved.set(name, target);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const intrinsicModules = intrinsics ? [...new Set(Object.values(INTRINSICS).map((i) => i.module))] : [];
|
|
202
|
+
const modules = [
|
|
203
|
+
.../* @__PURE__ */ new Set([...declared.map((name) => resolved.get(name).module), ...intrinsicModules])
|
|
204
|
+
].sort();
|
|
205
|
+
const imports = modules.map(
|
|
206
|
+
(m) => `import * as ${namespaceAlias(m)} from '${specifier(m)}';`
|
|
207
|
+
);
|
|
208
|
+
const lines = declared.map((name) => {
|
|
209
|
+
const target = resolved.get(name);
|
|
210
|
+
const ns = namespaceAlias(target.module);
|
|
211
|
+
return target.export === "default" ? ` const ${name}: typeof ${ns}.default;` : ` export import ${name} = ${ns}.${target.export};`;
|
|
212
|
+
});
|
|
213
|
+
const note = shadowedByDom.length > 0 ? `//
|
|
2
214
|
// Import these explicitly — lib.dom already declares the name, so an ambient
|
|
3
215
|
// declaration cannot win:
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
216
|
+
` + shadowedByDom.map((n) => {
|
|
217
|
+
const module2 = resolver.resolve(n)?.module;
|
|
218
|
+
return `// import { ${n} } from '${module2 ? specifier(module2) : ""}';
|
|
219
|
+
`;
|
|
220
|
+
}).join("") : "";
|
|
221
|
+
const intrinsicLines = intrinsics ? Object.entries(INTRINSICS).map(
|
|
222
|
+
([name, intrinsic]) => ` const ${name}: typeof ${namespaceAlias(intrinsic.module)}.${intrinsic.export};`
|
|
223
|
+
) : [];
|
|
224
|
+
const patternRules = rules.filter((rule) => "match" in rule).length;
|
|
225
|
+
const patternNote = patternRules > 0 ? `//
|
|
226
|
+
// ${patternRules} pattern rule${patternRules === 1 ? "" : "s"} cannot be declared:
|
|
7
227
|
// a pattern matches unboundedly many names, so there is no list to emit. Those
|
|
8
228
|
// tags still resolve at build time; declare them by hand if the editor needs them.
|
|
9
|
-
|
|
229
|
+
` : "";
|
|
230
|
+
const source = `// GENERATED by ${generator} — do not edit.
|
|
10
231
|
//
|
|
11
232
|
// The components \`resolve\` supplies without an import. This describes what the
|
|
12
233
|
// compiler already does; it does not enable it.
|
|
13
|
-
|
|
14
|
-
${
|
|
15
|
-
`)
|
|
16
|
-
`:`
|
|
17
|
-
`)+`
|
|
234
|
+
` + note + patternNote + (imports.length > 0 ? `
|
|
235
|
+
${imports.join("\n")}
|
|
236
|
+
` : "\n") + `
|
|
18
237
|
declare global {
|
|
19
|
-
${[...
|
|
20
|
-
|
|
238
|
+
${[...lines, ...intrinsicLines].join("\n")}
|
|
239
|
+
}
|
|
240
|
+
`;
|
|
241
|
+
return { source, declared, shadowedByDom, unavailable, patternRules };
|
|
21
242
|
}
|
|
22
|
-
`,declared:m,shadowedByDom:d,unavailable:R,patternRules:x}}
|
|
@@ -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;
|