@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,506 @@
1
- var w={kind:"eager"},J=["pointerdown","focusin","keydown"],E=new Set(["eager","idle","visible","interaction","media","never"]),c=class extends Error{};function f(e){return e.startsWith("load:")}function k(e,t){let n=e.slice(5);if(!E.has(n))throw new c(`Unknown load strategy 'load:${n}'. Expected one of ${[...E].join(", ")}.`);switch(n){case"eager":return w;case"idle":return{kind:"idle"};case"never":return{kind:"never"};case"visible":return t?{kind:"visible",rootMargin:t}:{kind:"visible"};case"interaction":return{kind:"interaction",events:t?L(t):[...J]};case"media":if(!t)throw new c(`'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`);return{kind:"media",query:t};default:throw new c(`Unhandled load strategy '${n}'.`)}}function L(e){let t=e.split(/[\s,]+/).map(n=>n.trim()).filter(Boolean);if(t.length===0)throw new c("'load:interaction' was given no event names.");return t}var C="children";function m(e){switch(e.kind){case"call":return!0;case"member":return e.property!==C;case"compound":return e.parts.some(m);case"opaque":return!1}}var X=new Set(["CallExpression","OptionalCallExpression"]),A=new Set(["MemberExpression","OptionalMemberExpression"]);function y(e){if(!e)return{kind:"opaque"};if(X.has(e.type))return{kind:"call"};if(A.has(e.type)){let t=e.property;return{kind:"member",property:!(e.computed===!0)&&t?.type==="Identifier"?t.name:null}}return e.type==="ConditionalExpression"?{kind:"compound",parts:[e.test,e.consequent,e.alternate].map(l)}:e.type==="LogicalExpression"||e.type==="BinaryExpression"?{kind:"compound",parts:[e.left,e.right].map(l)}:e.type==="TemplateLiteral"?{kind:"compound",parts:e.expressions.map(l)}:e.type==="ObjectExpression"?{kind:"compound",parts:e.properties.filter(n=>(n.type==="ObjectProperty"||n.type==="Property")&&n.computed!==!0).map(n=>l(n.value))}:e.type==="ArrayExpression"?{kind:"compound",parts:e.elements.filter(n=>n!=null&&n.type!=="SpreadElement").map(l)}:{kind:"opaque"}}var l=e=>y(e);function $(e){switch(e.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 e.reactive?"reactive-prop":e.expr!==void 0?"expression-prop":void 0;default:return"expression-prop"}}function v(e){let t=[],n=new Map,o=r=>{switch(r.kind){case"text":return!0;case"expr":return!1;case"component":case"control":for(let s of r.children)o(s);return!1;case"fragment":for(let s of r.children)o(s);return!1;case"element":{let s=!0;for(let a of r.children)o(a)||(s=!1);let i;for(let a of r.props)if(i=$(a),i)break;return!i&&!s&&(i=T(r)),r.static=!i,i?n.set(r,i):t.push(r),r.static}default:return!1}};for(let r of Array.isArray(e)?e:[e])o(r);return{staticElements:t,reasons:n}}function T(e){for(let t of e.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 S(e){let t=e.split(/\r\n|\n|\r/),n=0;for(let r=0;r<t.length;r++)/[^ \t]/.test(t[r])&&(n=r);let o="";for(let r=0;r<t.length;r++){let s=t[r].replace(/\t/g," ");r!==0&&(s=s.replace(/^ +/,"")),r!==t.length-1&&(s=s.replace(/ +$/,"")),s&&(r!==n&&(s+=" "),o+=s)}return o}var D=new Set(["svg","path","circle","rect","line","polygon","polyline","ellipse","g","defs","clipPath","text"]),P=/^on[A-Z]/,M=new Set(["click","dblclick","input","change","submit","focus","blur","keydown","keyup","keypress","mousedown","mouseup"]),b=e=>m(y(e)),u=(e,t)=>{if(!t.sourceFile)return;let n=e.loc?.start;return n?{line:n.line,column:n.column}:void 0};function d(e){if(e.type==="StringLiteral"||e.type==="NumericLiteral"||e.type==="BooleanLiteral"||e.type==="Literal"&&(typeof e.value=="string"||typeof e.value=="number"||typeof e.value=="boolean"))return e.value}var x=e=>!!e&&typeof d(e)=="string";function O(e,t){return e.type==="JSXIdentifier"?{tag:e.name,component:e.name[0]!==e.name[0].toLowerCase()}:e.type==="JSXMemberExpression"?{tag:t.code(e),component:!0}:e.type==="JSXNamespacedName"?{tag:`${e.namespace.name}:${e.name.name}`,component:!1}:{tag:"div",component:!1}}function g(e){return e.type==="JSXIdentifier"?e.name==="class"?"className":e.name:e.type==="JSXNamespacedName"?`${e.namespace.name}:${e.name.name}`:"unknown"}function j(e,t){let n=g(e.name),o=P.test(n),r=o||n.startsWith("on:")||n==="ref",i={name:n,kind:o?"event":"attr"};if(o){let p=n.slice(2).toLowerCase();i.event={name:p,delegated:M.has(p)}}let a=e.value;if(a==null)return i.literal=!0,i.at=u(e,t),i;if(x(a))return i.literal=d(a),i.at=u(a,t),i;if(a.type==="JSXExpressionContainer"&&a.expression?.type!=="JSXEmptyExpression"){let p=a.expression,h=d(p);return h!==void 0?(i.literal=h,i.at=u(p,t),i):(i.expr=t.code(p),i.reactive=r?!1:b(p),i.at=u(p,t),(p.type==="JSXElement"||p.type==="JSXFragment")&&(i.jsxElement=!0),i)}return i.literal=!0,i}function R(e,t){let n=e.value;return n==null?null:x(n)?JSON.stringify(d(n)):n.type==="JSXExpressionContainer"&&n.expression?.type!=="JSXEmptyExpression"?t.code(n.expression):null}function q(e,t){let n=[],o=[];for(let r of e){if(r.type==="JSXSpreadAttribute"){n.push({name:"",kind:"spread",expr:t.code(r.argument)});continue}if(r.type!=="JSXAttribute"||f(g(r.name)))continue;let s=r.name.type==="JSXNamespacedName"?r.name.namespace.name:null;if(s==="use"){let i=r.name.name.name;t.used.add(i);let a=R(r,t);o.push(a!=null?`[${i}, () => (${a})]`:`[${i}]`);continue}if(s==="oncapture"){let i=r.name.name.name.toLowerCase(),a=R(r,t)??"undefined";n.push({name:"on:"+i,kind:"attr",expr:`[${a}, { capture: true }]`});continue}n.push(j(r,t))}return o.length>0&&n.push({name:"use",kind:"attr",expr:`[${o.join(", ")}]`}),n}function N(e,t){let n=[];for(let o of e)if(o.type==="JSXText"){let r=S(o.value);r&&n.push({kind:"text",value:r})}else if(o.type==="JSXExpressionContainer"){if(o.expression?.type!=="JSXEmptyExpression"){let r=o.expression,s=b(r);n.push({kind:"expr",code:t.code(r),reactive:s,...s?{at:u(r,t)}:{}})}}else o.type==="JSXElement"||o.type==="JSXFragment"?n.push(I(o,t)):o.type==="JSXSpreadChild"&&n.push({kind:"expr",code:t.code(o.expression),reactive:!1});return n}function F(e){for(let t of e){if(t.type!=="JSXAttribute")continue;let n=g(t.name);if(f(n)){if(t.value&&!x(t.value))throw new c(`'${n}' needs a literal value, not an expression — the strategy is compile-time.`);return k(n,t.value?d(t.value):null)}}}function I(e,t){if(e.type==="JSXFragment")return{kind:"fragment",children:N(e.children,t)};let{tag:n,component:o}=O(e.openingElement.name,t),r=q(e.openingElement.attributes,t),s=N(e.children,t),i=t.sourceFile&&e.loc?.start?{file:t.sourceFile,line:e.loc.start.line,column:e.loc.start.column}:void 0;if(o){let a=F(e.openingElement.attributes);return{kind:"component",name:n,props:r,children:s,...a?{load:a}:{},...i?{at:i}:{}}}return{kind:"element",tag:n,svg:D.has(n),props:r,children:s,static:!1,...i?{at:i}:{}}}function Q(e,t){let n=I(e,t);return v(n),n}export{D as SVG_TAGS,Q as buildJsxIR};
1
+ // src/resolve/load-directive.ts
2
+ var EAGER = { kind: "eager" };
3
+ var DEFAULT_INTERACTION_EVENTS = ["pointerdown", "focusin", "keydown"];
4
+ var STRATEGIES = /* @__PURE__ */ new Set(["eager", "idle", "visible", "interaction", "media", "never"]);
5
+ var LoadDirectiveError = class extends Error {
6
+ };
7
+ function isLoadDirective(name) {
8
+ return name.startsWith("load:");
9
+ }
10
+ function parseLoadDirective(name, value) {
11
+ const strategy = name.slice("load:".length);
12
+ if (!STRATEGIES.has(strategy)) {
13
+ throw new LoadDirectiveError(
14
+ `Unknown load strategy 'load:${strategy}'. Expected one of ${[...STRATEGIES].join(", ")}.`
15
+ );
16
+ }
17
+ switch (strategy) {
18
+ case "eager":
19
+ return EAGER;
20
+ case "idle":
21
+ return { kind: "idle" };
22
+ case "never":
23
+ return { kind: "never" };
24
+ case "visible":
25
+ return value ? { kind: "visible", rootMargin: value } : { kind: "visible" };
26
+ case "interaction":
27
+ return {
28
+ kind: "interaction",
29
+ events: value ? splitEvents(value) : [...DEFAULT_INTERACTION_EVENTS]
30
+ };
31
+ case "media":
32
+ if (!value) {
33
+ throw new LoadDirectiveError(
34
+ `'load:media' needs a query, e.g. load:media="(min-width: 1024px)".`
35
+ );
36
+ }
37
+ return { kind: "media", query: value };
38
+ default:
39
+ throw new LoadDirectiveError(`Unhandled load strategy '${strategy}'.`);
40
+ }
41
+ }
42
+ function splitEvents(value) {
43
+ const events = value.split(/[\s,]+/).map((e) => e.trim()).filter(Boolean);
44
+ if (events.length === 0) {
45
+ throw new LoadDirectiveError(`'load:interaction' was given no event names.`);
46
+ }
47
+ return events;
48
+ }
49
+
50
+ // src/analyze/reactive-expr.ts
51
+ var STABLE_MEMBER = "children";
52
+ function isReactiveShape(shape) {
53
+ switch (shape.kind) {
54
+ case "call":
55
+ return true;
56
+ case "member":
57
+ return shape.property !== STABLE_MEMBER;
58
+ case "compound":
59
+ return shape.parts.some(isReactiveShape);
60
+ case "opaque":
61
+ return false;
62
+ }
63
+ }
64
+
65
+ // src/analyze/expr-shape.ts
66
+ var CALL = /* @__PURE__ */ new Set(["CallExpression", "OptionalCallExpression"]);
67
+ var MEMBER = /* @__PURE__ */ new Set(["MemberExpression", "OptionalMemberExpression"]);
68
+ function shapeOf(node) {
69
+ if (!node) return { kind: "opaque" };
70
+ if (CALL.has(node.type)) return { kind: "call" };
71
+ if (MEMBER.has(node.type)) {
72
+ const property = node.property;
73
+ const computed = node.computed === true;
74
+ return {
75
+ kind: "member",
76
+ property: !computed && property?.type === "Identifier" ? property.name : null
77
+ };
78
+ }
79
+ if (node.type === "ConditionalExpression") {
80
+ return { kind: "compound", parts: [node.test, node.consequent, node.alternate].map(part) };
81
+ }
82
+ if (node.type === "LogicalExpression" || node.type === "BinaryExpression") {
83
+ return { kind: "compound", parts: [node.left, node.right].map(part) };
84
+ }
85
+ if (node.type === "TemplateLiteral") {
86
+ return { kind: "compound", parts: node.expressions.map(part) };
87
+ }
88
+ if (node.type === "ObjectExpression") {
89
+ const props = node.properties.filter(
90
+ (p) => (p.type === "ObjectProperty" || p.type === "Property") && p.computed !== true
91
+ );
92
+ return { kind: "compound", parts: props.map((p) => part(p.value)) };
93
+ }
94
+ if (node.type === "ArrayExpression") {
95
+ const items = node.elements.filter(
96
+ (e) => e != null && e.type !== "SpreadElement"
97
+ );
98
+ return { kind: "compound", parts: items.map(part) };
99
+ }
100
+ return { kind: "opaque" };
101
+ }
102
+ var part = (n) => shapeOf(n);
103
+
104
+ // src/optimize/analyze-static.ts
105
+ function propReason(prop) {
106
+ switch (prop.kind) {
107
+ case "event":
108
+ return "event";
109
+ case "ref":
110
+ return "ref";
111
+ case "spread":
112
+ return "spread";
113
+ case "class":
114
+ case "style":
115
+ return "class-or-style-directive";
116
+ case "attr":
117
+ case "prop":
118
+ if (prop.reactive) return "reactive-prop";
119
+ if (prop.expr !== void 0) return "expression-prop";
120
+ return void 0;
121
+ /* c8 ignore next 2 */
122
+ default:
123
+ return "expression-prop";
124
+ }
125
+ }
126
+ function analyzeStatic(root) {
127
+ const staticElements = [];
128
+ const reasons = /* @__PURE__ */ new Map();
129
+ const visit = (node) => {
130
+ switch (node.kind) {
131
+ case "text":
132
+ return true;
133
+ case "expr":
134
+ return false;
135
+ case "component":
136
+ case "control":
137
+ for (const child of node.children) visit(child);
138
+ return false;
139
+ case "fragment":
140
+ for (const child of node.children) visit(child);
141
+ return false;
142
+ case "element": {
143
+ let childrenStatic = true;
144
+ for (const child of node.children) {
145
+ if (!visit(child)) childrenStatic = false;
146
+ }
147
+ let reason;
148
+ for (const prop of node.props) {
149
+ reason = propReason(prop);
150
+ if (reason) break;
151
+ }
152
+ if (!reason && !childrenStatic) {
153
+ reason = childReason(node);
154
+ }
155
+ node.static = !reason;
156
+ if (reason) reasons.set(node, reason);
157
+ else staticElements.push(node);
158
+ return node.static;
159
+ }
160
+ /* c8 ignore next 2 */
161
+ default:
162
+ return false;
163
+ }
164
+ };
165
+ for (const node of Array.isArray(root) ? root : [root]) visit(node);
166
+ return { staticElements, reasons };
167
+ }
168
+ function childReason(node) {
169
+ for (const child of node.children) {
170
+ if (child.kind === "expr") return "expression-child";
171
+ if (child.kind === "component") return "component-child";
172
+ if (child.kind === "control") return "control-child";
173
+ if (child.kind === "element" && !child.static) return "expression-child";
174
+ if (child.kind === "fragment") return "expression-child";
175
+ }
176
+ return "expression-child";
177
+ }
178
+
179
+ // src/lower/text.ts
180
+ function cleanTemplateText(value) {
181
+ const lines = value.split(/\r\n|\n|\r/);
182
+ let lastNonEmpty = 0;
183
+ for (let i = 0; i < lines.length; i++) {
184
+ if (/[^ \t]/.test(lines[i])) lastNonEmpty = i;
185
+ }
186
+ let out = "";
187
+ for (let i = 0; i < lines.length; i++) {
188
+ let line = lines[i].replace(/\t/g, " ");
189
+ if (i !== 0) line = line.replace(/^ +/, "");
190
+ if (i !== lines.length - 1) line = line.replace(/ +$/, "");
191
+ if (!line) continue;
192
+ if (i !== lastNonEmpty) line += " ";
193
+ out += line;
194
+ }
195
+ return out;
196
+ }
197
+
198
+ // src/analyze/paren.ts
199
+ function skipQuoted(src, start) {
200
+ const quote = src[start];
201
+ for (let i = start + 1; i < src.length; i++) {
202
+ const c = src[i];
203
+ if (c === "\\") i++;
204
+ else if (c === quote) return i + 1;
205
+ else if (c === "\n") return -1;
206
+ }
207
+ return -1;
208
+ }
209
+ function skipTemplate(src, start) {
210
+ let i = start + 1;
211
+ while (i < src.length) {
212
+ const c = src[i];
213
+ if (c === "\\") {
214
+ i += 2;
215
+ } else if (c === "`") {
216
+ return i + 1;
217
+ } else if (c === "$" && src[i + 1] === "{") {
218
+ let depth = 1;
219
+ i += 2;
220
+ while (i < src.length && depth > 0) {
221
+ const k = src[i];
222
+ if (k === "\\") i += 2;
223
+ else if (k === "`") {
224
+ const end = skipTemplate(src, i);
225
+ if (end < 0) return -1;
226
+ i = end;
227
+ } else if (k === '"' || k === "'") {
228
+ const end = skipQuoted(src, i);
229
+ if (end < 0) return -1;
230
+ i = end;
231
+ } else {
232
+ if (k === "{") depth++;
233
+ else if (k === "}") depth--;
234
+ i++;
235
+ }
236
+ }
237
+ } else {
238
+ i++;
239
+ }
240
+ }
241
+ return -1;
242
+ }
243
+ function skipRegex(src, start) {
244
+ let inClass = false;
245
+ for (let i = start + 1; i < src.length; i++) {
246
+ const c = src[i];
247
+ if (c === "\\") i++;
248
+ else if (c === "[") inClass = true;
249
+ else if (c === "]") inClass = false;
250
+ else if (c === "\n") return -1;
251
+ else if (c === "/" && !inClass) {
252
+ let end = i + 1;
253
+ while (end < src.length && /[a-z]/i.test(src[end])) end++;
254
+ return end;
255
+ }
256
+ }
257
+ return -1;
258
+ }
259
+ function divides(prev) {
260
+ return prev !== "" && /[A-Za-z0-9_$)\]]/.test(prev);
261
+ }
262
+ function topLevelComma(src) {
263
+ let depth = 0;
264
+ let prev = "";
265
+ let i = 0;
266
+ while (i < src.length) {
267
+ const c = src[i];
268
+ if (c === '"' || c === "'") {
269
+ const end = skipQuoted(src, i);
270
+ if (end < 0) return null;
271
+ i = end;
272
+ prev = c;
273
+ } else if (c === "`") {
274
+ const end = skipTemplate(src, i);
275
+ if (end < 0) return null;
276
+ i = end;
277
+ prev = c;
278
+ } else if (c === "/" && src[i + 1] === "/") {
279
+ return null;
280
+ } else if (c === "/" && src[i + 1] === "*") {
281
+ const end = src.indexOf("*/", i + 2);
282
+ if (end < 0) return null;
283
+ i = end + 2;
284
+ } else if (c === "/" && !divides(prev)) {
285
+ const end = skipRegex(src, i);
286
+ if (end < 0) return null;
287
+ i = end;
288
+ prev = "/";
289
+ } else {
290
+ if (c === "(" || c === "[" || c === "{") depth++;
291
+ else if (c === ")" || c === "]" || c === "}") {
292
+ depth--;
293
+ if (depth < 0) return null;
294
+ } else if (c === "," && depth === 0) return true;
295
+ if (!/\s/.test(c)) prev = c;
296
+ i++;
297
+ }
298
+ }
299
+ return depth === 0 ? false : null;
300
+ }
301
+ function paren(code, position) {
302
+ const src = code.trim();
303
+ if (src === "") return `(${code})`;
304
+ if (position === "arrowBody" && src[0] === "{") return `(${code})`;
305
+ return topLevelComma(src) === false ? code : `(${code})`;
306
+ }
307
+
308
+ // src/lower/jsx.ts
309
+ var SVG_TAGS = /* @__PURE__ */ new Set([
310
+ "svg",
311
+ "path",
312
+ "circle",
313
+ "rect",
314
+ "line",
315
+ "polygon",
316
+ "polyline",
317
+ "ellipse",
318
+ "g",
319
+ "defs",
320
+ "clipPath",
321
+ "text"
322
+ ]);
323
+ var EVENT_RE = /^on[A-Z]/;
324
+ var DELEGATED = /* @__PURE__ */ new Set([
325
+ "click",
326
+ "dblclick",
327
+ "input",
328
+ "change",
329
+ "submit",
330
+ "focus",
331
+ "blur",
332
+ "keydown",
333
+ "keyup",
334
+ "keypress",
335
+ "mousedown",
336
+ "mouseup"
337
+ ]);
338
+ var isReactive = (node) => isReactiveShape(shapeOf(node));
339
+ var posOf = (node, ctx) => {
340
+ if (!ctx.sourceFile) return void 0;
341
+ const at = node.loc?.start;
342
+ return at ? { line: at.line, column: at.column } : void 0;
343
+ };
344
+ function literalOf(node) {
345
+ if (node.type === "StringLiteral" || node.type === "NumericLiteral" || node.type === "BooleanLiteral") {
346
+ return node.value;
347
+ }
348
+ if (node.type === "Literal" && (typeof node.value === "string" || typeof node.value === "number" || typeof node.value === "boolean")) {
349
+ return node.value;
350
+ }
351
+ return void 0;
352
+ }
353
+ var isString = (node) => !!node && typeof literalOf(node) === "string";
354
+ function tagInfo(name, ctx) {
355
+ if (name.type === "JSXIdentifier") {
356
+ return { tag: name.name, component: name.name[0] !== name.name[0].toLowerCase() };
357
+ }
358
+ if (name.type === "JSXMemberExpression") return { tag: ctx.code(name), component: true };
359
+ if (name.type === "JSXNamespacedName") {
360
+ return { tag: `${name.namespace.name}:${name.name.name}`, component: false };
361
+ }
362
+ return { tag: "div", component: false };
363
+ }
364
+ function attrName(name) {
365
+ if (name.type === "JSXIdentifier") return name.name === "class" ? "className" : name.name;
366
+ if (name.type === "JSXNamespacedName") return `${name.namespace.name}:${name.name.name}`;
367
+ return "unknown";
368
+ }
369
+ function buildAttr(attr, ctx) {
370
+ const name = attrName(attr.name);
371
+ const isEvent = EVENT_RE.test(name);
372
+ const isHandler = isEvent || name.startsWith("on:") || name === "ref";
373
+ const kind = isEvent ? "event" : "attr";
374
+ const base = { name, kind };
375
+ if (isEvent) {
376
+ const evt = name.slice(2).toLowerCase();
377
+ base.event = { name: evt, delegated: DELEGATED.has(evt) };
378
+ }
379
+ const v = attr.value;
380
+ if (v == null) {
381
+ base.literal = true;
382
+ base.at = posOf(attr, ctx);
383
+ return base;
384
+ }
385
+ if (isString(v)) {
386
+ base.literal = literalOf(v);
387
+ base.at = posOf(v, ctx);
388
+ return base;
389
+ }
390
+ if (v.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression") {
391
+ const expr = v.expression;
392
+ const literal = literalOf(expr);
393
+ if (literal !== void 0) {
394
+ base.literal = literal;
395
+ base.at = posOf(expr, ctx);
396
+ return base;
397
+ }
398
+ base.expr = ctx.code(expr);
399
+ base.reactive = isHandler ? false : isReactive(expr);
400
+ base.at = posOf(expr, ctx);
401
+ if (expr.type === "JSXElement" || expr.type === "JSXFragment") base.jsxElement = true;
402
+ return base;
403
+ }
404
+ base.literal = true;
405
+ return base;
406
+ }
407
+ function attrExprCode(attr, ctx) {
408
+ const v = attr.value;
409
+ if (v == null) return null;
410
+ if (isString(v)) return JSON.stringify(literalOf(v));
411
+ if (v.type === "JSXExpressionContainer" && v.expression?.type !== "JSXEmptyExpression") {
412
+ return ctx.code(v.expression);
413
+ }
414
+ return null;
415
+ }
416
+ function buildProps(attrs, ctx) {
417
+ const props = [];
418
+ const usePairs = [];
419
+ for (const a of attrs) {
420
+ if (a.type === "JSXSpreadAttribute") {
421
+ props.push({ name: "", kind: "spread", expr: ctx.code(a.argument) });
422
+ continue;
423
+ }
424
+ if (a.type !== "JSXAttribute") continue;
425
+ if (isLoadDirective(attrName(a.name))) continue;
426
+ const ns = a.name.type === "JSXNamespacedName" ? a.name.namespace.name : null;
427
+ if (ns === "use") {
428
+ const dir = a.name.name.name;
429
+ ctx.used.add(dir);
430
+ const opts = attrExprCode(a, ctx);
431
+ usePairs.push(opts != null ? `[${dir}, () => ${paren(opts, "arrowBody")}]` : `[${dir}]`);
432
+ continue;
433
+ }
434
+ if (ns === "oncapture") {
435
+ const evt = a.name.name.name.toLowerCase();
436
+ const h = attrExprCode(a, ctx) ?? "undefined";
437
+ props.push({ name: "on:" + evt, kind: "attr", expr: `[${h}, { capture: true }]` });
438
+ continue;
439
+ }
440
+ props.push(buildAttr(a, ctx));
441
+ }
442
+ if (usePairs.length > 0) props.push({ name: "use", kind: "attr", expr: `[${usePairs.join(", ")}]` });
443
+ return props;
444
+ }
445
+ function buildChildren(children, ctx) {
446
+ const out = [];
447
+ for (const child of children) {
448
+ if (child.type === "JSXText") {
449
+ const text = cleanTemplateText(child.value);
450
+ if (text) out.push({ kind: "text", value: text });
451
+ } else if (child.type === "JSXExpressionContainer") {
452
+ if (child.expression?.type !== "JSXEmptyExpression") {
453
+ const expr = child.expression;
454
+ const reactive = isReactive(expr);
455
+ out.push({
456
+ kind: "expr",
457
+ code: ctx.code(expr),
458
+ reactive,
459
+ ...reactive ? { at: posOf(expr, ctx) } : {}
460
+ });
461
+ }
462
+ } else if (child.type === "JSXElement" || child.type === "JSXFragment") {
463
+ out.push(buildNode(child, ctx));
464
+ } else if (child.type === "JSXSpreadChild") {
465
+ out.push({ kind: "expr", code: ctx.code(child.expression), reactive: false });
466
+ }
467
+ }
468
+ return out;
469
+ }
470
+ function readLoad(attrs) {
471
+ for (const a of attrs) {
472
+ if (a.type !== "JSXAttribute") continue;
473
+ const name = attrName(a.name);
474
+ if (!isLoadDirective(name)) continue;
475
+ if (a.value && !isString(a.value)) {
476
+ throw new LoadDirectiveError(
477
+ `'${name}' needs a literal value, not an expression — the strategy is compile-time.`
478
+ );
479
+ }
480
+ return parseLoadDirective(name, a.value ? literalOf(a.value) : null);
481
+ }
482
+ return void 0;
483
+ }
484
+ function buildNode(node, ctx) {
485
+ if (node.type === "JSXFragment") {
486
+ return { kind: "fragment", children: buildChildren(node.children, ctx) };
487
+ }
488
+ const { tag, component } = tagInfo(node.openingElement.name, ctx);
489
+ const props = buildProps(node.openingElement.attributes, ctx);
490
+ const children = buildChildren(node.children, ctx);
491
+ const at = ctx.sourceFile && node.loc?.start ? { file: ctx.sourceFile, line: node.loc.start.line, column: node.loc.start.column } : void 0;
492
+ if (component) {
493
+ const load = readLoad(node.openingElement.attributes);
494
+ return { kind: "component", name: tag, props, children, ...load ? { load } : {}, ...at ? { at } : {} };
495
+ }
496
+ return { kind: "element", tag, svg: SVG_TAGS.has(tag), props, children, static: false, ...at ? { at } : {} };
497
+ }
498
+ function buildJsxIR(node, ctx) {
499
+ const ir = buildNode(node, ctx);
500
+ analyzeStatic(ir);
501
+ return ir;
502
+ }
503
+ export {
504
+ SVG_TAGS,
505
+ buildJsxIR
506
+ };