@fluixi/compiler 1.0.0-alpha.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (303) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +131 -0
  3. package/dist/analyze/expr-shape.cjs +62 -0
  4. package/dist/analyze/expr-shape.d.cts +14 -0
  5. package/dist/analyze/expr-shape.d.ts +15 -0
  6. package/dist/analyze/expr-shape.d.ts.map +1 -0
  7. package/dist/analyze/expr-shape.js +37 -0
  8. package/dist/analyze/expr-shape.mjs +41 -0
  9. package/dist/analyze/intrinsics.cjs +112 -0
  10. package/dist/analyze/intrinsics.d.cts +80 -0
  11. package/dist/analyze/intrinsics.d.ts +81 -0
  12. package/dist/analyze/intrinsics.d.ts.map +1 -0
  13. package/dist/analyze/intrinsics.js +126 -0
  14. package/dist/analyze/intrinsics.mjs +91 -0
  15. package/dist/analyze/paren.cjs +134 -0
  16. package/dist/analyze/paren.d.cts +23 -0
  17. package/dist/analyze/paren.d.ts +24 -0
  18. package/dist/analyze/paren.d.ts.map +1 -0
  19. package/dist/analyze/paren.js +168 -0
  20. package/dist/analyze/paren.mjs +113 -0
  21. package/dist/analyze/props-destructure.cjs +226 -0
  22. package/dist/analyze/props-destructure.d.cts +83 -0
  23. package/dist/analyze/props-destructure.d.ts +84 -0
  24. package/dist/analyze/props-destructure.d.ts.map +1 -0
  25. package/dist/analyze/props-destructure.js +272 -0
  26. package/dist/analyze/props-destructure.mjs +205 -0
  27. package/dist/analyze/reactive-bindings.cjs +210 -0
  28. package/dist/analyze/reactive-bindings.d.cts +42 -0
  29. package/dist/analyze/reactive-bindings.d.ts +43 -0
  30. package/dist/analyze/reactive-bindings.d.ts.map +1 -0
  31. package/dist/analyze/reactive-bindings.js +191 -0
  32. package/dist/analyze/reactive-bindings.mjs +187 -0
  33. package/dist/analyze/reactive-expr.cjs +38 -0
  34. package/dist/analyze/reactive-expr.d.cts +38 -0
  35. package/dist/analyze/reactive-expr.d.ts +39 -0
  36. package/dist/analyze/reactive-expr.d.ts.map +1 -0
  37. package/dist/analyze/reactive-expr.js +31 -0
  38. package/dist/analyze/reactive-expr.mjs +17 -0
  39. package/dist/analyze/static-graph.cjs +831 -0
  40. package/dist/analyze/static-graph.d.cts +102 -0
  41. package/dist/analyze/static-graph.d.ts +103 -0
  42. package/dist/analyze/static-graph.d.ts.map +1 -0
  43. package/dist/analyze/static-graph.js +871 -0
  44. package/dist/analyze/static-graph.mjs +813 -0
  45. package/dist/babel-I6BUWUCU.mjs +636 -0
  46. package/dist/chunk-3AICWNF7.mjs +92 -0
  47. package/dist/chunk-6CWJWGE2.mjs +2170 -0
  48. package/dist/chunk-C3XPDB4Y.mjs +16 -0
  49. package/dist/chunk-GX5XV6Z7.mjs +190 -0
  50. package/dist/chunk-HXEXPWJ2.mjs +999 -0
  51. package/dist/chunk-NU3W67UZ.mjs +584 -0
  52. package/dist/chunk-SKAVY75W.mjs +11 -0
  53. package/dist/codegen/backend.cjs +18 -0
  54. package/dist/codegen/backend.d.cts +35 -0
  55. package/dist/codegen/backend.d.ts +36 -0
  56. package/dist/codegen/backend.d.ts.map +1 -0
  57. package/dist/codegen/backend.js +1 -0
  58. package/dist/codegen/backend.mjs +0 -0
  59. package/dist/codegen/backends/imperative.cjs +577 -0
  60. package/dist/codegen/backends/imperative.d.cts +11 -0
  61. package/dist/codegen/backends/imperative.d.ts +12 -0
  62. package/dist/codegen/backends/imperative.d.ts.map +1 -0
  63. package/dist/codegen/backends/imperative.js +362 -0
  64. package/dist/codegen/backends/imperative.mjs +554 -0
  65. package/dist/codegen/contract.cjs +52 -0
  66. package/dist/codegen/contract.d.cts +24 -0
  67. package/dist/codegen/contract.d.ts +25 -0
  68. package/dist/codegen/contract.d.ts.map +1 -0
  69. package/dist/codegen/contract.js +30 -0
  70. package/dist/codegen/contract.mjs +31 -0
  71. package/dist/codegen/partial-template.cjs +176 -0
  72. package/dist/codegen/partial-template.d.cts +61 -0
  73. package/dist/codegen/partial-template.d.ts +62 -0
  74. package/dist/codegen/partial-template.d.ts.map +1 -0
  75. package/dist/codegen/partial-template.js +0 -0
  76. package/dist/codegen/partial-template.mjs +153 -0
  77. package/dist/codegen/serialize-static.cjs +125 -0
  78. package/dist/codegen/serialize-static.d.cts +38 -0
  79. package/dist/codegen/serialize-static.d.ts +39 -0
  80. package/dist/codegen/serialize-static.d.ts.map +1 -0
  81. package/dist/codegen/serialize-static.js +165 -0
  82. package/dist/codegen/serialize-static.mjs +104 -0
  83. package/dist/frontend/babel/build-ir-lit.cjs +1933 -0
  84. package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
  85. package/dist/frontend/babel/build-ir-lit.d.ts +27 -0
  86. package/dist/frontend/babel/build-ir-lit.d.ts.map +1 -0
  87. package/dist/frontend/babel/build-ir-lit.js +13 -0
  88. package/dist/frontend/babel/build-ir-lit.mjs +1902 -0
  89. package/dist/frontend/babel/build-ir.cjs +1948 -0
  90. package/dist/frontend/babel/build-ir.d.cts +35 -0
  91. package/dist/frontend/babel/build-ir.d.ts +36 -0
  92. package/dist/frontend/babel/build-ir.d.ts.map +1 -0
  93. package/dist/frontend/babel/build-ir.js +124 -0
  94. package/dist/frontend/babel/build-ir.mjs +1919 -0
  95. package/dist/frontend/babel/index.cjs +2610 -0
  96. package/dist/frontend/babel/index.d.cts +33 -0
  97. package/dist/frontend/babel/index.d.ts +34 -0
  98. package/dist/frontend/babel/index.d.ts.map +1 -0
  99. package/dist/frontend/babel/index.js +65 -0
  100. package/dist/frontend/babel/index.mjs +2580 -0
  101. package/dist/frontend/babel/lower-template.cjs +1931 -0
  102. package/dist/frontend/babel/lower-template.d.cts +23 -0
  103. package/dist/frontend/babel/lower-template.d.ts +24 -0
  104. package/dist/frontend/babel/lower-template.d.ts.map +1 -0
  105. package/dist/frontend/babel/lower-template.js +64 -0
  106. package/dist/frontend/babel/lower-template.mjs +1902 -0
  107. package/dist/frontend/babel/plugin.cjs +2556 -0
  108. package/dist/frontend/babel/plugin.d.cts +95 -0
  109. package/dist/frontend/babel/plugin.d.ts +96 -0
  110. package/dist/frontend/babel/plugin.d.ts.map +1 -0
  111. package/dist/frontend/babel/plugin.js +523 -0
  112. package/dist/frontend/babel/plugin.mjs +2527 -0
  113. package/dist/frontend/babel/server-functions.cjs +110 -0
  114. package/dist/frontend/babel/server-functions.d.cts +10 -0
  115. package/dist/frontend/babel/server-functions.d.ts +11 -0
  116. package/dist/frontend/babel/server-functions.d.ts.map +1 -0
  117. package/dist/frontend/babel/server-functions.js +81 -0
  118. package/dist/frontend/babel/server-functions.mjs +89 -0
  119. package/dist/frontend/babel/types.cjs +18 -0
  120. package/dist/frontend/babel/types.d.cts +33 -0
  121. package/dist/frontend/babel/types.d.ts +34 -0
  122. package/dist/frontend/babel/types.d.ts.map +1 -0
  123. package/dist/frontend/babel/types.js +1 -0
  124. package/dist/frontend/babel/types.mjs +0 -0
  125. package/dist/frontend/types.cjs +18 -0
  126. package/dist/frontend/types.d.cts +25 -0
  127. package/dist/frontend/types.d.ts +26 -0
  128. package/dist/frontend/types.d.ts.map +1 -0
  129. package/dist/frontend/types.js +1 -0
  130. package/dist/frontend/types.mjs +0 -0
  131. package/dist/frontend/vocabulary.cjs +98 -0
  132. package/dist/frontend/vocabulary.d.cts +79 -0
  133. package/dist/frontend/vocabulary.d.ts +80 -0
  134. package/dist/frontend/vocabulary.d.ts.map +1 -0
  135. package/dist/frontend/vocabulary.js +124 -0
  136. package/dist/frontend/vocabulary.mjs +77 -0
  137. package/dist/index.cjs +1957 -0
  138. package/dist/index.d.cts +27 -0
  139. package/dist/index.d.ts +28 -0
  140. package/dist/index.d.ts.map +1 -0
  141. package/dist/index.js +38 -0
  142. package/dist/index.mjs +1949 -0
  143. package/dist/integrations.cjs +5705 -0
  144. package/dist/integrations.d.cts +215 -0
  145. package/dist/integrations.d.ts +216 -0
  146. package/dist/integrations.d.ts.map +1 -0
  147. package/dist/integrations.js +566 -0
  148. package/dist/integrations.mjs +810 -0
  149. package/dist/ir/nodes.cjs +18 -0
  150. package/dist/ir/nodes.d.cts +168 -0
  151. package/dist/ir/nodes.d.ts +169 -0
  152. package/dist/ir/nodes.d.ts.map +1 -0
  153. package/dist/ir/nodes.js +1 -0
  154. package/dist/ir/nodes.mjs +0 -0
  155. package/dist/lower/compile-template.cjs +1670 -0
  156. package/dist/lower/compile-template.d.cts +82 -0
  157. package/dist/lower/compile-template.d.ts +83 -0
  158. package/dist/lower/compile-template.d.ts.map +1 -0
  159. package/dist/lower/compile-template.js +79 -0
  160. package/dist/lower/compile-template.mjs +1662 -0
  161. package/dist/lower/entities.cjs +288 -0
  162. package/dist/lower/entities.d.cts +1 -0
  163. package/dist/lower/entities.d.ts +2 -0
  164. package/dist/lower/entities.d.ts.map +1 -0
  165. package/dist/lower/entities.js +54 -0
  166. package/dist/lower/entities.mjs +267 -0
  167. package/dist/lower/jsx.cjs +1101 -0
  168. package/dist/lower/jsx.d.cts +33 -0
  169. package/dist/lower/jsx.d.ts +34 -0
  170. package/dist/lower/jsx.d.ts.map +1 -0
  171. package/dist/lower/jsx.js +414 -0
  172. package/dist/lower/jsx.mjs +1078 -0
  173. package/dist/lower/template.cjs +1354 -0
  174. package/dist/lower/template.d.cts +53 -0
  175. package/dist/lower/template.d.ts +54 -0
  176. package/dist/lower/template.d.ts.map +1 -0
  177. package/dist/lower/template.js +542 -0
  178. package/dist/lower/template.mjs +1335 -0
  179. package/dist/lower/text.cjs +42 -0
  180. package/dist/lower/text.d.cts +10 -0
  181. package/dist/lower/text.d.ts +11 -0
  182. package/dist/lower/text.d.ts.map +1 -0
  183. package/dist/lower/text.js +31 -0
  184. package/dist/lower/text.mjs +21 -0
  185. package/dist/optimize/analyze-static.cjs +112 -0
  186. package/dist/optimize/analyze-static.d.cts +39 -0
  187. package/dist/optimize/analyze-static.d.ts +40 -0
  188. package/dist/optimize/analyze-static.d.ts.map +1 -0
  189. package/dist/optimize/analyze-static.js +131 -0
  190. package/dist/optimize/analyze-static.mjs +91 -0
  191. package/dist/optimize/collapse-strategies.cjs +90 -0
  192. package/dist/optimize/collapse-strategies.d.cts +30 -0
  193. package/dist/optimize/collapse-strategies.d.ts +31 -0
  194. package/dist/optimize/collapse-strategies.d.ts.map +1 -0
  195. package/dist/optimize/collapse-strategies.js +33 -0
  196. package/dist/optimize/collapse-strategies.mjs +67 -0
  197. package/dist/options.cjs +33 -0
  198. package/dist/options.d.cts +39 -0
  199. package/dist/options.d.ts +40 -0
  200. package/dist/options.d.ts.map +1 -0
  201. package/dist/options.js +8 -0
  202. package/dist/options.mjs +12 -0
  203. package/dist/resolve/builtins.cjs +73 -0
  204. package/dist/resolve/builtins.d.cts +68 -0
  205. package/dist/resolve/builtins.d.ts +69 -0
  206. package/dist/resolve/builtins.d.ts.map +1 -0
  207. package/dist/resolve/builtins.js +64 -0
  208. package/dist/resolve/builtins.mjs +53 -0
  209. package/dist/resolve/component-globals.cjs +272 -0
  210. package/dist/resolve/component-globals.d.cts +88 -0
  211. package/dist/resolve/component-globals.d.ts +89 -0
  212. package/dist/resolve/component-globals.d.ts.map +1 -0
  213. package/dist/resolve/component-globals.js +160 -0
  214. package/dist/resolve/component-globals.mjs +249 -0
  215. package/dist/resolve/component-resolver.cjs +80 -0
  216. package/dist/resolve/component-resolver.d.cts +68 -0
  217. package/dist/resolve/component-resolver.d.ts +69 -0
  218. package/dist/resolve/component-resolver.d.ts.map +1 -0
  219. package/dist/resolve/component-resolver.js +95 -0
  220. package/dist/resolve/component-resolver.mjs +59 -0
  221. package/dist/resolve/load-directive.cjs +93 -0
  222. package/dist/resolve/load-directive.d.cts +53 -0
  223. package/dist/resolve/load-directive.d.ts +54 -0
  224. package/dist/resolve/load-directive.d.ts.map +1 -0
  225. package/dist/resolve/load-directive.js +93 -0
  226. package/dist/resolve/load-directive.mjs +72 -0
  227. package/dist/resolve/resolve-ir.cjs +108 -0
  228. package/dist/resolve/resolve-ir.d.cts +53 -0
  229. package/dist/resolve/resolve-ir.d.ts +54 -0
  230. package/dist/resolve/resolve-ir.d.ts.map +1 -0
  231. package/dist/resolve/resolve-ir.js +58 -0
  232. package/dist/resolve/resolve-ir.mjs +85 -0
  233. package/dist/resolve/write-globals.cjs +383 -0
  234. package/dist/resolve/write-globals.d.cts +36 -0
  235. package/dist/resolve/write-globals.d.ts +37 -0
  236. package/dist/resolve/write-globals.d.ts.map +1 -0
  237. package/dist/resolve/write-globals.js +169 -0
  238. package/dist/resolve/write-globals.mjs +362 -0
  239. package/dist/server-fns-VZLHMQTC.mjs +79 -0
  240. package/dist/server-functions-UAZKOLZW.mjs +82 -0
  241. package/dist/transform/bindings.cjs +71 -0
  242. package/dist/transform/bindings.d.cts +16 -0
  243. package/dist/transform/bindings.d.ts +17 -0
  244. package/dist/transform/bindings.d.ts.map +1 -0
  245. package/dist/transform/bindings.js +69 -0
  246. package/dist/transform/bindings.mjs +50 -0
  247. package/dist/transform/index.cjs +3837 -0
  248. package/dist/transform/index.d.cts +15 -0
  249. package/dist/transform/index.d.ts +16 -0
  250. package/dist/transform/index.d.ts.map +1 -0
  251. package/dist/transform/index.js +12 -0
  252. package/dist/transform/index.mjs +4882 -0
  253. package/dist/transform/intrinsics.cjs +261 -0
  254. package/dist/transform/intrinsics.d.cts +33 -0
  255. package/dist/transform/intrinsics.d.ts +34 -0
  256. package/dist/transform/intrinsics.d.ts.map +1 -0
  257. package/dist/transform/intrinsics.js +120 -0
  258. package/dist/transform/intrinsics.mjs +238 -0
  259. package/dist/transform/props.cjs +441 -0
  260. package/dist/transform/props.d.cts +45 -0
  261. package/dist/transform/props.d.ts +46 -0
  262. package/dist/transform/props.d.ts.map +1 -0
  263. package/dist/transform/props.js +221 -0
  264. package/dist/transform/props.mjs +1487 -0
  265. package/dist/transform/server-fn-id.cjs +35 -0
  266. package/dist/transform/server-fn-id.d.cts +9 -0
  267. package/dist/transform/server-fn-id.d.ts +10 -0
  268. package/dist/transform/server-fn-id.d.ts.map +1 -0
  269. package/dist/transform/server-fn-id.js +18 -0
  270. package/dist/transform/server-fn-id.mjs +14 -0
  271. package/dist/transform/server-fns.cjs +114 -0
  272. package/dist/transform/server-fns.d.cts +12 -0
  273. package/dist/transform/server-fns.d.ts +13 -0
  274. package/dist/transform/server-fns.d.ts.map +1 -0
  275. package/dist/transform/server-fns.js +94 -0
  276. package/dist/transform/server-fns.mjs +1160 -0
  277. package/dist/transform/source-locations.cjs +393 -0
  278. package/dist/transform/source-locations.d.cts +48 -0
  279. package/dist/transform/source-locations.d.ts +49 -0
  280. package/dist/transform/source-locations.d.ts.map +1 -0
  281. package/dist/transform/source-locations.js +303 -0
  282. package/dist/transform/source-locations.mjs +370 -0
  283. package/dist/transform/styles.cjs +606 -0
  284. package/dist/transform/styles.d.cts +237 -0
  285. package/dist/transform/styles.d.ts +238 -0
  286. package/dist/transform/styles.d.ts.map +1 -0
  287. package/dist/transform/styles.js +743 -0
  288. package/dist/transform/styles.mjs +671 -0
  289. package/dist/transform/templates.cjs +3806 -0
  290. package/dist/transform/templates.d.cts +82 -0
  291. package/dist/transform/templates.d.ts +83 -0
  292. package/dist/transform/templates.d.ts.map +1 -0
  293. package/dist/transform/templates.js +613 -0
  294. package/dist/transform/templates.mjs +4852 -0
  295. package/dist/transform-3W45L3EA.mjs +951 -0
  296. package/dist/tsconfig.lib.tsbuildinfo +1 -0
  297. package/dist/vite-styles.cjs +223 -0
  298. package/dist/vite-styles.d.cts +68 -0
  299. package/dist/vite-styles.d.ts +69 -0
  300. package/dist/vite-styles.d.ts.map +1 -0
  301. package/dist/vite-styles.js +241 -0
  302. package/dist/vite-styles.mjs +214 -0
  303. package/package.json +141 -0
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Write the generated component declarations into a project.
3
+ *
4
+ * Split from the generator so the generator stays pure and testable; this half owns the
5
+ * three things that only matter once a real file is involved:
6
+ *
7
+ * - **Never clobber someone's file.** A path like `src/fluixi.d.ts` is plausible enough
8
+ * that a project may already have one. Anything without our header is left alone and
9
+ * reported, because silently overwriting hand-written declarations is unrecoverable.
10
+ * - **Do not rewrite unchanged content.** The dev server watches this directory; an
11
+ * identical write still bumps mtime and can cost a reload every restart.
12
+ * - **Only declare what the project can resolve.** Dependencies come from its manifest,
13
+ * so a component from an uninstalled package is skipped rather than degraded to `any`.
14
+ */
15
+ import { mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
16
+ import { basename, dirname, relative, sep, resolve as resolvePath } from 'node:path';
17
+ import { componentGlobals } from './component-globals.js';
18
+ /** The marker every generated file carries, used to tell ours from a hand-written one. */
19
+ const GENERATED_MARKER = 'GENERATED by @fluixi/compiler';
20
+ export const DEFAULT_GLOBALS_PATH = 'fluixi.d.ts';
21
+ /**
22
+ * Whether `target` looks covered by the project's `include`, as best we can tell.
23
+ *
24
+ * `undefined` when there is nothing to judge from, no tsconfig, unreadable, or an
25
+ * `extends` we would have to resolve to answer honestly. Best-effort by design: this
26
+ * drives a warning, never a failure, so a wrong guess must not be able to break a build.
27
+ */
28
+ function coveredByInclude(root, target) {
29
+ let config;
30
+ try {
31
+ const raw = readFileSync(resolvePath(root, 'tsconfig.json'), 'utf8');
32
+ // Comments are legal in tsconfig and would break JSON.parse.
33
+ config = JSON.parse(raw.replace(/^\s*\/\/.*$/gm, ''));
34
+ }
35
+ catch {
36
+ return undefined;
37
+ }
38
+ if (config.extends !== undefined)
39
+ return undefined;
40
+ // No `include` means the whole directory tree, which covers anything we write.
41
+ if (!Array.isArray(config.include))
42
+ return true;
43
+ const relative = relativePosix(root, target);
44
+ return config.include.some((entry) => {
45
+ if (typeof entry !== 'string')
46
+ return false;
47
+ const pattern = entry
48
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
49
+ .replace(/\*\*\//g, '(?:.*/)?')
50
+ .replace(/\*/g, '[^/]*');
51
+ // A bare directory entry (`src`) covers everything beneath it.
52
+ return new RegExp(`^${pattern}(?:/.*)?$`).test(relative);
53
+ });
54
+ }
55
+ /** `from` -> `to` as a posix-style relative path. */
56
+ function relativePosix(from, to) {
57
+ return relative(from, to).split(sep).join('/');
58
+ }
59
+ /**
60
+ * Make a specifier resolvable from the generated file.
61
+ *
62
+ * A bundler-root-absolute `/src/components/Card.tsx` is what Vite wants and what
63
+ * TypeScript cannot resolve at all, so it becomes a path relative to the generated file.
64
+ * The extension goes to `.js` because that is what TypeScript expects to be written for
65
+ * a `.ts`/`.tsx` source under every module resolution mode that accepts an extension.
66
+ */
67
+ function forTypeScript(module, outDir, root) {
68
+ if (!module.startsWith('/'))
69
+ return module;
70
+ const absolute = resolvePath(root, module.slice(1));
71
+ let rel = relative(outDir, absolute).split(sep).join('/');
72
+ if (!rel.startsWith('.'))
73
+ rel = `./${rel}`;
74
+ return rel.replace(/\.(tsx|ts|jsx|mts|cts)$/, '.js');
75
+ }
76
+ /** The project's declared dependencies, or undefined when there is no readable manifest. */
77
+ function projectDependencies(root) {
78
+ try {
79
+ const manifest = JSON.parse(readFileSync(resolvePath(root, 'package.json'), 'utf8'));
80
+ return [
81
+ ...Object.keys(manifest.dependencies ?? {}),
82
+ ...Object.keys(manifest.devDependencies ?? {}),
83
+ ...Object.keys(manifest.peerDependencies ?? {}),
84
+ ];
85
+ }
86
+ catch {
87
+ // No manifest to read: declare everything and let TypeScript report what is missing.
88
+ return undefined;
89
+ }
90
+ }
91
+ /**
92
+ * Names from the files a pattern rule points at: `/src/components/$1.tsx` lists
93
+ * `src/components` and offers each `X` for `X.tsx`. Only a project path with the group in
94
+ * the file name; the resolver still decides whether a name matches.
95
+ */
96
+ export function patternCandidates(rules, root) {
97
+ const out = [];
98
+ for (const rule of rules) {
99
+ if (!('match' in rule) || !rule.module.startsWith('/'))
100
+ continue;
101
+ const dir = dirname(rule.module);
102
+ const file = basename(rule.module);
103
+ const group = file.match(/\$\d+/);
104
+ if (dir.includes('$') || !group || file.indexOf('$', group.index + 1) !== -1)
105
+ continue;
106
+ const before = file.slice(0, group.index);
107
+ const after = file.slice(group.index + group[0].length);
108
+ let entries;
109
+ try {
110
+ entries = readdirSync(resolvePath(root, dir.slice(1)));
111
+ }
112
+ catch {
113
+ continue;
114
+ }
115
+ for (const entry of entries) {
116
+ if (entry.length > before.length + after.length && entry.startsWith(before) && entry.endsWith(after)) {
117
+ out.push(entry.slice(before.length, entry.length - after.length));
118
+ }
119
+ }
120
+ }
121
+ return out;
122
+ }
123
+ /** Generate and write the declarations for `root`, returning what was done. */
124
+ export function writeComponentGlobals(options, root) {
125
+ if (options.globals === false)
126
+ return { status: 'skipped', reason: 'disabled' };
127
+ const rules = options.resolve ?? [];
128
+ const target = resolvePath(root, options.globals ?? DEFAULT_GLOBALS_PATH);
129
+ let existing;
130
+ try {
131
+ existing = readFileSync(target, 'utf8');
132
+ }
133
+ catch {
134
+ existing = undefined;
135
+ }
136
+ if (existing !== undefined && !existing.includes(GENERATED_MARKER)) {
137
+ return { status: 'skipped', reason: 'foreign-file', path: target };
138
+ }
139
+ const { source, declared } = componentGlobals(rules, {
140
+ available: projectDependencies(root),
141
+ candidates: patternCandidates(rules, root),
142
+ specifier: (module) => forTypeScript(module, dirname(target), root),
143
+ });
144
+ if (existing === source) {
145
+ return {
146
+ status: 'unchanged',
147
+ path: target,
148
+ declared: declared.length,
149
+ warning: warnIfUnreachable(root, target),
150
+ };
151
+ }
152
+ mkdirSync(dirname(target), { recursive: true });
153
+ writeFileSync(target, source);
154
+ return {
155
+ status: 'written',
156
+ path: target,
157
+ declared: declared.length,
158
+ warning: warnIfUnreachable(root, target),
159
+ };
160
+ }
161
+ /** The message to show when the generated file is outside the project's `include`. */
162
+ function warnIfUnreachable(root, target) {
163
+ if (coveredByInclude(root, target) !== false)
164
+ return undefined;
165
+ const relative = relativePosix(root, target);
166
+ return (`[fluixi] ${relative} is not covered by "include" in tsconfig.json, so TypeScript ` +
167
+ `will ignore it and every resolved component stays "Cannot find name". Add ` +
168
+ `"${relative}" to "include".`);
169
+ }
@@ -0,0 +1,362 @@
1
+ // src/resolve/write-globals.ts
2
+ import { mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { basename, dirname, relative, sep, resolve as resolvePath } from "node:path";
4
+
5
+ // src/resolve/component-resolver.ts
6
+ var isMapRule = (rule) => "components" in rule;
7
+ function substitute(template, match) {
8
+ return template.replace(/\$(\d+)/g, (whole, index) => {
9
+ const group = match[Number(index)];
10
+ return group ?? whole;
11
+ });
12
+ }
13
+ function normalise(name, entry) {
14
+ return typeof entry === "string" ? { module: entry, export: name } : entry;
15
+ }
16
+ function createComponentResolver(rules = []) {
17
+ const exact = /* @__PURE__ */ new Map();
18
+ const conflicts = [];
19
+ const patterns = [];
20
+ for (const rule of rules) {
21
+ if (!isMapRule(rule)) {
22
+ patterns.push(rule);
23
+ continue;
24
+ }
25
+ for (const [name, entry] of Object.entries(rule.components)) {
26
+ const resolved = normalise(name, entry);
27
+ const existing = exact.get(name);
28
+ if (existing && existing.module !== resolved.module) {
29
+ const conflict = conflicts.find((c) => c.name === name);
30
+ if (conflict) conflict.modules.push(resolved.module);
31
+ else conflicts.push({ name, modules: [existing.module, resolved.module] });
32
+ continue;
33
+ }
34
+ exact.set(name, resolved);
35
+ }
36
+ }
37
+ const cache = /* @__PURE__ */ new Map();
38
+ const resolve = (name) => {
39
+ if (cache.has(name)) return cache.get(name);
40
+ let result = exact.get(name);
41
+ if (!result) {
42
+ for (const rule of patterns) {
43
+ const match = name.match(new RegExp(rule.match.source, rule.match.flags.replace("g", "")));
44
+ if (!match) continue;
45
+ result = {
46
+ module: substitute(rule.module, match),
47
+ export: rule.export ? substitute(rule.export, match) : name
48
+ };
49
+ break;
50
+ }
51
+ }
52
+ cache.set(name, result);
53
+ return result;
54
+ };
55
+ return {
56
+ resolve,
57
+ names: () => [...exact.keys()],
58
+ conflicts: () => conflicts
59
+ };
60
+ }
61
+
62
+ // src/resolve/builtins.ts
63
+ var DOM_CONTROL_FLOW = [
64
+ "Show",
65
+ "For",
66
+ "Index",
67
+ "Switch",
68
+ "Match",
69
+ "Portal",
70
+ "Dynamic",
71
+ "ErrorBoundary"
72
+ ];
73
+ var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
74
+ var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
75
+ var BUILTIN_COMPONENTS = [
76
+ ...DOM_CONTROL_FLOW,
77
+ ...CORE_CONTROL_FLOW,
78
+ ...ROUTER_COMPONENTS
79
+ ];
80
+ var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
81
+ ...DOM_CONTROL_FLOW,
82
+ ...CORE_CONTROL_FLOW
83
+ ]);
84
+ function builtinComponentMap(modules = {}) {
85
+ const {
86
+ controlFlowModule = "@fluixi/dom",
87
+ coreModule = "@fluixi/core",
88
+ routerModule = "@fluixi/core/router"
89
+ } = modules;
90
+ const map = {};
91
+ for (const name of DOM_CONTROL_FLOW) map[name] = controlFlowModule;
92
+ for (const name of CORE_CONTROL_FLOW) map[name] = coreModule;
93
+ for (const name of ROUTER_COMPONENTS) map[name] = routerModule;
94
+ return map;
95
+ }
96
+
97
+ // src/analyze/intrinsics.ts
98
+ var REACTIVE_MODULE = "@fluixi/reactive/signal";
99
+ var INTRINSICS = {
100
+ $signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
101
+ $memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
102
+ $effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
103
+ $store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
104
+ $resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
105
+ $cachedResource: { export: "cachedResource", module: "@fluixi/reactive/cached-resource", returns: "resource-handle" },
106
+ // No short runtime form for these yet, so the intrinsic stands for the `create*`
107
+ // name. Still worth having: no import to write, and when a shorter form is
108
+ // designed, the change is this line rather than a compiler pass.
109
+ $selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
110
+ $deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
111
+ // Not value constructors, but the compiler has to know them: they change what a read
112
+ // does. `untrack` suppresses dependency collection, which is exactly the kind of thing
113
+ // dependency analysis must not guess at.
114
+ $untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
115
+ $untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" },
116
+ // Scopes, scheduling and lifecycle: no value to classify, but the same authoring promise,
117
+ // no import to write. `$cleanup` registers a callback on the current owner (`onCleanup`).
118
+ $batch: { export: "batch", module: REACTIVE_MODULE, returns: "plain" },
119
+ $cleanup: { export: "onCleanup", module: REACTIVE_MODULE, returns: "plain" },
120
+ $root: { export: "root", module: REACTIVE_MODULE, returns: "plain" },
121
+ $context: { export: "context", module: REACTIVE_MODULE, returns: "plain" },
122
+ $renderEffect: { export: "renderEffect", module: REACTIVE_MODULE, returns: "effect" },
123
+ $computed: { export: "computed", module: REACTIVE_MODULE, returns: "effect" },
124
+ // Storage for where the code runs, and a signal kept in it. `$persisted` is a signal
125
+ // handle as far as reads go: the same accessor with `set` on it.
126
+ $storage: { export: "useStorage", module: "@fluixi/core/storage", returns: "plain" },
127
+ $asyncStorage: { export: "useAsyncStorage", module: "@fluixi/core/storage", returns: "plain" },
128
+ $persisted: { export: "persisted", module: "@fluixi/core/storage", returns: "signal-handle" },
129
+ // An environment variable, public or server-only; the browser build refuses a secret.
130
+ $env: { export: "env", module: "@fluixi/start/env", returns: "plain" }
131
+ };
132
+ var TAG_INTRINSICS = {
133
+ $html: { export: "html", module: "@fluixi/core" },
134
+ $svg: { export: "svg", module: "@fluixi/core" },
135
+ $css: { export: "css", module: "@fluixi/core" }
136
+ };
137
+ var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
138
+
139
+ // src/resolve/component-globals.ts
140
+ var DOM_GLOBALS = /* @__PURE__ */ new Set([
141
+ "Text",
142
+ "Image",
143
+ "Option",
144
+ "Audio",
145
+ "Comment",
146
+ "Range",
147
+ "Selection",
148
+ "Notification",
149
+ "Event",
150
+ "Document",
151
+ "Element",
152
+ "Node",
153
+ "Screen",
154
+ "Window",
155
+ "Location",
156
+ "History",
157
+ "Storage",
158
+ "Response",
159
+ "Request",
160
+ "Headers"
161
+ ]);
162
+ function packageOf(specifier) {
163
+ if (specifier.startsWith(".") || specifier.startsWith("/")) return void 0;
164
+ if (/^[~@]\//.test(specifier)) return void 0;
165
+ const parts = specifier.split("/");
166
+ return specifier.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0];
167
+ }
168
+ function namespaceAlias(module) {
169
+ return `_${module.replace(/[^A-Za-z0-9]/g, "_")}`;
170
+ }
171
+ function componentGlobals(rules, options = {}) {
172
+ const {
173
+ available: availableList,
174
+ builtins = true,
175
+ intrinsics = true,
176
+ generator = "@fluixi/compiler",
177
+ specifier = (module) => module,
178
+ candidates = []
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
+ const names = /* @__PURE__ */ new Set([...resolver.names(), ...[...candidates].filter((n) => /^[A-Za-z_$][\w$]*$/.test(n))]);
191
+ for (const name of [...names].sort()) {
192
+ const target = resolver.resolve(name);
193
+ if (!target) continue;
194
+ const pkg = packageOf(target.module);
195
+ if (DOM_GLOBALS.has(name)) shadowedByDom.push(name);
196
+ else if (available && pkg && !available.has(pkg)) unavailable.push(name);
197
+ else {
198
+ declared.push(name);
199
+ resolved.set(name, target);
200
+ }
201
+ }
202
+ const usableIntrinsics = intrinsics ? Object.entries({ ...INTRINSICS, ...TAG_INTRINSICS }).filter(([, i]) => {
203
+ const pkg = packageOf(i.module);
204
+ return !available || !pkg || available.has(pkg);
205
+ }) : [];
206
+ const intrinsicModules = [...new Set(usableIntrinsics.map(([, i]) => i.module))];
207
+ const modules = [
208
+ .../* @__PURE__ */ new Set([...declared.map((name) => resolved.get(name).module), ...intrinsicModules])
209
+ ].sort();
210
+ const imports = modules.map(
211
+ (m) => `import * as ${namespaceAlias(m)} from '${specifier(m)}';`
212
+ );
213
+ const lines = declared.map((name) => {
214
+ const target = resolved.get(name);
215
+ const ns = namespaceAlias(target.module);
216
+ return target.export === "default" ? ` const ${name}: typeof ${ns}.default;` : ` export import ${name} = ${ns}.${target.export};`;
217
+ });
218
+ const note = shadowedByDom.length > 0 ? `//
219
+ // Import these explicitly: lib.dom already declares the name, so an ambient
220
+ // declaration cannot win:
221
+ ` + shadowedByDom.map((n) => {
222
+ const module = resolver.resolve(n)?.module;
223
+ return `// import { ${n} } from '${module ? specifier(module) : ""}';
224
+ `;
225
+ }).join("") : "";
226
+ const intrinsicLines = usableIntrinsics.map(
227
+ ([name, intrinsic]) => ` const ${name}: typeof ${namespaceAlias(intrinsic.module)}.${intrinsic.export};`
228
+ );
229
+ const patternRules = rules.filter((rule) => "match" in rule).length;
230
+ const patternNote = patternRules === 0 ? "" : options.candidates ? `//
231
+ // ${patternRules} pattern rule${patternRules === 1 ? "" : "s"}: declared for the files the module path
232
+ // points at. A name with no such file still resolves at build time; declare it by hand.
233
+ ` : `//
234
+ // ${patternRules} pattern rule${patternRules === 1 ? "" : "s"} cannot be declared:
235
+ // a pattern matches unboundedly many names, so there is no list to emit. Those
236
+ // tags still resolve at build time; declare them by hand if the editor needs them.
237
+ `;
238
+ const source = `// GENERATED by ${generator}, do not edit.
239
+ //
240
+ // The components \`resolve\` supplies without an import. This describes what the
241
+ // compiler already does; it does not enable it.
242
+ ` + note + patternNote + (imports.length > 0 ? `
243
+ ${imports.join("\n")}
244
+ ` : "\n") + `
245
+ declare global {
246
+ ${[...lines, ...intrinsicLines].join("\n")}
247
+ }
248
+ `;
249
+ return { source, declared, shadowedByDom, unavailable, patternRules };
250
+ }
251
+
252
+ // src/resolve/write-globals.ts
253
+ var GENERATED_MARKER = "GENERATED by @fluixi/compiler";
254
+ var DEFAULT_GLOBALS_PATH = "fluixi.d.ts";
255
+ function coveredByInclude(root, target) {
256
+ let config;
257
+ try {
258
+ const raw = readFileSync(resolvePath(root, "tsconfig.json"), "utf8");
259
+ config = JSON.parse(raw.replace(/^\s*\/\/.*$/gm, ""));
260
+ } catch {
261
+ return void 0;
262
+ }
263
+ if (config.extends !== void 0) return void 0;
264
+ if (!Array.isArray(config.include)) return true;
265
+ const relative2 = relativePosix(root, target);
266
+ return config.include.some((entry) => {
267
+ if (typeof entry !== "string") return false;
268
+ const pattern = entry.replace(/[.+^${}()|[\]\\]/g, "\\$&").replace(/\*\*\//g, "(?:.*/)?").replace(/\*/g, "[^/]*");
269
+ return new RegExp(`^${pattern}(?:/.*)?$`).test(relative2);
270
+ });
271
+ }
272
+ function relativePosix(from, to) {
273
+ return relative(from, to).split(sep).join("/");
274
+ }
275
+ function forTypeScript(module, outDir, root) {
276
+ if (!module.startsWith("/")) return module;
277
+ const absolute = resolvePath(root, module.slice(1));
278
+ let rel = relative(outDir, absolute).split(sep).join("/");
279
+ if (!rel.startsWith(".")) rel = `./${rel}`;
280
+ return rel.replace(/\.(tsx|ts|jsx|mts|cts)$/, ".js");
281
+ }
282
+ function projectDependencies(root) {
283
+ try {
284
+ const manifest = JSON.parse(readFileSync(resolvePath(root, "package.json"), "utf8"));
285
+ return [
286
+ ...Object.keys(manifest.dependencies ?? {}),
287
+ ...Object.keys(manifest.devDependencies ?? {}),
288
+ ...Object.keys(manifest.peerDependencies ?? {})
289
+ ];
290
+ } catch {
291
+ return void 0;
292
+ }
293
+ }
294
+ function patternCandidates(rules, root) {
295
+ const out = [];
296
+ for (const rule of rules) {
297
+ if (!("match" in rule) || !rule.module.startsWith("/")) continue;
298
+ const dir = dirname(rule.module);
299
+ const file = basename(rule.module);
300
+ const group = file.match(/\$\d+/);
301
+ if (dir.includes("$") || !group || file.indexOf("$", group.index + 1) !== -1) continue;
302
+ const before = file.slice(0, group.index);
303
+ const after = file.slice(group.index + group[0].length);
304
+ let entries;
305
+ try {
306
+ entries = readdirSync(resolvePath(root, dir.slice(1)));
307
+ } catch {
308
+ continue;
309
+ }
310
+ for (const entry of entries) {
311
+ if (entry.length > before.length + after.length && entry.startsWith(before) && entry.endsWith(after)) {
312
+ out.push(entry.slice(before.length, entry.length - after.length));
313
+ }
314
+ }
315
+ }
316
+ return out;
317
+ }
318
+ function writeComponentGlobals(options, root) {
319
+ if (options.globals === false) return { status: "skipped", reason: "disabled" };
320
+ const rules = options.resolve ?? [];
321
+ const target = resolvePath(root, options.globals ?? DEFAULT_GLOBALS_PATH);
322
+ let existing;
323
+ try {
324
+ existing = readFileSync(target, "utf8");
325
+ } catch {
326
+ existing = void 0;
327
+ }
328
+ if (existing !== void 0 && !existing.includes(GENERATED_MARKER)) {
329
+ return { status: "skipped", reason: "foreign-file", path: target };
330
+ }
331
+ const { source, declared } = componentGlobals(rules, {
332
+ available: projectDependencies(root),
333
+ candidates: patternCandidates(rules, root),
334
+ specifier: (module) => forTypeScript(module, dirname(target), root)
335
+ });
336
+ if (existing === source) {
337
+ return {
338
+ status: "unchanged",
339
+ path: target,
340
+ declared: declared.length,
341
+ warning: warnIfUnreachable(root, target)
342
+ };
343
+ }
344
+ mkdirSync(dirname(target), { recursive: true });
345
+ writeFileSync(target, source);
346
+ return {
347
+ status: "written",
348
+ path: target,
349
+ declared: declared.length,
350
+ warning: warnIfUnreachable(root, target)
351
+ };
352
+ }
353
+ function warnIfUnreachable(root, target) {
354
+ if (coveredByInclude(root, target) !== false) return void 0;
355
+ const relative2 = relativePosix(root, target);
356
+ return `[fluixi] ${relative2} is not covered by "include" in tsconfig.json, so TypeScript will ignore it and every resolved component stays "Cannot find name". Add "${relative2}" to "include".`;
357
+ }
358
+ export {
359
+ DEFAULT_GLOBALS_PATH,
360
+ patternCandidates,
361
+ writeComponentGlobals
362
+ };
@@ -0,0 +1,79 @@
1
+ /*! @fluixi/compiler v1.0.0-alpha.100 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
+ import {
3
+ MagicString
4
+ } from "./chunk-HXEXPWJ2.mjs";
5
+ import "./chunk-3AICWNF7.mjs";
6
+ import {
7
+ serverFnId
8
+ } from "./chunk-C3XPDB4Y.mjs";
9
+ import "./chunk-SKAVY75W.mjs";
10
+
11
+ // src/transform/server-fns.ts
12
+ import { parse } from "@babel/parser";
13
+ var RUNTIME = "@fluixi/start/server-fn";
14
+ var FUNCTION_TYPES = /* @__PURE__ */ new Set([
15
+ "FunctionDeclaration",
16
+ "FunctionExpression",
17
+ "ArrowFunctionExpression"
18
+ ]);
19
+ function directive(node) {
20
+ if (!FUNCTION_TYPES.has(node.type)) return null;
21
+ const body = node.body;
22
+ if (!body || body.type !== "BlockStatement") return null;
23
+ for (const d of body.directives ?? []) {
24
+ if (d.value?.value === "use server") return d;
25
+ }
26
+ return null;
27
+ }
28
+ function findServerFns(node, out) {
29
+ if (!node || typeof node !== "object") return;
30
+ if (Array.isArray(node)) {
31
+ for (const child of node) findServerFns(child, out);
32
+ return;
33
+ }
34
+ if (typeof node.type === "string") {
35
+ const found = directive(node);
36
+ if (found) {
37
+ out.push({ fn: node, directive: found });
38
+ return;
39
+ }
40
+ }
41
+ for (const key of Object.keys(node)) {
42
+ if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
43
+ findServerFns(node[key], out);
44
+ }
45
+ }
46
+ function transformServerFns(code, options) {
47
+ if (!code.includes("use server")) return null;
48
+ const ast = parse(code, {
49
+ sourceType: "module",
50
+ plugins: ["jsx", "typescript"],
51
+ errorRecovery: true
52
+ });
53
+ const found = [];
54
+ findServerFns(ast.program, found);
55
+ if (found.length === 0) return null;
56
+ const helper = options.ssr ? "$$registerServerFn" : "$$createServerReference";
57
+ const out = new MagicString(code);
58
+ found.forEach(({ fn, directive: dir }, index) => {
59
+ const id = serverFnId(options.filename, options.root, index);
60
+ const declaration = fn.type === "FunctionDeclaration";
61
+ if (!options.ssr) {
62
+ const stub = `${helper}(${JSON.stringify(id)})`;
63
+ out.overwrite(fn.start, fn.end, declaration ? `const ${fn.id.name} = ${stub};` : stub);
64
+ return;
65
+ }
66
+ out.remove(dir.start, dir.end);
67
+ out.appendLeft(fn.start, declaration ? `const ${fn.id.name} = ${helper}(${JSON.stringify(id)}, ` : `${helper}(${JSON.stringify(id)}, `);
68
+ out.appendRight(fn.end, declaration ? ");" : ")");
69
+ });
70
+ out.prepend(`import { ${helper} } from ${JSON.stringify(options.runtimeModule ?? RUNTIME)};
71
+ `);
72
+ return {
73
+ code: out.toString(),
74
+ map: out.generateMap({ source: options.filename, includeContent: true, hires: true })
75
+ };
76
+ }
77
+ export {
78
+ transformServerFns
79
+ };
@@ -0,0 +1,82 @@
1
+ /*! @fluixi/compiler v1.0.0-alpha.100 | (c) 2026 Ibrahima Touré and Fluixi contributors | MIT */
2
+ import {
3
+ serverFnId
4
+ } from "./chunk-C3XPDB4Y.mjs";
5
+ import "./chunk-SKAVY75W.mjs";
6
+
7
+ // src/frontend/babel/server-functions.ts
8
+ import { transformSync } from "@babel/core";
9
+ var RUNTIME = "@fluixi/start/server-fn";
10
+ function serverFunctionsBabelPlugin({ types: t }) {
11
+ return {
12
+ name: "fluixi-server-functions",
13
+ visitor: {
14
+ Program: {
15
+ enter(_path, state) {
16
+ state.fxIndex = 0;
17
+ state.fxUsed = null;
18
+ },
19
+ exit(path, state) {
20
+ if (!state.fxUsed) return;
21
+ path.unshiftContainer(
22
+ "body",
23
+ t.importDeclaration(
24
+ [t.importSpecifier(t.identifier(state.fxUsed), t.identifier(state.fxUsed))],
25
+ t.stringLiteral(state.opts.runtimeModule || RUNTIME)
26
+ )
27
+ );
28
+ }
29
+ },
30
+ "FunctionDeclaration|FunctionExpression|ArrowFunctionExpression": (path, state) => {
31
+ const body = path.node.body;
32
+ if (!t.isBlockStatement(body)) return;
33
+ const dirs = body.directives || [];
34
+ const di = dirs.findIndex((d) => d.value.value === "use server");
35
+ if (di < 0) return;
36
+ body.directives.splice(di, 1);
37
+ const id = serverFnId(
38
+ state.opts.filename || state.filename || "unknown",
39
+ state.opts.root,
40
+ state.fxIndex++
41
+ );
42
+ const ssr = !!state.opts.ssr;
43
+ const helper = ssr ? "$$registerServerFn" : "$$createServerReference";
44
+ state.fxUsed = helper;
45
+ const replacement = ssr ? t.callExpression(t.identifier(helper), [
46
+ t.stringLiteral(id),
47
+ path.isFunctionDeclaration() ? t.functionExpression(
48
+ null,
49
+ path.node.params,
50
+ body,
51
+ path.node.generator,
52
+ path.node.async
53
+ ) : path.node
54
+ ]) : t.callExpression(t.identifier(helper), [t.stringLiteral(id)]);
55
+ if (path.isFunctionDeclaration()) {
56
+ path.replaceWith(
57
+ t.variableDeclaration("const", [t.variableDeclarator(path.node.id, replacement)])
58
+ );
59
+ } else {
60
+ path.replaceWith(replacement);
61
+ }
62
+ path.skip();
63
+ }
64
+ }
65
+ };
66
+ }
67
+ function transformServerFunctions(code, opts) {
68
+ if (!code.includes("use server")) return null;
69
+ const result = transformSync(code, {
70
+ filename: opts.filename,
71
+ configFile: false,
72
+ babelrc: false,
73
+ sourceMaps: true,
74
+ parserOpts: { plugins: ["typescript", "jsx"] },
75
+ plugins: [[serverFunctionsBabelPlugin, opts]]
76
+ });
77
+ if (!result?.code) return null;
78
+ return { code: result.code, map: result.map };
79
+ }
80
+ export {
81
+ transformServerFunctions
82
+ };