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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) 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 -1
  23. package/dist/analyze/static-graph.d.cts +102 -0
  24. package/dist/analyze/static-graph.mjs +793 -1
  25. package/dist/babel-NRW4EFTG.mjs +636 -0
  26. package/dist/chunk-3YKZ4GNH.mjs +11 -0
  27. package/dist/chunk-EZR7NZOY.mjs +1718 -0
  28. package/dist/chunk-FSSWUXUR.mjs +16 -0
  29. package/dist/chunk-MJV3UXIL.mjs +158 -0
  30. package/dist/chunk-R2VHAZAX.mjs +1078 -0
  31. package/dist/codegen/backend.cjs +18 -1
  32. package/dist/codegen/backend.d.cts +35 -0
  33. package/dist/codegen/backends/imperative.cjs +542 -1
  34. package/dist/codegen/backends/imperative.d.cts +11 -0
  35. package/dist/codegen/backends/imperative.d.ts.map +1 -1
  36. package/dist/codegen/backends/imperative.js +12 -8
  37. package/dist/codegen/backends/imperative.mjs +519 -1
  38. package/dist/codegen/contract.cjs +52 -1
  39. package/dist/codegen/contract.d.cts +24 -0
  40. package/dist/codegen/contract.mjs +31 -1
  41. package/dist/codegen/partial-template.cjs +176 -1
  42. package/dist/codegen/partial-template.d.cts +61 -0
  43. package/dist/codegen/partial-template.mjs +153 -1
  44. package/dist/codegen/serialize-static.cjs +125 -1
  45. package/dist/codegen/serialize-static.d.cts +38 -0
  46. package/dist/codegen/serialize-static.mjs +104 -1
  47. package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
  48. package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
  49. package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
  50. package/dist/frontend/babel/build-ir.cjs +1524 -1
  51. package/dist/frontend/babel/build-ir.d.cts +35 -0
  52. package/dist/frontend/babel/build-ir.mjs +1495 -1
  53. package/dist/frontend/babel/index.cjs +2186 -1
  54. package/dist/frontend/babel/index.d.cts +33 -0
  55. package/dist/frontend/babel/index.mjs +2156 -1
  56. package/dist/frontend/babel/lower-template.cjs +1507 -1
  57. package/dist/frontend/babel/lower-template.d.cts +23 -0
  58. package/dist/frontend/babel/lower-template.mjs +1478 -1
  59. package/dist/frontend/babel/plugin.cjs +2132 -1
  60. package/dist/frontend/babel/plugin.d.cts +95 -0
  61. package/dist/frontend/babel/plugin.mjs +2103 -1
  62. package/dist/frontend/babel/server-functions.cjs +110 -1
  63. package/dist/frontend/babel/server-functions.d.cts +10 -0
  64. package/dist/frontend/babel/server-functions.mjs +89 -1
  65. package/dist/frontend/babel/types.cjs +18 -1
  66. package/dist/frontend/babel/types.d.cts +33 -0
  67. package/dist/frontend/types.cjs +18 -1
  68. package/dist/frontend/types.d.cts +25 -0
  69. package/dist/frontend/vocabulary.cjs +98 -0
  70. package/dist/frontend/vocabulary.d.cts +79 -0
  71. package/dist/frontend/vocabulary.d.ts +80 -0
  72. package/dist/frontend/vocabulary.d.ts.map +1 -0
  73. package/dist/frontend/vocabulary.js +124 -0
  74. package/dist/frontend/vocabulary.mjs +77 -0
  75. package/dist/index.cjs +1594 -13
  76. package/dist/index.d.cts +27 -0
  77. package/dist/index.mjs +1574 -13
  78. package/dist/integrations.cjs +4307 -25
  79. package/dist/integrations.d.cts +215 -0
  80. package/dist/integrations.mjs +531 -17
  81. package/dist/ir/nodes.cjs +18 -1
  82. package/dist/ir/nodes.d.cts +168 -0
  83. package/dist/lower/compile-template.cjs +1356 -1
  84. package/dist/lower/compile-template.d.cts +69 -0
  85. package/dist/lower/compile-template.mjs +1336 -1
  86. package/dist/lower/jsx.cjs +529 -1
  87. package/dist/lower/jsx.d.cts +25 -0
  88. package/dist/lower/jsx.d.ts.map +1 -1
  89. package/dist/lower/jsx.js +2 -1
  90. package/dist/lower/jsx.mjs +506 -1
  91. package/dist/lower/template.cjs +1061 -1
  92. package/dist/lower/template.d.cts +53 -0
  93. package/dist/lower/template.d.ts.map +1 -1
  94. package/dist/lower/template.js +5 -4
  95. package/dist/lower/template.mjs +1042 -1
  96. package/dist/lower/text.cjs +42 -1
  97. package/dist/lower/text.d.cts +10 -0
  98. package/dist/lower/text.mjs +21 -1
  99. package/dist/optimize/analyze-static.cjs +112 -1
  100. package/dist/optimize/analyze-static.d.cts +39 -0
  101. package/dist/optimize/analyze-static.mjs +91 -1
  102. package/dist/optimize/collapse-strategies.cjs +90 -1
  103. package/dist/optimize/collapse-strategies.d.cts +30 -0
  104. package/dist/optimize/collapse-strategies.mjs +67 -1
  105. package/dist/options.cjs +33 -1
  106. package/dist/options.d.cts +39 -0
  107. package/dist/options.mjs +12 -1
  108. package/dist/resolve/builtins.cjs +73 -1
  109. package/dist/resolve/builtins.d.cts +68 -0
  110. package/dist/resolve/builtins.mjs +53 -1
  111. package/dist/resolve/component-globals.cjs +233 -13
  112. package/dist/resolve/component-globals.d.cts +80 -0
  113. package/dist/resolve/component-globals.mjs +210 -13
  114. package/dist/resolve/component-resolver.cjs +80 -1
  115. package/dist/resolve/component-resolver.d.cts +68 -0
  116. package/dist/resolve/component-resolver.mjs +59 -1
  117. package/dist/resolve/load-directive.cjs +93 -1
  118. package/dist/resolve/load-directive.d.cts +53 -0
  119. package/dist/resolve/load-directive.mjs +72 -1
  120. package/dist/resolve/resolve-ir.cjs +108 -1
  121. package/dist/resolve/resolve-ir.d.cts +53 -0
  122. package/dist/resolve/resolve-ir.mjs +85 -1
  123. package/dist/resolve/write-globals.cjs +318 -13
  124. package/dist/resolve/write-globals.d.cts +30 -0
  125. package/dist/resolve/write-globals.mjs +297 -13
  126. package/dist/server-fns-4ZXN6DYU.mjs +78 -0
  127. package/dist/server-functions-V6D6DRIA.mjs +82 -0
  128. package/dist/transform/bindings.cjs +71 -1
  129. package/dist/transform/bindings.d.cts +16 -0
  130. package/dist/transform/bindings.mjs +50 -1
  131. package/dist/transform/index.cjs +2732 -8
  132. package/dist/transform/index.d.cts +15 -0
  133. package/dist/transform/index.mjs +3773 -17
  134. package/dist/transform/intrinsics.cjs +216 -3
  135. package/dist/transform/intrinsics.d.cts +21 -0
  136. package/dist/transform/intrinsics.mjs +193 -3
  137. package/dist/transform/props.cjs +441 -3
  138. package/dist/transform/props.d.cts +45 -0
  139. package/dist/transform/props.mjs +1482 -12
  140. package/dist/transform/server-fn-id.cjs +35 -1
  141. package/dist/transform/server-fn-id.d.cts +9 -0
  142. package/dist/transform/server-fn-id.mjs +14 -1
  143. package/dist/transform/server-fns.cjs +114 -2
  144. package/dist/transform/server-fns.d.cts +12 -0
  145. package/dist/transform/server-fns.mjs +1155 -11
  146. package/dist/transform/source-locations.cjs +330 -1
  147. package/dist/transform/source-locations.d.cts +43 -0
  148. package/dist/transform/source-locations.mjs +307 -1
  149. package/dist/transform/templates.cjs +2701 -7
  150. package/dist/transform/templates.d.cts +69 -0
  151. package/dist/transform/templates.mjs +3743 -16
  152. package/dist/transform-BT4MMASR.mjs +893 -0
  153. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  154. package/package.json +6 -5
  155. package/dist/babel-VXKH6MRQ.mjs +0 -1
  156. package/dist/chunk-3SAEGOMQ.mjs +0 -1
  157. package/dist/chunk-5KMMN5QP.mjs +0 -1
  158. package/dist/chunk-IBRM4W7I.mjs +0 -10
  159. package/dist/chunk-OHHZCYIQ.mjs +0 -1
  160. package/dist/chunk-YKZ54NVE.mjs +0 -1
  161. package/dist/server-fns-6QM243HC.mjs +0 -2
  162. package/dist/server-functions-E3LKCZ4R.mjs +0 -1
  163. package/dist/transform-C4ZXRVGP.mjs +0 -8
@@ -1 +1,42 @@
1
- "use strict";var f=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var c=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var s=(l,e)=>{for(var n in e)f(l,n,{get:e[n],enumerable:!0})},a=(l,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of c(e))!p.call(l,t)&&t!==n&&f(l,t,{get:()=>e[t],enumerable:!(r=o(e,t))||r.enumerable});return l};var g=l=>a(f({},"__esModule",{value:!0}),l);var h={};s(h,{cleanTemplateText:()=>u});module.exports=g(h);function u(l){let e=l.split(/\r\n|\n|\r/),n=0;for(let t=0;t<e.length;t++)/[^ \t]/.test(e[t])&&(n=t);let r="";for(let t=0;t<e.length;t++){let i=e[t].replace(/\t/g," ");t!==0&&(i=i.replace(/^ +/,"")),t!==e.length-1&&(i=i.replace(/ +$/,"")),i&&(t!==n&&(i+=" "),r+=i)}return r}
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/lower/text.ts
21
+ var text_exports = {};
22
+ __export(text_exports, {
23
+ cleanTemplateText: () => cleanTemplateText
24
+ });
25
+ module.exports = __toCommonJS(text_exports);
26
+ function cleanTemplateText(value) {
27
+ const lines = value.split(/\r\n|\n|\r/);
28
+ let lastNonEmpty = 0;
29
+ for (let i = 0; i < lines.length; i++) {
30
+ if (/[^ \t]/.test(lines[i])) lastNonEmpty = i;
31
+ }
32
+ let out = "";
33
+ for (let i = 0; i < lines.length; i++) {
34
+ let line = lines[i].replace(/\t/g, " ");
35
+ if (i !== 0) line = line.replace(/^ +/, "");
36
+ if (i !== lines.length - 1) line = line.replace(/ +$/, "");
37
+ if (!line) continue;
38
+ if (i !== lastNonEmpty) line += " ";
39
+ out += line;
40
+ }
41
+ return out;
42
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Whitespace handling for template text runs.
3
+ *
4
+ * JSX and `` html`...` `` collapse a text run the same way — the rule came from
5
+ * JSX and the template syntax adopted it so an author moving between the two
6
+ * gets the same output. It is pure string work with no parser in it, so it lives
7
+ * here rather than in a front-end, where both can reach it and neither owns it.
8
+ */
9
+ /** Canonical JSX text cleaning — kept identical to plugin.ts cleanTemplateText. */
10
+ export declare function cleanTemplateText(value: string): string;
@@ -1 +1,21 @@
1
- function f(r){let l=r.split(/\r\n|\n|\r/),n=0;for(let t=0;t<l.length;t++)/[^ \t]/.test(l[t])&&(n=t);let i="";for(let t=0;t<l.length;t++){let e=l[t].replace(/\t/g," ");t!==0&&(e=e.replace(/^ +/,"")),t!==l.length-1&&(e=e.replace(/ +$/,"")),e&&(t!==n&&(e+=" "),i+=e)}return i}export{f as cleanTemplateText};
1
+ // src/lower/text.ts
2
+ function cleanTemplateText(value) {
3
+ const lines = value.split(/\r\n|\n|\r/);
4
+ let lastNonEmpty = 0;
5
+ for (let i = 0; i < lines.length; i++) {
6
+ if (/[^ \t]/.test(lines[i])) lastNonEmpty = i;
7
+ }
8
+ let out = "";
9
+ for (let i = 0; i < lines.length; i++) {
10
+ let line = lines[i].replace(/\t/g, " ");
11
+ if (i !== 0) line = line.replace(/^ +/, "");
12
+ if (i !== lines.length - 1) line = line.replace(/ +$/, "");
13
+ if (!line) continue;
14
+ if (i !== lastNonEmpty) line += " ";
15
+ out += line;
16
+ }
17
+ return out;
18
+ }
19
+ export {
20
+ cleanTemplateText
21
+ };
@@ -1 +1,112 @@
1
- "use strict";var a=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var d=(r,e)=>{for(var s in e)a(r,s,{get:e[s],enumerable:!0})},u=(r,e,s,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of f(e))!p.call(r,t)&&t!==s&&a(r,t,{get:()=>e[t],enumerable:!(n=l(e,t))||n.enumerable});return r};var R=r=>u(a({},"__esModule",{value:!0}),r);var y={};d(y,{analyzeStatic:()=>m,staticRoots:()=>x});module.exports=R(y);function h(r){switch(r.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return r.reactive?"reactive-prop":r.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function m(r){let e=[],s=new Map,n=t=>{switch(t.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let i of t.children)n(i);return!1;case"fragment":for(let i of t.children)n(i);return!1;case"element":{let i=!0;for(let o of t.children)n(o)||(i=!1);let c;for(let o of t.props)if(c=h(o),c)break;return!c&&!i&&(c=I(t)),t.static=!c,c?s.set(t,c):e.push(t),t.static}default:return!1}};for(let t of Array.isArray(r)?r:[r])n(t);return{staticElements:e,reasons:s}}function I(r){for(let e of r.children){if(e.kind==="expr")return"expression-child";if(e.kind==="component")return"component-child";if(e.kind==="control")return"control-child";if(e.kind==="element"&&!e.static||e.kind==="fragment")return"expression-child"}return"expression-child"}function x(r){let e=[],s=n=>{if(n.kind==="element"&&n.static){e.push(n);return}let t=n.children;if(t)for(let i of t)s(i)};for(let n of Array.isArray(r)?r:[r])s(n);return e}
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/optimize/analyze-static.ts
21
+ var analyze_static_exports = {};
22
+ __export(analyze_static_exports, {
23
+ analyzeStatic: () => analyzeStatic,
24
+ staticRoots: () => staticRoots
25
+ });
26
+ module.exports = __toCommonJS(analyze_static_exports);
27
+ function propReason(prop) {
28
+ switch (prop.kind) {
29
+ case "event":
30
+ return "event";
31
+ case "ref":
32
+ return "ref";
33
+ case "spread":
34
+ return "spread";
35
+ case "class":
36
+ case "style":
37
+ return "class-or-style-directive";
38
+ case "attr":
39
+ case "prop":
40
+ if (prop.reactive) return "reactive-prop";
41
+ if (prop.expr !== void 0) return "expression-prop";
42
+ return void 0;
43
+ /* c8 ignore next 2 */
44
+ default:
45
+ return "expression-prop";
46
+ }
47
+ }
48
+ function analyzeStatic(root) {
49
+ const staticElements = [];
50
+ const reasons = /* @__PURE__ */ new Map();
51
+ const visit = (node) => {
52
+ switch (node.kind) {
53
+ case "text":
54
+ return true;
55
+ case "expr":
56
+ return false;
57
+ case "component":
58
+ case "control":
59
+ for (const child of node.children) visit(child);
60
+ return false;
61
+ case "fragment":
62
+ for (const child of node.children) visit(child);
63
+ return false;
64
+ case "element": {
65
+ let childrenStatic = true;
66
+ for (const child of node.children) {
67
+ if (!visit(child)) childrenStatic = false;
68
+ }
69
+ let reason;
70
+ for (const prop of node.props) {
71
+ reason = propReason(prop);
72
+ if (reason) break;
73
+ }
74
+ if (!reason && !childrenStatic) {
75
+ reason = childReason(node);
76
+ }
77
+ node.static = !reason;
78
+ if (reason) reasons.set(node, reason);
79
+ else staticElements.push(node);
80
+ return node.static;
81
+ }
82
+ /* c8 ignore next 2 */
83
+ default:
84
+ return false;
85
+ }
86
+ };
87
+ for (const node of Array.isArray(root) ? root : [root]) visit(node);
88
+ return { staticElements, reasons };
89
+ }
90
+ function childReason(node) {
91
+ for (const child of node.children) {
92
+ if (child.kind === "expr") return "expression-child";
93
+ if (child.kind === "component") return "component-child";
94
+ if (child.kind === "control") return "control-child";
95
+ if (child.kind === "element" && !child.static) return "expression-child";
96
+ if (child.kind === "fragment") return "expression-child";
97
+ }
98
+ return "expression-child";
99
+ }
100
+ function staticRoots(root) {
101
+ const roots = [];
102
+ const visit = (node) => {
103
+ if (node.kind === "element" && node.static) {
104
+ roots.push(node);
105
+ return;
106
+ }
107
+ const children = node.children;
108
+ if (children) for (const child of children) visit(child);
109
+ };
110
+ for (const node of Array.isArray(root) ? root : [root]) visit(node);
111
+ return roots;
112
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Static analysis: mark the element subtrees that never change after creation.
3
+ *
4
+ * A static subtree can be built once as an HTML string and cloned per instance, instead
5
+ * of constructed an element at a time. That is the difference between one `cloneNode`
6
+ * and N `createElement` + N `spread` calls — measured at 2.1x faster for a three-element
7
+ * row and 2.4x for a nine-element card, with the gap widening as components grow.
8
+ *
9
+ * `IRElement.static` has existed since the IR was written, documented as
10
+ * "subtree has no dynamic parts → hoistable (template-clone)", but was hardcoded `false`
11
+ * with no producer. This is the producer.
12
+ *
13
+ * The analysis is deliberately conservative: marking something static that is not is a
14
+ * correctness bug (a shared DOM node across renders), while missing one is only a lost
15
+ * optimisation. Anything not positively known to be inert makes its whole ancestry
16
+ * dynamic.
17
+ */
18
+ import type { IRNode, IRElement } from '../ir/nodes.cjs';
19
+ /** Why a subtree could not be treated as static. Useful for diagnostics and tests. */
20
+ export type DynamicReason = 'reactive-prop' | 'expression-prop' | 'event' | 'ref' | 'spread' | 'class-or-style-directive' | 'expression-child' | 'component-child' | 'control-child';
21
+ export interface StaticReport {
22
+ /** Elements marked static, in visit order. */
23
+ staticElements: IRElement[];
24
+ /** Why each non-static element was rejected, keyed by the element node. */
25
+ reasons: Map<IRElement, DynamicReason>;
26
+ }
27
+ /**
28
+ * Mark every static element in the tree, returning what was decided.
29
+ *
30
+ * Mutates `IRElement.static` in place, since that field is the contract codegen reads.
31
+ */
32
+ export declare function analyzeStatic(root: IRNode | IRNode[]): StaticReport;
33
+ /**
34
+ * The outermost static elements — the roots worth turning into templates.
35
+ *
36
+ * Cloning a static child of a static parent is wasted: the parent's template already
37
+ * contains it.
38
+ */
39
+ export declare function staticRoots(root: IRNode | IRNode[]): IRElement[];
@@ -1 +1,91 @@
1
- function a(r){switch(r.kind){case"event":return"event";case"ref":return"ref";case"spread":return"spread";case"class":case"style":return"class-or-style-directive";case"attr":case"prop":return r.reactive?"reactive-prop":r.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function f(r){let t=[],c=new Map,n=e=>{switch(e.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of e.children)n(s);return!1;case"fragment":for(let s of e.children)n(s);return!1;case"element":{let s=!0;for(let o of e.children)n(o)||(s=!1);let i;for(let o of e.props)if(i=a(o),i)break;return!i&&!s&&(i=l(e)),e.static=!i,i?c.set(e,i):t.push(e),e.static}default:return!1}};for(let e of Array.isArray(r)?r:[r])n(e);return{staticElements:t,reasons:c}}function l(r){for(let t of r.children){if(t.kind==="expr")return"expression-child";if(t.kind==="component")return"component-child";if(t.kind==="control")return"control-child";if(t.kind==="element"&&!t.static||t.kind==="fragment")return"expression-child"}return"expression-child"}function p(r){let t=[],c=n=>{if(n.kind==="element"&&n.static){t.push(n);return}let e=n.children;if(e)for(let s of e)c(s)};for(let n of Array.isArray(r)?r:[r])c(n);return t}export{f as analyzeStatic,p as staticRoots};
1
+ // src/optimize/analyze-static.ts
2
+ function propReason(prop) {
3
+ switch (prop.kind) {
4
+ case "event":
5
+ return "event";
6
+ case "ref":
7
+ return "ref";
8
+ case "spread":
9
+ return "spread";
10
+ case "class":
11
+ case "style":
12
+ return "class-or-style-directive";
13
+ case "attr":
14
+ case "prop":
15
+ if (prop.reactive) return "reactive-prop";
16
+ if (prop.expr !== void 0) return "expression-prop";
17
+ return void 0;
18
+ /* c8 ignore next 2 */
19
+ default:
20
+ return "expression-prop";
21
+ }
22
+ }
23
+ function analyzeStatic(root) {
24
+ const staticElements = [];
25
+ const reasons = /* @__PURE__ */ new Map();
26
+ const visit = (node) => {
27
+ switch (node.kind) {
28
+ case "text":
29
+ return true;
30
+ case "expr":
31
+ return false;
32
+ case "component":
33
+ case "control":
34
+ for (const child of node.children) visit(child);
35
+ return false;
36
+ case "fragment":
37
+ for (const child of node.children) visit(child);
38
+ return false;
39
+ case "element": {
40
+ let childrenStatic = true;
41
+ for (const child of node.children) {
42
+ if (!visit(child)) childrenStatic = false;
43
+ }
44
+ let reason;
45
+ for (const prop of node.props) {
46
+ reason = propReason(prop);
47
+ if (reason) break;
48
+ }
49
+ if (!reason && !childrenStatic) {
50
+ reason = childReason(node);
51
+ }
52
+ node.static = !reason;
53
+ if (reason) reasons.set(node, reason);
54
+ else staticElements.push(node);
55
+ return node.static;
56
+ }
57
+ /* c8 ignore next 2 */
58
+ default:
59
+ return false;
60
+ }
61
+ };
62
+ for (const node of Array.isArray(root) ? root : [root]) visit(node);
63
+ return { staticElements, reasons };
64
+ }
65
+ function childReason(node) {
66
+ for (const child of node.children) {
67
+ if (child.kind === "expr") return "expression-child";
68
+ if (child.kind === "component") return "component-child";
69
+ if (child.kind === "control") return "control-child";
70
+ if (child.kind === "element" && !child.static) return "expression-child";
71
+ if (child.kind === "fragment") return "expression-child";
72
+ }
73
+ return "expression-child";
74
+ }
75
+ function staticRoots(root) {
76
+ const roots = [];
77
+ const visit = (node) => {
78
+ if (node.kind === "element" && node.static) {
79
+ roots.push(node);
80
+ return;
81
+ }
82
+ const children = node.children;
83
+ if (children) for (const child of children) visit(child);
84
+ };
85
+ for (const node of Array.isArray(root) ? root : [root]) visit(node);
86
+ return roots;
87
+ }
88
+ export {
89
+ analyzeStatic,
90
+ staticRoots
91
+ };
@@ -1 +1,90 @@
1
- "use strict";var d=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var v=(e,o)=>{for(var t in o)d(e,t,{get:o[t],enumerable:!0})},x=(e,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of g(o))!R.call(e,n)&&n!==t&&d(e,n,{get:()=>o[n],enumerable:!(i=f(o,n))||i.enumerable});return e};var S=e=>x(d({},"__esModule",{value:!0}),e);var E={};v(E,{collapseStrategies:()=>I});module.exports=S(E);function l(e){return e.kind!=="eager"&&e.kind!=="never"}var u=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],p=["Suspense","SuspenseList","Await"],m=["Router","Outlet","Redirect","Link"],O=[...u,...p,...m],C=new Set([...u,...p]);function c(e,o){let t=Array.isArray(e)?e:[e];for(let i of t){o(i);let n=i.children;n&&c(n,o)}}function I(e){let o=[];c(e,r=>{r.kind==="component"&&r.source&&o.push(r)});let t=new Set,i=new Set;for(let r of o){let{module:s,loading:a}=r.source;a.kind==="eager"&&t.add(s),a.kind==="never"&&i.add(s)}let n=new Map;for(let r of o){let s=r.source;l(s.loading)&&t.has(s.module)&&(s.loading={kind:"eager"},n.set(s.module,(n.get(s.module)??0)+1))}return{collapsed:n,conflicted:[...i].filter(r=>t.has(r))}}
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/optimize/collapse-strategies.ts
21
+ var collapse_strategies_exports = {};
22
+ __export(collapse_strategies_exports, {
23
+ collapseStrategies: () => collapseStrategies
24
+ });
25
+ module.exports = __toCommonJS(collapse_strategies_exports);
26
+
27
+ // src/resolve/load-directive.ts
28
+ function isDeferred(strategy) {
29
+ return strategy.kind !== "eager" && strategy.kind !== "never";
30
+ }
31
+
32
+ // src/resolve/builtins.ts
33
+ var DOM_CONTROL_FLOW = [
34
+ "Show",
35
+ "For",
36
+ "Index",
37
+ "Switch",
38
+ "Match",
39
+ "Portal",
40
+ "Dynamic",
41
+ "ErrorBoundary"
42
+ ];
43
+ var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
44
+ var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
45
+ var BUILTIN_COMPONENTS = [
46
+ ...DOM_CONTROL_FLOW,
47
+ ...CORE_CONTROL_FLOW,
48
+ ...ROUTER_COMPONENTS
49
+ ];
50
+ var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
51
+ ...DOM_CONTROL_FLOW,
52
+ ...CORE_CONTROL_FLOW
53
+ ]);
54
+
55
+ // src/resolve/resolve-ir.ts
56
+ function walk(root, visit) {
57
+ const nodes = Array.isArray(root) ? root : [root];
58
+ for (const node of nodes) {
59
+ visit(node);
60
+ const children = node.children;
61
+ if (children) walk(children, visit);
62
+ }
63
+ }
64
+
65
+ // src/optimize/collapse-strategies.ts
66
+ function collapseStrategies(root) {
67
+ const components = [];
68
+ walk(root, (node) => {
69
+ if (node.kind === "component" && node.source) components.push(node);
70
+ });
71
+ const eager = /* @__PURE__ */ new Set();
72
+ const never = /* @__PURE__ */ new Set();
73
+ for (const node of components) {
74
+ const { module: module2, loading } = node.source;
75
+ if (loading.kind === "eager") eager.add(module2);
76
+ if (loading.kind === "never") never.add(module2);
77
+ }
78
+ const collapsed = /* @__PURE__ */ new Map();
79
+ for (const node of components) {
80
+ const source = node.source;
81
+ if (!isDeferred(source.loading)) continue;
82
+ if (!eager.has(source.module)) continue;
83
+ source.loading = { kind: "eager" };
84
+ collapsed.set(source.module, (collapsed.get(source.module) ?? 0) + 1);
85
+ }
86
+ return {
87
+ collapsed,
88
+ conflicted: [...never].filter((m) => eager.has(m))
89
+ };
90
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Strategy collapsing — demote a deferred reference whose module is already present.
3
+ *
4
+ * This is not a nice-to-have. Without it the naive feature is a regression: if a module
5
+ * is referenced eagerly anywhere in the compilation unit, it is in the parent chunk
6
+ * already, so a `load:visible` boundary elsewhere adds a wrapper, a promise and a
7
+ * re-render in order to fetch nothing. The bytes are paid twice — once in the chunk,
8
+ * once in the deferral machinery — and the component renders later than it needs to.
9
+ *
10
+ * Collapsing runs per module, not per component name, because a chunk is a module:
11
+ * `<Button>` eager and `<ButtonGroup load:visible>` from the same package means the
12
+ * package is already loaded, so deferring the second buys nothing.
13
+ *
14
+ * `never` is not collapsed. It means "no client code at all", which is a statement about
15
+ * what should exist rather than about when to fetch it; an eager sibling does not make a
16
+ * server-only component suddenly belong in the client bundle. That combination is
17
+ * contradictory and reported instead.
18
+ */
19
+ import type { IRNode } from '../ir/nodes.cjs';
20
+ export interface CollapseReport {
21
+ /** Modules demoted to eager, with the reference count that was demoted. */
22
+ collapsed: Map<string, number>;
23
+ /**
24
+ * Modules referenced both as `load:never` and in a way that needs client code.
25
+ * Contradictory rather than optimisable, so it is reported and left alone.
26
+ */
27
+ conflicted: string[];
28
+ }
29
+ /** Demote deferred references to modules that are already in the chunk. */
30
+ export declare function collapseStrategies(root: IRNode | IRNode[]): CollapseReport;
@@ -1 +1,67 @@
1
- function a(o){return o.kind!=="eager"&&o.kind!=="never"}var l=["Show","For","Index","Switch","Match","Portal","Dynamic","ErrorBoundary"],u=["Suspense","SuspenseList","Await"],p=["Router","Outlet","Redirect","Link"],g=[...l,...u,...p],m=new Set([...l,...u]);function d(o,t){let i=Array.isArray(o)?o:[o];for(let s of i){t(s);let r=s.children;r&&d(r,t)}}function w(o){let t=[];d(o,e=>{e.kind==="component"&&e.source&&t.push(e)});let i=new Set,s=new Set;for(let e of t){let{module:n,loading:c}=e.source;c.kind==="eager"&&i.add(n),c.kind==="never"&&s.add(n)}let r=new Map;for(let e of t){let n=e.source;a(n.loading)&&i.has(n.module)&&(n.loading={kind:"eager"},r.set(n.module,(r.get(n.module)??0)+1))}return{collapsed:r,conflicted:[...s].filter(e=>i.has(e))}}export{w as collapseStrategies};
1
+ // src/resolve/load-directive.ts
2
+ function isDeferred(strategy) {
3
+ return strategy.kind !== "eager" && strategy.kind !== "never";
4
+ }
5
+
6
+ // src/resolve/builtins.ts
7
+ var DOM_CONTROL_FLOW = [
8
+ "Show",
9
+ "For",
10
+ "Index",
11
+ "Switch",
12
+ "Match",
13
+ "Portal",
14
+ "Dynamic",
15
+ "ErrorBoundary"
16
+ ];
17
+ var CORE_CONTROL_FLOW = ["Suspense", "SuspenseList", "Await"];
18
+ var ROUTER_COMPONENTS = ["Router", "Outlet", "Redirect", "Link"];
19
+ var BUILTIN_COMPONENTS = [
20
+ ...DOM_CONTROL_FLOW,
21
+ ...CORE_CONTROL_FLOW,
22
+ ...ROUTER_COMPONENTS
23
+ ];
24
+ var RESERVED_COMPONENTS = /* @__PURE__ */ new Set([
25
+ ...DOM_CONTROL_FLOW,
26
+ ...CORE_CONTROL_FLOW
27
+ ]);
28
+
29
+ // src/resolve/resolve-ir.ts
30
+ function walk(root, visit) {
31
+ const nodes = Array.isArray(root) ? root : [root];
32
+ for (const node of nodes) {
33
+ visit(node);
34
+ const children = node.children;
35
+ if (children) walk(children, visit);
36
+ }
37
+ }
38
+
39
+ // src/optimize/collapse-strategies.ts
40
+ function collapseStrategies(root) {
41
+ const components = [];
42
+ walk(root, (node) => {
43
+ if (node.kind === "component" && node.source) components.push(node);
44
+ });
45
+ const eager = /* @__PURE__ */ new Set();
46
+ const never = /* @__PURE__ */ new Set();
47
+ for (const node of components) {
48
+ const { module, loading } = node.source;
49
+ if (loading.kind === "eager") eager.add(module);
50
+ if (loading.kind === "never") never.add(module);
51
+ }
52
+ const collapsed = /* @__PURE__ */ new Map();
53
+ for (const node of components) {
54
+ const source = node.source;
55
+ if (!isDeferred(source.loading)) continue;
56
+ if (!eager.has(source.module)) continue;
57
+ source.loading = { kind: "eager" };
58
+ collapsed.set(source.module, (collapsed.get(source.module) ?? 0) + 1);
59
+ }
60
+ return {
61
+ collapsed,
62
+ conflicted: [...never].filter((m) => eager.has(m))
63
+ };
64
+ }
65
+ export {
66
+ collapseStrategies
67
+ };
package/dist/options.cjs CHANGED
@@ -1 +1,33 @@
1
- "use strict";var t=Object.defineProperty;var r=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var s=Object.prototype.hasOwnProperty;var m=(o,e)=>{for(var a in e)t(o,a,{get:e[a],enumerable:!0})},i=(o,e,a,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of p(e))!s.call(o,l)&&l!==a&&t(o,l,{get:()=>e[l],enumerable:!(n=r(e,l))||n.enumerable});return o};var d=o=>i(t({},"__esModule",{value:!0}),o);var b={};m(b,{defaultOptions:()=>v});module.exports=d(b);var v={backend:"imperative",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};
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/options.ts
21
+ var options_exports = {};
22
+ __export(options_exports, {
23
+ defaultOptions: () => defaultOptions
24
+ });
25
+ module.exports = __toCommonJS(options_exports);
26
+ var defaultOptions = {
27
+ backend: "imperative",
28
+ moduleName: "@fluixi/dom",
29
+ delegateEvents: true,
30
+ hydratable: false,
31
+ sourceMaps: true,
32
+ dev: false
33
+ };
@@ -0,0 +1,39 @@
1
+ import type { ComponentResolverRule } from './resolve/component-resolver.cjs';
2
+ /**
3
+ * Public compiler options. This schema is the stable public API — it stays put
4
+ * as backends change. Switching DOM strategy is `backend`, not a rewrite.
5
+ */
6
+ export interface CompilerOptions {
7
+ /**
8
+ * Clone static subtrees from a `<template>` instead of building them element by
9
+ * element. Roughly 2x faster to instantiate, but **client-only**: `createTemplate`
10
+ * produces real DOM nodes, which the SSR renderer's ServerElement tree rejects, and a
11
+ * clone creates a fresh node where hydration must adopt the existing one. Opt in for
12
+ * a client-rendered app; leave off wherever SSR or hydration is involved.
13
+ */
14
+ templateClone?: boolean;
15
+ /**
16
+ * Also clone subtrees whose *structure* is static but which contain dynamic holes —
17
+ * the common shape. Roughly halves the emitted code for such a subtree and replaces
18
+ * per-element construction with one clone.
19
+ *
20
+ * Works under SSR and hydration: each hole is bracketed by `<!--fx-->` markers, so its
21
+ * content is exactly the nodes between them and the server's markup has the same shape
22
+ * as the client's template. Hydration adopts those nodes rather than rebuilding them.
23
+ */
24
+ partialTemplates?: boolean;
25
+ /** which codegen backend to use */
26
+ backend?: 'imperative' | 'template-clone';
27
+ /** runtime module emitted symbols are imported from */
28
+ moduleName?: string;
29
+ delegateEvents?: boolean;
30
+ hydratable?: boolean;
31
+ sourceMaps?: boolean;
32
+ dev?: boolean;
33
+ /**
34
+ * Rules that resolve an unbound capitalised tag to a module, so a component can be
35
+ * used in a template without an import. See `createComponentResolver`.
36
+ */
37
+ resolve?: readonly ComponentResolverRule[];
38
+ }
39
+ export declare const defaultOptions: CompilerOptions;
package/dist/options.mjs CHANGED
@@ -1 +1,12 @@
1
- var e={backend:"imperative",moduleName:"@fluixi/dom",delegateEvents:!0,hydratable:!1,sourceMaps:!0,dev:!1};export{e as defaultOptions};
1
+ // src/options.ts
2
+ var defaultOptions = {
3
+ backend: "imperative",
4
+ moduleName: "@fluixi/dom",
5
+ delegateEvents: true,
6
+ hydratable: false,
7
+ sourceMaps: true,
8
+ dev: false
9
+ };
10
+ export {
11
+ defaultOptions
12
+ };