@fluixi/compiler 1.0.0-alpha.82 → 1.0.0-alpha.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/analyze/expr-shape.cjs +62 -1
  2. package/dist/analyze/expr-shape.d.cts +14 -0
  3. package/dist/analyze/expr-shape.mjs +41 -1
  4. package/dist/analyze/intrinsics.cjs +80 -1
  5. package/dist/analyze/intrinsics.d.cts +66 -0
  6. package/dist/analyze/intrinsics.mjs +59 -1
  7. package/dist/analyze/paren.cjs +134 -0
  8. package/dist/analyze/paren.d.cts +23 -0
  9. package/dist/analyze/paren.d.ts +24 -0
  10. package/dist/analyze/paren.d.ts.map +1 -0
  11. package/dist/analyze/paren.js +168 -0
  12. package/dist/analyze/paren.mjs +113 -0
  13. package/dist/analyze/props-destructure.cjs +226 -1
  14. package/dist/analyze/props-destructure.d.cts +83 -0
  15. package/dist/analyze/props-destructure.mjs +205 -1
  16. package/dist/analyze/reactive-bindings.cjs +190 -1
  17. package/dist/analyze/reactive-bindings.d.cts +42 -0
  18. package/dist/analyze/reactive-bindings.mjs +167 -1
  19. package/dist/analyze/reactive-expr.cjs +38 -1
  20. package/dist/analyze/reactive-expr.d.cts +38 -0
  21. package/dist/analyze/reactive-expr.mjs +17 -1
  22. package/dist/analyze/static-graph.cjs +811 -0
  23. package/dist/analyze/static-graph.d.cts +102 -0
  24. package/dist/analyze/static-graph.d.ts +103 -0
  25. package/dist/analyze/static-graph.d.ts.map +1 -0
  26. package/dist/analyze/static-graph.js +869 -0
  27. package/dist/analyze/static-graph.mjs +793 -0
  28. package/dist/babel-NRW4EFTG.mjs +636 -0
  29. package/dist/chunk-3YKZ4GNH.mjs +11 -0
  30. package/dist/chunk-EZR7NZOY.mjs +1718 -0
  31. package/dist/chunk-FSSWUXUR.mjs +16 -0
  32. package/dist/chunk-MJV3UXIL.mjs +158 -0
  33. package/dist/chunk-R2VHAZAX.mjs +1078 -0
  34. package/dist/codegen/backend.cjs +18 -1
  35. package/dist/codegen/backend.d.cts +35 -0
  36. package/dist/codegen/backends/imperative.cjs +542 -1
  37. package/dist/codegen/backends/imperative.d.cts +11 -0
  38. package/dist/codegen/backends/imperative.d.ts.map +1 -1
  39. package/dist/codegen/backends/imperative.js +68 -13
  40. package/dist/codegen/backends/imperative.mjs +519 -1
  41. package/dist/codegen/contract.cjs +52 -1
  42. package/dist/codegen/contract.d.cts +24 -0
  43. package/dist/codegen/contract.mjs +31 -1
  44. package/dist/codegen/partial-template.cjs +176 -1
  45. package/dist/codegen/partial-template.d.cts +61 -0
  46. package/dist/codegen/partial-template.mjs +153 -1
  47. package/dist/codegen/serialize-static.cjs +125 -1
  48. package/dist/codegen/serialize-static.d.cts +38 -0
  49. package/dist/codegen/serialize-static.d.ts +16 -0
  50. package/dist/codegen/serialize-static.d.ts.map +1 -1
  51. package/dist/codegen/serialize-static.js +25 -0
  52. package/dist/codegen/serialize-static.mjs +104 -1
  53. package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
  54. package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
  55. package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
  56. package/dist/frontend/babel/build-ir.cjs +1524 -1
  57. package/dist/frontend/babel/build-ir.d.cts +35 -0
  58. package/dist/frontend/babel/build-ir.mjs +1495 -1
  59. package/dist/frontend/babel/index.cjs +2186 -1
  60. package/dist/frontend/babel/index.d.cts +33 -0
  61. package/dist/frontend/babel/index.mjs +2156 -1
  62. package/dist/frontend/babel/lower-template.cjs +1507 -1
  63. package/dist/frontend/babel/lower-template.d.cts +23 -0
  64. package/dist/frontend/babel/lower-template.mjs +1478 -1
  65. package/dist/frontend/babel/plugin.cjs +2132 -1
  66. package/dist/frontend/babel/plugin.d.cts +95 -0
  67. package/dist/frontend/babel/plugin.mjs +2103 -1
  68. package/dist/frontend/babel/server-functions.cjs +110 -1
  69. package/dist/frontend/babel/server-functions.d.cts +10 -0
  70. package/dist/frontend/babel/server-functions.mjs +89 -1
  71. package/dist/frontend/babel/types.cjs +18 -1
  72. package/dist/frontend/babel/types.d.cts +33 -0
  73. package/dist/frontend/types.cjs +18 -1
  74. package/dist/frontend/types.d.cts +25 -0
  75. package/dist/frontend/vocabulary.cjs +98 -0
  76. package/dist/frontend/vocabulary.d.cts +79 -0
  77. package/dist/frontend/vocabulary.d.ts +80 -0
  78. package/dist/frontend/vocabulary.d.ts.map +1 -0
  79. package/dist/frontend/vocabulary.js +124 -0
  80. package/dist/frontend/vocabulary.mjs +77 -0
  81. package/dist/index.cjs +1594 -13
  82. package/dist/index.d.cts +27 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +3 -0
  85. package/dist/index.mjs +1574 -13
  86. package/dist/integrations.cjs +4307 -25
  87. package/dist/integrations.d.cts +215 -0
  88. package/dist/integrations.d.ts +16 -0
  89. package/dist/integrations.d.ts.map +1 -1
  90. package/dist/integrations.js +21 -2
  91. package/dist/integrations.mjs +531 -17
  92. package/dist/ir/nodes.cjs +18 -1
  93. package/dist/ir/nodes.d.cts +168 -0
  94. package/dist/ir/nodes.d.ts +46 -0
  95. package/dist/ir/nodes.d.ts.map +1 -1
  96. package/dist/lower/compile-template.cjs +1356 -1
  97. package/dist/lower/compile-template.d.cts +69 -0
  98. package/dist/lower/compile-template.d.ts +12 -0
  99. package/dist/lower/compile-template.d.ts.map +1 -1
  100. package/dist/lower/compile-template.js +5 -1
  101. package/dist/lower/compile-template.mjs +1336 -1
  102. package/dist/lower/jsx.cjs +529 -1
  103. package/dist/lower/jsx.d.cts +25 -0
  104. package/dist/lower/jsx.d.ts +2 -0
  105. package/dist/lower/jsx.d.ts.map +1 -1
  106. package/dist/lower/jsx.js +27 -4
  107. package/dist/lower/jsx.mjs +506 -1
  108. package/dist/lower/template.cjs +1061 -1
  109. package/dist/lower/template.d.cts +53 -0
  110. package/dist/lower/template.d.ts +14 -1
  111. package/dist/lower/template.d.ts.map +1 -1
  112. package/dist/lower/template.js +106 -19
  113. package/dist/lower/template.mjs +1042 -1
  114. package/dist/lower/text.cjs +42 -1
  115. package/dist/lower/text.d.cts +10 -0
  116. package/dist/lower/text.mjs +21 -1
  117. package/dist/optimize/analyze-static.cjs +112 -1
  118. package/dist/optimize/analyze-static.d.cts +39 -0
  119. package/dist/optimize/analyze-static.mjs +91 -1
  120. package/dist/optimize/collapse-strategies.cjs +90 -1
  121. package/dist/optimize/collapse-strategies.d.cts +30 -0
  122. package/dist/optimize/collapse-strategies.mjs +67 -1
  123. package/dist/options.cjs +33 -1
  124. package/dist/options.d.cts +39 -0
  125. package/dist/options.mjs +12 -1
  126. package/dist/resolve/builtins.cjs +73 -1
  127. package/dist/resolve/builtins.d.cts +68 -0
  128. package/dist/resolve/builtins.mjs +53 -1
  129. package/dist/resolve/component-globals.cjs +233 -13
  130. package/dist/resolve/component-globals.d.cts +80 -0
  131. package/dist/resolve/component-globals.mjs +210 -13
  132. package/dist/resolve/component-resolver.cjs +80 -1
  133. package/dist/resolve/component-resolver.d.cts +68 -0
  134. package/dist/resolve/component-resolver.mjs +59 -1
  135. package/dist/resolve/load-directive.cjs +93 -1
  136. package/dist/resolve/load-directive.d.cts +53 -0
  137. package/dist/resolve/load-directive.mjs +72 -1
  138. package/dist/resolve/resolve-ir.cjs +108 -1
  139. package/dist/resolve/resolve-ir.d.cts +53 -0
  140. package/dist/resolve/resolve-ir.mjs +85 -1
  141. package/dist/resolve/write-globals.cjs +318 -13
  142. package/dist/resolve/write-globals.d.cts +30 -0
  143. package/dist/resolve/write-globals.mjs +297 -13
  144. package/dist/server-fns-4ZXN6DYU.mjs +78 -0
  145. package/dist/server-functions-V6D6DRIA.mjs +82 -0
  146. package/dist/transform/bindings.cjs +71 -1
  147. package/dist/transform/bindings.d.cts +16 -0
  148. package/dist/transform/bindings.mjs +50 -1
  149. package/dist/transform/index.cjs +2732 -8
  150. package/dist/transform/index.d.cts +15 -0
  151. package/dist/transform/index.mjs +3773 -17
  152. package/dist/transform/intrinsics.cjs +216 -3
  153. package/dist/transform/intrinsics.d.cts +21 -0
  154. package/dist/transform/intrinsics.mjs +193 -3
  155. package/dist/transform/props.cjs +441 -3
  156. package/dist/transform/props.d.cts +45 -0
  157. package/dist/transform/props.mjs +1482 -12
  158. package/dist/transform/server-fn-id.cjs +35 -1
  159. package/dist/transform/server-fn-id.d.cts +9 -0
  160. package/dist/transform/server-fn-id.mjs +14 -1
  161. package/dist/transform/server-fns.cjs +114 -2
  162. package/dist/transform/server-fns.d.cts +12 -0
  163. package/dist/transform/server-fns.mjs +1155 -11
  164. package/dist/transform/source-locations.cjs +330 -0
  165. package/dist/transform/source-locations.d.cts +43 -0
  166. package/dist/transform/source-locations.d.ts +44 -0
  167. package/dist/transform/source-locations.d.ts.map +1 -0
  168. package/dist/transform/source-locations.js +238 -0
  169. package/dist/transform/source-locations.mjs +307 -0
  170. package/dist/transform/templates.cjs +2701 -7
  171. package/dist/transform/templates.d.cts +69 -0
  172. package/dist/transform/templates.d.ts +12 -4
  173. package/dist/transform/templates.d.ts.map +1 -1
  174. package/dist/transform/templates.js +72 -7
  175. package/dist/transform/templates.mjs +3743 -16
  176. package/dist/transform-BT4MMASR.mjs +893 -0
  177. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  178. package/package.json +6 -5
  179. package/dist/babel-4JUDAR2G.mjs +0 -1
  180. package/dist/chunk-3SAEGOMQ.mjs +0 -1
  181. package/dist/chunk-IBRM4W7I.mjs +0 -10
  182. package/dist/chunk-OHHZCYIQ.mjs +0 -1
  183. package/dist/chunk-PVR2SN3B.mjs +0 -1
  184. package/dist/chunk-QUIYULS2.mjs +0 -1
  185. package/dist/chunk-YR3SAEO7.mjs +0 -1
  186. package/dist/server-fns-6QM243HC.mjs +0 -2
  187. package/dist/server-functions-E3LKCZ4R.mjs +0 -1
  188. package/dist/transform-5WC4FWJE.mjs +0 -8
@@ -1,22 +1,219 @@
1
- var j=t=>"components"in t;function O(t,o){return t.replace(/\$(\d+)/g,(a,u)=>o[Number(u)]??a)}function _(t,o){return typeof o=="string"?{module:o,export:t}:o}function S(t=[]){let o=new Map,a=[],u=[];for(let n of t){if(!j(n)){u.push(n);continue}for(let[r,l]of Object.entries(n.components)){let c=_(r,l),m=o.get(r);if(m&&m.module!==c.module){let d=a.find(R=>R.name===r);d?d.modules.push(c.module):a.push({name:r,modules:[m.module,c.module]});continue}o.set(r,c)}}let i=new Map;return{resolve:n=>{if(i.has(n))return i.get(n);let r=o.get(n);if(!r)for(let l of u){let c=n.match(new RegExp(l.match.source,l.match.flags.replace("g","")));if(c){r={module:O(l.module,c),export:l.export?O(l.export,c):n};break}}return i.set(n,r),r},names:()=>[...o.keys()],conflicts:()=>a}}var C=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],b=["Suspense","SuspenseList","Await"],$=["Router","Outlet","Redirect","Link"],G=[...C,...b,...$],W=new Set([...C,...b]);function E(t={}){let{controlFlowModule:o="@fluixi/dom",coreModule:a="@fluixi/core",routerModule:u="@fluixi/core/router"}=t,i={};for(let p of C)i[p]=o;for(let p of b)i[p]=a;for(let p of $)i[p]=u;return i}var f="@fluixi/reactive/signal",h={$signal:{export:"signal",module:f,returns:"signal-handle"},$memo:{export:"memo",module:f,returns:"memo-handle"},$effect:{export:"effect",module:f,returns:"effect"},$store:{export:"store",module:"@fluixi/reactive/store",returns:"store-handle"},$resource:{export:"resource",module:f,returns:"resource-handle"},$selector:{export:"createSelector",module:f,returns:"memo-accessor"},$deferred:{export:"createDeferred",module:f,returns:"memo-accessor"},$untrack:{export:"untrack",module:f,returns:"plain"},$untrackStore:{export:"untrackStore",module:"@fluixi/reactive/store",returns:"plain"}};var U=new RegExp(`\\$(?:${Object.keys(h).map(t=>t.slice(1)).join("|")})\\s*\\(`);var D=new Set(["Text","Image","Option","Audio","Comment","Range","Selection","Notification","Event","Document","Element","Node","Screen","Window","Location","History","Storage","Response","Request","Headers"]);function P(t){if(t.startsWith(".")||t.startsWith("/")||/^[~@]\//.test(t))return;let o=t.split("/");return t.startsWith("@")?o.slice(0,2).join("/"):o[0]}function M(t){return`_${t.replace(/[^A-Za-z0-9]/g,"_")}`}function z(t,o={}){let{available:a,builtins:u=!0,intrinsics:i=!0,generator:p="@fluixi/compiler",specifier:n=e=>e}=o,r=[...t];u&&r.push({components:E()});let l=S(r),c=a?new Set(a):void 0,m=[],d=[],R=[],v=new Map;for(let e of[...l.names()].sort()){let s=l.resolve(e);if(!s)continue;let g=P(s.module);D.has(e)?d.push(e):c&&g&&!c.has(g)?R.push(e):(m.push(e),v.set(e,s))}let I=i?[...new Set(Object.values(h).map(e=>e.module))]:[],y=[...new Set([...m.map(e=>v.get(e).module),...I])].sort().map(e=>`import * as ${M(e)} from '${n(e)}';`),w=m.map(e=>{let s=v.get(e),g=M(s.module);return s.export==="default"?` const ${e}: typeof ${g}.default;`:` export import ${e} = ${g}.${s.export};`}),N=d.length>0?`//
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 ? `//
2
188
  // Import these explicitly — lib.dom already declares the name, so an ambient
3
189
  // declaration cannot win:
4
- `+d.map(e=>{let s=l.resolve(e)?.module;return`// import { ${e} } from '${s?n(s):""}';
5
- `}).join(""):"",T=i?Object.entries(h).map(([e,s])=>` const ${e}: typeof ${M(s.module)}.${s.export};`):[],x=t.filter(e=>"match"in e).length,L=x>0?`//
6
- // ${x} pattern rule${x===1?"":"s"} cannot be declared:
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
- `:"";return{source:`// GENERATED by ${p} — do not edit.
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
- `+N+L+(y.length>0?`
14
- ${y.join(`
15
- `)}
16
- `:`
17
- `)+`
208
+ ` + note + patternNote + (imports.length > 0 ? `
209
+ ${imports.join("\n")}
210
+ ` : "\n") + `
18
211
  declare global {
19
- ${[...w,...T].join(`
20
- `)}
212
+ ${[...lines, ...intrinsicLines].join("\n")}
213
+ }
214
+ `;
215
+ return { source, declared, shadowedByDom, unavailable, patternRules };
21
216
  }
22
- `,declared:m,shadowedByDom:d,unavailable:R,patternRules:x}}export{z as componentGlobals};
217
+ export {
218
+ componentGlobals
219
+ };
@@ -1 +1,80 @@
1
- "use strict";var u=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var C=(o,e)=>{for(var n in e)u(o,n,{get:e[n],enumerable:!0})},v=(o,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of g(e))!R.call(o,t)&&t!==n&&u(o,t,{get:()=>e[t],enumerable:!(i=d(e,t))||i.enumerable});return o};var x=o=>v(u({},"__esModule",{value:!0}),o);var y={};C(y,{createComponentResolver:()=>b});module.exports=x(y);var h=o=>"components"in o;function a(o,e){return o.replace(/\$(\d+)/g,(n,i)=>e[Number(i)]??n)}function M(o,e){return typeof e=="string"?{module:e,export:o}:e}function b(o=[]){let e=new Map,n=[],i=[];for(let r of o){if(!h(r)){i.push(r);continue}for(let[s,p]of Object.entries(r.components)){let l=M(s,p),c=e.get(s);if(c&&c.module!==l.module){let m=n.find(f=>f.name===s);m?m.modules.push(l.module):n.push({name:s,modules:[c.module,l.module]});continue}e.set(s,l)}}let t=new Map;return{resolve:r=>{if(t.has(r))return t.get(r);let s=e.get(r);if(!s)for(let p of i){let l=r.match(new RegExp(p.match.source,p.match.flags.replace("g","")));if(l){s={module:a(p.module,l),export:p.export?a(p.export,l):r};break}}return t.set(r,s),s},names:()=>[...e.keys()],conflicts:()=>n}}
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;
@@ -1 +1,59 @@
1
- var f=r=>"components"in r;function m(r,e){return r.replace(/\$(\d+)/g,(l,i)=>e[Number(i)]??l)}function d(r,e){return typeof e=="string"?{module:e,export:r}:e}function R(r=[]){let e=new Map,l=[],i=[];for(let o of r){if(!f(o)){i.push(o);continue}for(let[n,s]of Object.entries(o.components)){let t=d(n,s),c=e.get(n);if(c&&c.module!==t.module){let u=l.find(a=>a.name===n);u?u.modules.push(t.module):l.push({name:n,modules:[c.module,t.module]});continue}e.set(n,t)}}let p=new Map;return{resolve:o=>{if(p.has(o))return p.get(o);let n=e.get(o);if(!n)for(let s of i){let t=o.match(new RegExp(s.match.source,s.match.flags.replace("g","")));if(t){n={module:m(s.module,t),export:s.export?m(s.export,t):o};break}}return p.set(o,n),n},names:()=>[...e.keys()],conflicts:()=>l}}export{R as createComponentResolver};
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
+ export {
58
+ createComponentResolver
59
+ };
@@ -1 +1,93 @@
1
- "use strict";var o=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var k=(e,n)=>{for(var t in n)o(e,t,{get:n[t],enumerable:!0})},p=(e,n,t,a)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of g(n))!u.call(e,r)&&r!==t&&o(e,r,{get:()=>n[r],enumerable:!(a=l(n,r))||a.enumerable});return e};var w=e=>p(o({},"__esModule",{value:!0}),e);var y={};k(y,{DEFAULT_INTERACTION_EVENTS:()=>c,EAGER:()=>d,LoadDirectiveError:()=>i,isDeferred:()=>m,isLoadDirective:()=>v,parseLoadDirective:()=>f,strategyKey:()=>x});module.exports=w(y);var d={kind:"eager"},c=["pointerdown","focusin","keydown"],s=new Set(["eager","idle","visible","interaction","media","never"]),i=class extends Error{};function v(e){return e.startsWith("load:")}function f(e,n){let t=e.slice(5);if(!s.has(t))throw new i(`Unknown load strategy 'load:${t}'. Expected one of ${[...s].join(", ")}.`);switch(t){case"eager":return d;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return n?{kind:"visible",rootMargin:n}:{kind:"visible"};case"interaction":return{kind:"interaction",events:n?h(n):[...c]};case"media":if(!n)throw new i(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:n};default:throw new i(`Unhandled load strategy '${t}'.`)}}function h(e){let n=e.split(/[\s,]+/).map(t=>t.trim()).filter(Boolean);if(n.length===0)throw new i("'load:interaction' was given no event names.");return n}function m(e){return e.kind!=="eager"&&e.kind!=="never"}function x(e){switch(e.kind){case"visible":return`visible:${e.rootMargin??""}`;case"interaction":return`interaction:${[...e.events].sort().join(",")}`;case"media":return`media:${e.query}`;default:return e.kind}}
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/load-directive.ts
21
+ var load_directive_exports = {};
22
+ __export(load_directive_exports, {
23
+ DEFAULT_INTERACTION_EVENTS: () => DEFAULT_INTERACTION_EVENTS,
24
+ EAGER: () => EAGER,
25
+ LoadDirectiveError: () => LoadDirectiveError,
26
+ isDeferred: () => isDeferred,
27
+ isLoadDirective: () => isLoadDirective,
28
+ parseLoadDirective: () => parseLoadDirective,
29
+ strategyKey: () => strategyKey
30
+ });
31
+ module.exports = __toCommonJS(load_directive_exports);
32
+ var EAGER = { kind: "eager" };
33
+ var DEFAULT_INTERACTION_EVENTS = ["pointerdown", "focusin", "keydown"];
34
+ var STRATEGIES = /* @__PURE__ */ new Set(["eager", "idle", "visible", "interaction", "media", "never"]);
35
+ var LoadDirectiveError = class extends Error {
36
+ };
37
+ function isLoadDirective(name) {
38
+ return name.startsWith("load:");
39
+ }
40
+ function parseLoadDirective(name, value) {
41
+ const strategy = name.slice("load:".length);
42
+ if (!STRATEGIES.has(strategy)) {
43
+ throw new LoadDirectiveError(
44
+ `Unknown load strategy 'load:${strategy}'. Expected one of ${[...STRATEGIES].join(", ")}.`
45
+ );
46
+ }
47
+ switch (strategy) {
48
+ case "eager":
49
+ return EAGER;
50
+ case "idle":
51
+ return { kind: "idle" };
52
+ case "never":
53
+ return { kind: "never" };
54
+ case "visible":
55
+ return value ? { kind: "visible", rootMargin: value } : { kind: "visible" };
56
+ case "interaction":
57
+ return {
58
+ kind: "interaction",
59
+ events: value ? splitEvents(value) : [...DEFAULT_INTERACTION_EVENTS]
60
+ };
61
+ case "media":
62
+ if (!value) {
63
+ throw new LoadDirectiveError(
64
+ `'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`
65
+ );
66
+ }
67
+ return { kind: "media", query: value };
68
+ default:
69
+ throw new LoadDirectiveError(`Unhandled load strategy '${strategy}'.`);
70
+ }
71
+ }
72
+ function splitEvents(value) {
73
+ const events = value.split(/[\s,]+/).map((e) => e.trim()).filter(Boolean);
74
+ if (events.length === 0) {
75
+ throw new LoadDirectiveError(`'load:interaction' was given no event names.`);
76
+ }
77
+ return events;
78
+ }
79
+ function isDeferred(strategy) {
80
+ return strategy.kind !== "eager" && strategy.kind !== "never";
81
+ }
82
+ function strategyKey(strategy) {
83
+ switch (strategy.kind) {
84
+ case "visible":
85
+ return `visible:${strategy.rootMargin ?? ""}`;
86
+ case "interaction":
87
+ return `interaction:${[...strategy.events].sort().join(",")}`;
88
+ case "media":
89
+ return `media:${strategy.query}`;
90
+ default:
91
+ return strategy.kind;
92
+ }
93
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * The `load:` directive — when a component's code is fetched.
3
+ *
4
+ * Resolution decides *where* a component comes from; this decides *when*. They are
5
+ * separate because they vary independently: the location of `<RevenueChart>` is the
6
+ * same everywhere and belongs in config, while whether this particular usage should
7
+ * wait for the viewport is a property of the usage. Fusing them — `<Chart lazy="./Chart">`
8
+ * — was rejected for exactly that reason.
9
+ *
10
+ * `load:` joins the existing `use:`/`prop:`/`attr:`/`bool:` namespace, so it cannot
11
+ * collide with a real prop and the parser already has a directive taxonomy to hang it on.
12
+ *
13
+ * One parser for both frontends. `load:visible` is already a valid `JSXNamespacedName`,
14
+ * so JSX needs no parser change, and the html`` path produces a `LoadDirective` node —
15
+ * but both funnel through {@link parseLoadDirective}, so the two syntaxes cannot drift.
16
+ */
17
+ /** When a component's module is fetched. */
18
+ export type IRLoadStrategy = {
19
+ kind: 'eager';
20
+ } | {
21
+ kind: 'idle';
22
+ } | {
23
+ kind: 'visible';
24
+ rootMargin?: string;
25
+ } | {
26
+ kind: 'interaction';
27
+ events: string[];
28
+ } | {
29
+ kind: 'media';
30
+ query: string;
31
+ } | {
32
+ kind: 'never';
33
+ };
34
+ /** Everything is eager unless a directive says otherwise. */
35
+ export declare const EAGER: IRLoadStrategy;
36
+ /** Events that trigger an `interaction` load when none are named. */
37
+ export declare const DEFAULT_INTERACTION_EVENTS: readonly ["pointerdown", "focusin", "keydown"];
38
+ export declare class LoadDirectiveError extends Error {
39
+ }
40
+ /** True for an attribute name in the `load:` namespace. */
41
+ export declare function isLoadDirective(name: string): boolean;
42
+ /**
43
+ * Parse `load:<strategy>` plus its optional value into a strategy.
44
+ *
45
+ * `value` is the attribute's literal text — `load:visible="200px"` — or null for a bare
46
+ * directive. A `${…}` hole is rejected: the strategy has to be known at compile time
47
+ * because it decides how the module is emitted, and a runtime value cannot.
48
+ */
49
+ export declare function parseLoadDirective(name: string, value: string | null): IRLoadStrategy;
50
+ /** True when the strategy means "not in the parent chunk". */
51
+ export declare function isDeferred(strategy: IRLoadStrategy): boolean;
52
+ /** A stable key for grouping references that share a strategy. */
53
+ export declare function strategyKey(strategy: IRLoadStrategy): string;