@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,33 @@
1
+ /**
2
+ * Build IR from a JSX tree.
3
+ *
4
+ * Reads `node.type` rather than a parser's helpers, and asks the caller for the
5
+ * source of an expression through `code()`: a front-end that can slice the
6
+ * original text returns that, one that reprints returns the printed form. Either
7
+ * way the IR is the same, which is what keeps one builder for both.
8
+ */
9
+ import type { IRNode } from '../ir/nodes.cjs';
10
+ interface Node {
11
+ type: string;
12
+ [key: string]: any;
13
+ }
14
+ export interface JsxContext {
15
+ /** The source of an expression node, with anything nested already compiled. */
16
+ code(node: Node): string;
17
+ /** Runtime symbols the emitted code needs; `use:` directives register here too. */
18
+ used: Set<string>;
19
+ /** The file being compiled, when component usage sites are to be recorded. */
20
+ sourceFile?: string;
21
+ /** Scoped styles: intrinsic elements inside a range get `data-fx-s` set to its value. */
22
+ scopes?: {
23
+ start: number;
24
+ end: number;
25
+ value: string;
26
+ }[];
27
+ /** Start offsets of `<style>` elements the compiler took out of the template. */
28
+ dropStyles?: Set<number>;
29
+ }
30
+ export declare const SVG_TAGS: Set<string>;
31
+ /** Build IR from a JSXElement or JSXFragment. */
32
+ export declare function buildJsxIR(node: Node, ctx: JsxContext): IRNode;
33
+ export {};
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Build IR from a JSX tree.
3
+ *
4
+ * Reads `node.type` rather than a parser's helpers, and asks the caller for the
5
+ * source of an expression through `code()`: a front-end that can slice the
6
+ * original text returns that, one that reprints returns the printed form. Either
7
+ * way the IR is the same, which is what keeps one builder for both.
8
+ */
9
+ import type { IRNode } from '../ir/nodes.js';
10
+ interface Node {
11
+ type: string;
12
+ [key: string]: any;
13
+ }
14
+ export interface JsxContext {
15
+ /** The source of an expression node, with anything nested already compiled. */
16
+ code(node: Node): string;
17
+ /** Runtime symbols the emitted code needs; `use:` directives register here too. */
18
+ used: Set<string>;
19
+ /** The file being compiled, when component usage sites are to be recorded. */
20
+ sourceFile?: string;
21
+ /** Scoped styles: intrinsic elements inside a range get `data-fx-s` set to its value. */
22
+ scopes?: {
23
+ start: number;
24
+ end: number;
25
+ value: string;
26
+ }[];
27
+ /** Start offsets of `<style>` elements the compiler took out of the template. */
28
+ dropStyles?: Set<number>;
29
+ }
30
+ export declare const SVG_TAGS: Set<string>;
31
+ /** Build IR from a JSXElement or JSXFragment. */
32
+ export declare function buildJsxIR(node: Node, ctx: JsxContext): IRNode;
33
+ export {};
34
+ //# sourceMappingURL=jsx.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsx.d.ts","sourceRoot":"","sources":["../../src/lower/jsx.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAkB,MAAM,EAAsB,MAAM,gBAAgB,CAAC;AAUjF,UAAU,IAAI;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,+EAA+E;IAC/E,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAAC;IACzB,mFAAmF;IACnF,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAClB,8EAA8E;IAC9E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,yFAAyF;IACzF,MAAM,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACzD,iFAAiF;IACjF,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CAC1B;AAED,eAAO,MAAM,QAAQ,aAGnB,CAAC;AAoYH,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,GAAG,MAAM,CAM9D"}
@@ -0,0 +1,414 @@
1
+ import { isLoadDirective, parseLoadDirective, LoadDirectiveError } from '../resolve/load-directive.js';
2
+ import { isReactiveShape } from '../analyze/reactive-expr.js';
3
+ import { shapeOf } from '../analyze/expr-shape.js';
4
+ import { analyzeStatic } from '../optimize/analyze-static.js';
5
+ import { cleanTemplateText } from './text.js';
6
+ import { paren } from '../analyze/paren.js';
7
+ import { markHole } from '../transform/source-locations.js';
8
+ import { imperativeBackend, inlineTemplates } from '../codegen/backends/imperative.js';
9
+ export const SVG_TAGS = new Set([
10
+ 'svg', 'path', 'circle', 'rect', 'line', 'polygon', 'polyline',
11
+ 'ellipse', 'g', 'defs', 'clipPath', 'text',
12
+ ]);
13
+ const EVENT_RE = /^on[A-Z]/;
14
+ const DELEGATED = new Set([
15
+ 'click', 'dblclick', 'input', 'change', 'submit', 'focus', 'blur',
16
+ 'keydown', 'keyup', 'keypress', 'mousedown', 'mouseup',
17
+ ]);
18
+ const isReactive = (node) => isReactiveShape(shapeOf(node));
19
+ /** The tag that carries directives and renders only its content. Never a custom element: no dash. */
20
+ const CONTAINER = 'container';
21
+ /** An intrinsic element's `if`, `else`, `each` or `key` attribute, as written. */
22
+ function directive(node, name) {
23
+ if (node.type !== 'JSXElement')
24
+ return undefined;
25
+ const opening = node.openingElement;
26
+ if (opening.name.type !== 'JSXIdentifier' || opening.name.name[0] !== opening.name.name[0].toLowerCase())
27
+ return undefined;
28
+ return opening.attributes.find((a) => a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && a.name.name === name);
29
+ }
30
+ /** The expression a directive holds: `if={cond}`. */
31
+ function directiveExpr(attr) {
32
+ const v = attr.value;
33
+ return v?.type === 'JSXExpressionContainer' && v.expression?.type !== 'JSXEmptyExpression' ? v.expression : undefined;
34
+ }
35
+ /** A nested subtree as code, for `Show`'s fallback and `For`'s render function. */
36
+ function emitIR(ir, ctx) {
37
+ const { code, imports, templates } = imperativeBackend.emit(ir, {});
38
+ for (const s of imports)
39
+ ctx.used.add(s);
40
+ return inlineTemplates(code, templates);
41
+ }
42
+ /** Only when the host asked for source locations, the flag that records usage sites too. */
43
+ const posOf = (node, ctx) => {
44
+ if (!ctx.sourceFile)
45
+ return undefined;
46
+ const at = node.loc?.start;
47
+ return at ? { line: at.line, column: at.column } : undefined;
48
+ };
49
+ /** A literal value, or undefined when the node is not one. */
50
+ function literalOf(node) {
51
+ if (node.type === 'StringLiteral' || node.type === 'NumericLiteral' || node.type === 'BooleanLiteral') {
52
+ return node.value;
53
+ }
54
+ // ESTree spells all three `Literal`; regexes and null are not values we inline.
55
+ if (node.type === 'Literal' && (typeof node.value === 'string' || typeof node.value === 'number' || typeof node.value === 'boolean')) {
56
+ return node.value;
57
+ }
58
+ return undefined;
59
+ }
60
+ const isString = (node) => !!node && typeof literalOf(node) === 'string';
61
+ /** A capitalized / member / namespaced tag is a component. */
62
+ function tagInfo(name, ctx) {
63
+ if (name.type === 'JSXIdentifier') {
64
+ return { tag: name.name, component: name.name[0] !== name.name[0].toLowerCase() };
65
+ }
66
+ if (name.type === 'JSXMemberExpression')
67
+ return { tag: ctx.code(name), component: true };
68
+ if (name.type === 'JSXNamespacedName') {
69
+ return { tag: `${name.namespace.name}:${name.name.name}`, component: false };
70
+ }
71
+ return { tag: 'div', component: false };
72
+ }
73
+ function attrName(name) {
74
+ if (name.type === 'JSXIdentifier')
75
+ return name.name === 'class' ? 'className' : name.name;
76
+ if (name.type === 'JSXNamespacedName')
77
+ return `${name.namespace.name}:${name.name.name}`;
78
+ return 'unknown';
79
+ }
80
+ function buildAttr(attr, ctx) {
81
+ const name = attrName(attr.name);
82
+ const isEvent = EVENT_RE.test(name);
83
+ // on: reaches the runtime as a native listener; a handler, never reactive. `ref`
84
+ // joins them: the runtime CALLS it with the element, so a thunk gets called
85
+ // instead and the real ref never sees anything.
86
+ const isHandler = isEvent || name.startsWith('on:') || name === 'ref';
87
+ const kind = isEvent ? 'event' : 'attr';
88
+ const base = { name, kind };
89
+ if (isEvent) {
90
+ const evt = name.slice(2).toLowerCase();
91
+ base.event = { name: evt, delegated: DELEGATED.has(evt) };
92
+ }
93
+ const v = attr.value;
94
+ if (v == null) {
95
+ base.literal = true; // valueless attribute
96
+ base.at = posOf(attr, ctx);
97
+ return base;
98
+ }
99
+ if (isString(v)) {
100
+ base.literal = literalOf(v);
101
+ base.at = posOf(v, ctx);
102
+ return base;
103
+ }
104
+ if (v.type === 'JSXExpressionContainer' && v.expression?.type !== 'JSXEmptyExpression') {
105
+ const expr = v.expression;
106
+ const literal = literalOf(expr);
107
+ if (literal !== undefined) {
108
+ base.literal = literal;
109
+ base.at = posOf(expr, ctx);
110
+ return base;
111
+ }
112
+ base.expr = ctx.code(expr);
113
+ base.reactive = isHandler ? false : isReactive(expr);
114
+ // Every prop, not only the ones that move: a panel names the line for each of them.
115
+ // Nothing treats this as a binding position: that asks for `reactive` as well.
116
+ base.at = posOf(expr, ctx);
117
+ if (expr.type === 'JSXElement' || expr.type === 'JSXFragment')
118
+ base.jsxElement = true;
119
+ return base;
120
+ }
121
+ base.literal = true;
122
+ return base;
123
+ }
124
+ /** Attribute value as JS code, or null when valueless. */
125
+ function attrExprCode(attr, ctx) {
126
+ const v = attr.value;
127
+ if (v == null)
128
+ return null;
129
+ if (isString(v))
130
+ return JSON.stringify(literalOf(v));
131
+ if (v.type === 'JSXExpressionContainer' && v.expression?.type !== 'JSXEmptyExpression') {
132
+ return ctx.code(v.expression);
133
+ }
134
+ return null;
135
+ }
136
+ /**
137
+ * `element`: the tag is a DOM element. Only there are class:/style: and a style object taken
138
+ * apart; a component gets its props as written.
139
+ */
140
+ function buildProps(attrs, ctx, element = false) {
141
+ const props = [];
142
+ const usePairs = []; // use:name directives collapse into one `use` prop
143
+ // class:x and style:x collapse into one classList / style object, as in templates; each
144
+ // value that moves is an accessor in it, so the runtime updates that one key.
145
+ const classEntries = [];
146
+ const styleEntries = [];
147
+ let styleAt;
148
+ for (const a of attrs) {
149
+ if (a.type === 'JSXSpreadAttribute') {
150
+ props.push({ name: '', kind: 'spread', expr: ctx.code(a.argument) });
151
+ continue;
152
+ }
153
+ if (a.type !== 'JSXAttribute')
154
+ continue;
155
+ // load: is a directive, not a prop: the resolve pass reads it off the node.
156
+ if (isLoadDirective(attrName(a.name)))
157
+ continue;
158
+ const ns = a.name.type === 'JSXNamespacedName' ? a.name.namespace.name : null;
159
+ // use:name / use:name={opts} -> [dir, () => opts]; dir is an in-scope fn
160
+ if (ns === 'use') {
161
+ const dir = a.name.name.name;
162
+ ctx.used.add(dir); // keep the import
163
+ const opts = attrExprCode(a, ctx);
164
+ // parens round the body so an object literal is not read as a block
165
+ usePairs.push(opts != null ? `[${dir}, () => ${paren(opts, 'arrowBody')}]` : `[${dir}]`);
166
+ continue;
167
+ }
168
+ if (element && (ns === 'class' || ns === 'style')) {
169
+ const key = JSON.stringify(a.name.name.name);
170
+ const v = a.value;
171
+ let value;
172
+ if (v == null)
173
+ value = 'true';
174
+ else if (isString(v))
175
+ value = JSON.stringify(literalOf(v));
176
+ else if (v.type === 'JSXExpressionContainer' && v.expression?.type !== 'JSXEmptyExpression') {
177
+ value = keyValue(v.expression, ctx);
178
+ if (ns === 'style')
179
+ styleAt ??= posOf(v.expression, ctx);
180
+ }
181
+ else
182
+ continue;
183
+ (ns === 'class' ? classEntries : styleEntries).push(`${key}: ${value}`);
184
+ continue;
185
+ }
186
+ // style={{ … }}: one entry per property, so `--gap` moving does not rewrite `margin`.
187
+ if (element && a.name.type === 'JSXIdentifier' && a.name.name === 'style' && a.value?.type === 'JSXExpressionContainer') {
188
+ const entries = objectEntries(a.value.expression, ctx);
189
+ if (entries) {
190
+ styleEntries.unshift(...entries);
191
+ styleAt = posOf(a.value.expression, ctx);
192
+ continue;
193
+ }
194
+ }
195
+ // oncapture:name -> native on:name with { capture: true }
196
+ if (ns === 'oncapture') {
197
+ const evt = a.name.name.name.toLowerCase();
198
+ const h = attrExprCode(a, ctx) ?? 'undefined';
199
+ props.push({ name: 'on:' + evt, kind: 'attr', expr: `[${h}, { capture: true }]` });
200
+ continue;
201
+ }
202
+ props.push(buildAttr(a, ctx));
203
+ }
204
+ if (classEntries.length > 0)
205
+ props.push({ name: 'classList', kind: 'attr', expr: `{ ${classEntries.join(', ')} }`, reactive: false });
206
+ if (styleEntries.length > 0) {
207
+ const entries = `{ ${styleEntries.join(', ')} }`;
208
+ // A style the object form could not take apart (a string, a variable) goes first, and
209
+ // the keys after it: the runtime applies an array in order.
210
+ const base = props.findIndex((p) => p.name === 'style' && p.kind === 'attr');
211
+ if (base === -1)
212
+ props.push({ name: 'style', kind: 'attr', expr: entries, reactive: false, ...(styleAt ? { at: styleAt } : {}) });
213
+ else {
214
+ const prop = props[base];
215
+ const value = prop.literal !== undefined ? JSON.stringify(prop.literal) : prop.reactive ? `() => ${paren(prop.expr, 'arrowBody')}` : prop.expr;
216
+ props[base] = { name: 'style', kind: 'attr', expr: `[${value}, ${entries}]`, reactive: false, ...(prop.at ? { at: prop.at } : {}) };
217
+ }
218
+ }
219
+ if (usePairs.length > 0)
220
+ props.push({ name: 'use', kind: 'attr', expr: `[${usePairs.join(', ')}]` });
221
+ return props;
222
+ }
223
+ /** A value inside a classList / style object: an accessor when it moves. */
224
+ function keyValue(expr, ctx) {
225
+ const code = ctx.code(expr);
226
+ if (!isReactive(expr))
227
+ return code;
228
+ const accessor = `() => ${paren(code, 'arrowBody')}`;
229
+ const at = posOf(expr, ctx);
230
+ return at ? markHole(accessor, at.line, at.column) : accessor;
231
+ }
232
+ /** `{ a: x, '--b': y }` as object entries; null for anything with a spread or a method. */
233
+ function objectEntries(expr, ctx) {
234
+ if (expr?.type !== 'ObjectExpression')
235
+ return null;
236
+ const entries = [];
237
+ for (const p of expr.properties) {
238
+ if (p.type !== 'ObjectProperty')
239
+ return null;
240
+ const key = p.computed
241
+ ? `[${ctx.code(p.key)}]`
242
+ : p.key.type === 'Identifier'
243
+ ? JSON.stringify(p.key.name)
244
+ : JSON.stringify(String(p.key.value));
245
+ entries.push(`${key}: ${keyValue(p.value, ctx)}`);
246
+ }
247
+ return entries;
248
+ }
249
+ function buildChildren(children, ctx) {
250
+ const out = [];
251
+ for (let i = 0; i < children.length; i++) {
252
+ const child = children[i];
253
+ if (directive(child, 'if')) {
254
+ // The next element, past whitespace, is the fallback when it says `else`.
255
+ let next = i + 1;
256
+ while (next < children.length && children[next].type === 'JSXText' && !cleanTemplateText(children[next].value))
257
+ next++;
258
+ const fallback = directive(children[next], 'else') ? children[next] : null;
259
+ out.push(buildIf(child, fallback, ctx));
260
+ if (fallback)
261
+ i = next;
262
+ continue;
263
+ }
264
+ if (child.type === 'JSXText') {
265
+ // Drop whitespace-only text spanning a newline so a lone child stays lone ,
266
+ // an array insert will not reactively bind a memo/component inside it.
267
+ const text = cleanTemplateText(child.value);
268
+ if (text)
269
+ out.push({ kind: 'text', value: text });
270
+ }
271
+ else if (child.type === 'JSXExpressionContainer') {
272
+ if (child.expression?.type !== 'JSXEmptyExpression') {
273
+ const expr = child.expression;
274
+ const reactive = isReactive(expr);
275
+ out.push({
276
+ kind: 'expr',
277
+ code: ctx.code(expr),
278
+ reactive,
279
+ ...(reactive ? { at: posOf(expr, ctx) } : {}),
280
+ });
281
+ }
282
+ }
283
+ else if (child.type === 'JSXElement' || child.type === 'JSXFragment') {
284
+ // A `<style>` the compiler took out leaves no child behind, not even an empty insert.
285
+ if (ctx.dropStyles?.has(child.start))
286
+ continue;
287
+ out.push(buildNode(child, ctx));
288
+ }
289
+ else if (child.type === 'JSXSpreadChild') {
290
+ out.push({ kind: 'expr', code: ctx.code(child.expression), reactive: false });
291
+ }
292
+ }
293
+ return out;
294
+ }
295
+ /** The load: strategy written on a component tag, if any. */
296
+ function readLoad(attrs) {
297
+ for (const a of attrs) {
298
+ if (a.type !== 'JSXAttribute')
299
+ continue;
300
+ const name = attrName(a.name);
301
+ if (!isLoadDirective(name))
302
+ continue;
303
+ if (a.value && !isString(a.value)) {
304
+ throw new LoadDirectiveError(`'${name}' needs a literal value, not an expression — the strategy is compile-time.`);
305
+ }
306
+ return parseLoadDirective(name, a.value ? literalOf(a.value) : null);
307
+ }
308
+ return undefined;
309
+ }
310
+ /** `<el if={cond}>` and an optional `<el else>` after it → `<Show when fallback>`. */
311
+ function buildIf(node, fallback, ctx) {
312
+ const cond = directiveExpr(directive(node, 'if'));
313
+ const props = [
314
+ cond
315
+ ? { name: 'when', kind: 'attr', expr: ctx.code(cond), reactive: isReactive(cond), at: posOf(cond, ctx) }
316
+ : { name: 'when', kind: 'attr', literal: true },
317
+ ];
318
+ if (fallback) {
319
+ props.push({ name: 'fallback', kind: 'attr', expr: emitIR(buildElement(fallback, ctx, ['else']), ctx), jsxElement: true });
320
+ }
321
+ return { kind: 'component', name: 'Show', props, children: [buildElement(node, ctx, ['if'])] };
322
+ }
323
+ /**
324
+ * `<el each={items} key?>{(item) => …}</el>` → `<el><For each by>{…}</For></el>`: the
325
+ * content repeats, the element does not. Null when there is no `each`.
326
+ */
327
+ function buildEach(node, ctx) {
328
+ const attr = directive(node, 'each');
329
+ if (!attr)
330
+ return null;
331
+ const list = directiveExpr(attr);
332
+ const props = [
333
+ list
334
+ ? { name: 'each', kind: 'attr', expr: ctx.code(list), reactive: isReactive(list), at: posOf(list, ctx) }
335
+ : { name: 'each', kind: 'attr', expr: '[]' },
336
+ ];
337
+ const key = directive(node, 'key');
338
+ if (key) {
339
+ const keyExpr = directiveExpr(key);
340
+ const by = isString(key.value)
341
+ ? `(item) => item[${JSON.stringify(literalOf(key.value))}]`
342
+ : keyExpr
343
+ ? ctx.code(keyExpr)
344
+ : undefined;
345
+ if (by)
346
+ props.push({ name: 'by', kind: 'attr', expr: by });
347
+ }
348
+ const content = node.children.filter((c) => !(c.type === 'JSXText' && !cleanTemplateText(c.value)));
349
+ const only = content.length === 1 && content[0].type === 'JSXExpressionContainer' ? content[0].expression : null;
350
+ let render;
351
+ if (only && (only.type === 'ArrowFunctionExpression' || only.type === 'FunctionExpression')) {
352
+ const fn = ctx.code(only);
353
+ // A body that reads signals, `{(it) => it.label + count()}`, is handed back as an
354
+ // accessor so the runtime binds it; a body that builds elements needs nothing.
355
+ const live = only.type === 'ArrowFunctionExpression' && only.body.type !== 'BlockStatement' && isReactive(only.body);
356
+ render = live ? `(...args) => () => (${fn})(...args)` : fn;
357
+ }
358
+ else {
359
+ const built = buildChildren(node.children, ctx);
360
+ const ir = built.length === 1 ? built[0] : { kind: 'fragment', children: built };
361
+ render = `() => ${paren(emitIR(ir, ctx), 'arrowBody')}`;
362
+ }
363
+ return { kind: 'component', name: 'For', props, children: [{ kind: 'expr', code: render, reactive: false }] };
364
+ }
365
+ /** An element, with the directives already handled by the caller left out. */
366
+ function buildElement(node, ctx, handled) {
367
+ const skip = new Set(handled);
368
+ // `key` is only a directive beside `each`; anywhere else it is an ordinary attribute.
369
+ const directives = new Set(['if', 'else', 'each', ...(directive(node, 'each') ? ['key'] : [])]);
370
+ const attributes = node.openingElement.attributes.filter((a) => !(a.type === 'JSXAttribute' && a.name.type === 'JSXIdentifier' && (skip.has(a.name.name) || directives.has(a.name.name))));
371
+ const { tag } = tagInfo(node.openingElement.name, ctx);
372
+ const each = buildEach(node, ctx);
373
+ const children = each ? [each] : buildChildren(node.children, ctx);
374
+ if (tag === CONTAINER)
375
+ return children.length === 1 ? children[0] : { kind: 'fragment', children };
376
+ const at = ctx.sourceFile && node.loc?.start
377
+ ? { file: ctx.sourceFile, line: node.loc.start.line, column: node.loc.start.column }
378
+ : undefined;
379
+ const props = buildProps(attributes, ctx, true);
380
+ // A scoped style's mark: a static attribute, so it is part of the template itself and
381
+ // every render carries it, on the client, from the server and through hydration.
382
+ const scope = ctx.scopes?.find((s) => node.start >= s.start && node.end <= s.end);
383
+ if (scope)
384
+ props.unshift({ name: 'data-fx-s', kind: 'attr', literal: scope.value });
385
+ return { kind: 'element', tag, svg: SVG_TAGS.has(tag), props, children, static: false, ...(at ? { at } : {}) };
386
+ }
387
+ function buildNode(node, ctx) {
388
+ if (node.type === 'JSXFragment') {
389
+ return { kind: 'fragment', children: buildChildren(node.children, ctx) };
390
+ }
391
+ if (directive(node, 'if'))
392
+ return buildIf(node, null, ctx);
393
+ // Its CSS went to the host; nothing of the element is rendered.
394
+ if (ctx.dropStyles?.has(node.start))
395
+ return { kind: 'fragment', children: [] };
396
+ const { tag, component } = tagInfo(node.openingElement.name, ctx);
397
+ if (!component)
398
+ return buildElement(node, ctx, []);
399
+ const props = buildProps(node.openingElement.attributes, ctx);
400
+ const children = buildChildren(node.children, ctx);
401
+ const at = ctx.sourceFile && node.loc?.start
402
+ ? { file: ctx.sourceFile, line: node.loc.start.line, column: node.loc.start.column }
403
+ : undefined;
404
+ const load = readLoad(node.openingElement.attributes);
405
+ return { kind: 'component', name: tag, props, children, ...(load ? { load } : {}), ...(at ? { at } : {}) };
406
+ }
407
+ /** Build IR from a JSXElement or JSXFragment. */
408
+ export function buildJsxIR(node, ctx) {
409
+ const ir = buildNode(node, ctx);
410
+ // `static` is a property of a whole subtree, so one pass decides it rather than
411
+ // each node at construction.
412
+ analyzeStatic(ir);
413
+ return ir;
414
+ }