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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/analyze/expr-shape.cjs +62 -1
  2. package/dist/analyze/expr-shape.d.cts +14 -0
  3. package/dist/analyze/expr-shape.mjs +41 -1
  4. package/dist/analyze/intrinsics.cjs +80 -1
  5. package/dist/analyze/intrinsics.d.cts +66 -0
  6. package/dist/analyze/intrinsics.mjs +59 -1
  7. package/dist/analyze/paren.cjs +134 -0
  8. package/dist/analyze/paren.d.cts +23 -0
  9. package/dist/analyze/paren.d.ts +24 -0
  10. package/dist/analyze/paren.d.ts.map +1 -0
  11. package/dist/analyze/paren.js +168 -0
  12. package/dist/analyze/paren.mjs +113 -0
  13. package/dist/analyze/props-destructure.cjs +226 -1
  14. package/dist/analyze/props-destructure.d.cts +83 -0
  15. package/dist/analyze/props-destructure.mjs +205 -1
  16. package/dist/analyze/reactive-bindings.cjs +190 -1
  17. package/dist/analyze/reactive-bindings.d.cts +42 -0
  18. package/dist/analyze/reactive-bindings.mjs +167 -1
  19. package/dist/analyze/reactive-expr.cjs +38 -1
  20. package/dist/analyze/reactive-expr.d.cts +38 -0
  21. package/dist/analyze/reactive-expr.mjs +17 -1
  22. package/dist/analyze/static-graph.cjs +811 -0
  23. package/dist/analyze/static-graph.d.cts +102 -0
  24. package/dist/analyze/static-graph.d.ts +103 -0
  25. package/dist/analyze/static-graph.d.ts.map +1 -0
  26. package/dist/analyze/static-graph.js +869 -0
  27. package/dist/analyze/static-graph.mjs +793 -0
  28. package/dist/babel-NRW4EFTG.mjs +636 -0
  29. package/dist/chunk-3YKZ4GNH.mjs +11 -0
  30. package/dist/chunk-EZR7NZOY.mjs +1718 -0
  31. package/dist/chunk-FSSWUXUR.mjs +16 -0
  32. package/dist/chunk-MJV3UXIL.mjs +158 -0
  33. package/dist/chunk-R2VHAZAX.mjs +1078 -0
  34. package/dist/codegen/backend.cjs +18 -1
  35. package/dist/codegen/backend.d.cts +35 -0
  36. package/dist/codegen/backends/imperative.cjs +542 -1
  37. package/dist/codegen/backends/imperative.d.cts +11 -0
  38. package/dist/codegen/backends/imperative.d.ts.map +1 -1
  39. package/dist/codegen/backends/imperative.js +68 -13
  40. package/dist/codegen/backends/imperative.mjs +519 -1
  41. package/dist/codegen/contract.cjs +52 -1
  42. package/dist/codegen/contract.d.cts +24 -0
  43. package/dist/codegen/contract.mjs +31 -1
  44. package/dist/codegen/partial-template.cjs +176 -1
  45. package/dist/codegen/partial-template.d.cts +61 -0
  46. package/dist/codegen/partial-template.mjs +153 -1
  47. package/dist/codegen/serialize-static.cjs +125 -1
  48. package/dist/codegen/serialize-static.d.cts +38 -0
  49. package/dist/codegen/serialize-static.d.ts +16 -0
  50. package/dist/codegen/serialize-static.d.ts.map +1 -1
  51. package/dist/codegen/serialize-static.js +25 -0
  52. package/dist/codegen/serialize-static.mjs +104 -1
  53. package/dist/frontend/babel/build-ir-lit.cjs +1509 -1
  54. package/dist/frontend/babel/build-ir-lit.d.cts +26 -0
  55. package/dist/frontend/babel/build-ir-lit.mjs +1478 -1
  56. package/dist/frontend/babel/build-ir.cjs +1524 -1
  57. package/dist/frontend/babel/build-ir.d.cts +35 -0
  58. package/dist/frontend/babel/build-ir.mjs +1495 -1
  59. package/dist/frontend/babel/index.cjs +2186 -1
  60. package/dist/frontend/babel/index.d.cts +33 -0
  61. package/dist/frontend/babel/index.mjs +2156 -1
  62. package/dist/frontend/babel/lower-template.cjs +1507 -1
  63. package/dist/frontend/babel/lower-template.d.cts +23 -0
  64. package/dist/frontend/babel/lower-template.mjs +1478 -1
  65. package/dist/frontend/babel/plugin.cjs +2132 -1
  66. package/dist/frontend/babel/plugin.d.cts +95 -0
  67. package/dist/frontend/babel/plugin.mjs +2103 -1
  68. package/dist/frontend/babel/server-functions.cjs +110 -1
  69. package/dist/frontend/babel/server-functions.d.cts +10 -0
  70. package/dist/frontend/babel/server-functions.mjs +89 -1
  71. package/dist/frontend/babel/types.cjs +18 -1
  72. package/dist/frontend/babel/types.d.cts +33 -0
  73. package/dist/frontend/types.cjs +18 -1
  74. package/dist/frontend/types.d.cts +25 -0
  75. package/dist/frontend/vocabulary.cjs +98 -0
  76. package/dist/frontend/vocabulary.d.cts +79 -0
  77. package/dist/frontend/vocabulary.d.ts +80 -0
  78. package/dist/frontend/vocabulary.d.ts.map +1 -0
  79. package/dist/frontend/vocabulary.js +124 -0
  80. package/dist/frontend/vocabulary.mjs +77 -0
  81. package/dist/index.cjs +1594 -13
  82. package/dist/index.d.cts +27 -0
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +3 -0
  85. package/dist/index.mjs +1574 -13
  86. package/dist/integrations.cjs +4307 -25
  87. package/dist/integrations.d.cts +215 -0
  88. package/dist/integrations.d.ts +16 -0
  89. package/dist/integrations.d.ts.map +1 -1
  90. package/dist/integrations.js +21 -2
  91. package/dist/integrations.mjs +531 -17
  92. package/dist/ir/nodes.cjs +18 -1
  93. package/dist/ir/nodes.d.cts +168 -0
  94. package/dist/ir/nodes.d.ts +46 -0
  95. package/dist/ir/nodes.d.ts.map +1 -1
  96. package/dist/lower/compile-template.cjs +1356 -1
  97. package/dist/lower/compile-template.d.cts +69 -0
  98. package/dist/lower/compile-template.d.ts +12 -0
  99. package/dist/lower/compile-template.d.ts.map +1 -1
  100. package/dist/lower/compile-template.js +5 -1
  101. package/dist/lower/compile-template.mjs +1336 -1
  102. package/dist/lower/jsx.cjs +529 -1
  103. package/dist/lower/jsx.d.cts +25 -0
  104. package/dist/lower/jsx.d.ts +2 -0
  105. package/dist/lower/jsx.d.ts.map +1 -1
  106. package/dist/lower/jsx.js +27 -4
  107. package/dist/lower/jsx.mjs +506 -1
  108. package/dist/lower/template.cjs +1061 -1
  109. package/dist/lower/template.d.cts +53 -0
  110. package/dist/lower/template.d.ts +14 -1
  111. package/dist/lower/template.d.ts.map +1 -1
  112. package/dist/lower/template.js +106 -19
  113. package/dist/lower/template.mjs +1042 -1
  114. package/dist/lower/text.cjs +42 -1
  115. package/dist/lower/text.d.cts +10 -0
  116. package/dist/lower/text.mjs +21 -1
  117. package/dist/optimize/analyze-static.cjs +112 -1
  118. package/dist/optimize/analyze-static.d.cts +39 -0
  119. package/dist/optimize/analyze-static.mjs +91 -1
  120. package/dist/optimize/collapse-strategies.cjs +90 -1
  121. package/dist/optimize/collapse-strategies.d.cts +30 -0
  122. package/dist/optimize/collapse-strategies.mjs +67 -1
  123. package/dist/options.cjs +33 -1
  124. package/dist/options.d.cts +39 -0
  125. package/dist/options.mjs +12 -1
  126. package/dist/resolve/builtins.cjs +73 -1
  127. package/dist/resolve/builtins.d.cts +68 -0
  128. package/dist/resolve/builtins.mjs +53 -1
  129. package/dist/resolve/component-globals.cjs +233 -13
  130. package/dist/resolve/component-globals.d.cts +80 -0
  131. package/dist/resolve/component-globals.mjs +210 -13
  132. package/dist/resolve/component-resolver.cjs +80 -1
  133. package/dist/resolve/component-resolver.d.cts +68 -0
  134. package/dist/resolve/component-resolver.mjs +59 -1
  135. package/dist/resolve/load-directive.cjs +93 -1
  136. package/dist/resolve/load-directive.d.cts +53 -0
  137. package/dist/resolve/load-directive.mjs +72 -1
  138. package/dist/resolve/resolve-ir.cjs +108 -1
  139. package/dist/resolve/resolve-ir.d.cts +53 -0
  140. package/dist/resolve/resolve-ir.mjs +85 -1
  141. package/dist/resolve/write-globals.cjs +318 -13
  142. package/dist/resolve/write-globals.d.cts +30 -0
  143. package/dist/resolve/write-globals.mjs +297 -13
  144. package/dist/server-fns-4ZXN6DYU.mjs +78 -0
  145. package/dist/server-functions-V6D6DRIA.mjs +82 -0
  146. package/dist/transform/bindings.cjs +71 -1
  147. package/dist/transform/bindings.d.cts +16 -0
  148. package/dist/transform/bindings.mjs +50 -1
  149. package/dist/transform/index.cjs +2732 -8
  150. package/dist/transform/index.d.cts +15 -0
  151. package/dist/transform/index.mjs +3773 -17
  152. package/dist/transform/intrinsics.cjs +216 -3
  153. package/dist/transform/intrinsics.d.cts +21 -0
  154. package/dist/transform/intrinsics.mjs +193 -3
  155. package/dist/transform/props.cjs +441 -3
  156. package/dist/transform/props.d.cts +45 -0
  157. package/dist/transform/props.mjs +1482 -12
  158. package/dist/transform/server-fn-id.cjs +35 -1
  159. package/dist/transform/server-fn-id.d.cts +9 -0
  160. package/dist/transform/server-fn-id.mjs +14 -1
  161. package/dist/transform/server-fns.cjs +114 -2
  162. package/dist/transform/server-fns.d.cts +12 -0
  163. package/dist/transform/server-fns.mjs +1155 -11
  164. package/dist/transform/source-locations.cjs +330 -0
  165. package/dist/transform/source-locations.d.cts +43 -0
  166. package/dist/transform/source-locations.d.ts +44 -0
  167. package/dist/transform/source-locations.d.ts.map +1 -0
  168. package/dist/transform/source-locations.js +238 -0
  169. package/dist/transform/source-locations.mjs +307 -0
  170. package/dist/transform/templates.cjs +2701 -7
  171. package/dist/transform/templates.d.cts +69 -0
  172. package/dist/transform/templates.d.ts +12 -4
  173. package/dist/transform/templates.d.ts.map +1 -1
  174. package/dist/transform/templates.js +72 -7
  175. package/dist/transform/templates.mjs +3743 -16
  176. package/dist/transform-BT4MMASR.mjs +893 -0
  177. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  178. package/package.json +6 -5
  179. package/dist/babel-4JUDAR2G.mjs +0 -1
  180. package/dist/chunk-3SAEGOMQ.mjs +0 -1
  181. package/dist/chunk-IBRM4W7I.mjs +0 -10
  182. package/dist/chunk-OHHZCYIQ.mjs +0 -1
  183. package/dist/chunk-PVR2SN3B.mjs +0 -1
  184. package/dist/chunk-QUIYULS2.mjs +0 -1
  185. package/dist/chunk-YR3SAEO7.mjs +0 -1
  186. package/dist/server-fns-6QM243HC.mjs +0 -2
  187. package/dist/server-functions-E3LKCZ4R.mjs +0 -1
  188. package/dist/transform-5WC4FWJE.mjs +0 -8
@@ -1,6 +1,8 @@
1
1
  import { planPartialTemplate } from '../partial-template.js';
2
- import { isSerializable, serializeStatic, isPlainLiteralAttr, htmlAttrName, } from '../serialize-static.js';
2
+ import { isSerializable, serializeStatic, templatePositions, isPlainLiteralAttr, htmlAttrName, } from '../serialize-static.js';
3
3
  import { RUNTIME_CONTRACT_V1 } from '../contract.js';
4
+ import { markHole, markProps, SOURCE_MARKER } from '../../transform/source-locations.js';
5
+ import { paren } from '../../analyze/paren.js';
4
6
  /**
5
7
  * Imperative fine-grained backend — emits createNativeElement/insert/spread/
6
8
  * createComponent (RUNTIME_CONTRACT_V1), the runtime proven by the @fluixi/dom
@@ -34,9 +36,17 @@ function propKey(name) {
34
36
  }
35
37
  function propValue(p) {
36
38
  if (p.expr !== undefined) {
39
+ // A ref is not reactive, but which variable ends up holding the element is worth
40
+ // saying, so it carries its own text and position.
41
+ if (p.name === 'ref' && p.at)
42
+ return markHole(paren(p.expr, 'value'), p.at.line, p.at.column, p.expr);
37
43
  // Events and non-reactive expressions pass through; reactive ones become thunks
38
44
  // so the runtime (spread/insert) can wire a render effect.
39
- return p.reactive ? `() => (${p.expr})` : `(${p.expr})`;
45
+ if (!p.reactive)
46
+ return paren(p.expr, 'value');
47
+ const accessor = `() => ${paren(p.expr, 'arrowBody')}`;
48
+ // `at` is the gate: a production build carries no marker.
49
+ return p.at ? markHole(accessor, p.at.line, p.at.column, p.directive) : accessor;
40
50
  }
41
51
  return JSON.stringify(p.literal ?? true);
42
52
  }
@@ -49,8 +59,9 @@ function propValue(p) {
49
59
  * function instead of the value (e.g. `history.get is not a function`).
50
60
  */
51
61
  function componentPropValue(p) {
62
+ // Sits in a `return`, where a top-level comma would read as a sequence.
52
63
  if (p.expr !== undefined)
53
- return `(${p.expr})`;
64
+ return paren(p.expr, 'value');
54
65
  return JSON.stringify(p.literal ?? true);
55
66
  }
56
67
  /** Build a props object literal (or mergeProps(...) when spreads are present). */
@@ -67,12 +78,20 @@ function emitProps(props, childrenExpr, used) {
67
78
  }
68
79
  return obj;
69
80
  }
81
+ /**
82
+ * The memo a component lowers to is an accessor, so it takes the same hole mark as any
83
+ * other reactive binding. Without it, the insert that places the subtree reports whatever
84
+ * the runtime stack says — a position in the compiled file.
85
+ */
86
+ function markBind(code, at) {
87
+ return at ? markHole(code, at.line, at.column) : code;
88
+ }
70
89
  function emitChildren(children, used, templates) {
71
90
  if (children.length === 1)
72
91
  return emitNode(children[0], used, templates);
73
92
  return `[${children.map((c) => emitNode(c, used, templates)).join(', ')}]`;
74
93
  }
75
- function emitComponent(name, props, children, used, templates) {
94
+ function emitComponent(name, props, children, used, templates, at) {
76
95
  used.add('createMemo');
77
96
  used.add('createComponent');
78
97
  const spreads = props.filter((p) => p.kind === 'spread');
@@ -95,6 +114,14 @@ function emitComponent(name, props, children, used, templates) {
95
114
  used.add('mergeProps');
96
115
  obj = `mergeProps(${spreads.map((s) => s.expr).join(', ')}, ${obj})`;
97
116
  }
117
+ // Every prop is a getter, so none of them can carry a position. The map rides alongside,
118
+ // and a build that recorded no locations emits nothing.
119
+ const propAt = {};
120
+ for (const p of normal)
121
+ if (p.at)
122
+ propAt[p.name] = [p.at.line, p.at.column];
123
+ if (Object.keys(propAt).length)
124
+ obj = markProps(obj, propAt);
98
125
  // The memo never recomputes — every prop is a getter, so this callback reads nothing
99
126
  // reactive. It is here for what it makes `insert` do, and it cannot be elided.
100
127
  //
@@ -115,7 +142,14 @@ function emitComponent(name, props, children, used, templates) {
115
142
  // Control flow does use a bare arrow, and that is not a counter-example: control flow
116
143
  // is the reactive boundary and is *meant* to re-run. A user component is meant to run
117
144
  // once.
118
- return `createMemo(() => createComponent(${name}, ${obj}))`;
145
+ // The mark goes inside the call, where it runs before createMemo makes the node and so
146
+ // is the one the node takes. Devtools installs the global; without it this is a no-op.
147
+ const mark = at
148
+ ? `globalThis.${SOURCE_MARKER}?.(${JSON.stringify(at.file)},${at.line},${at.column},${JSON.stringify(name)}), `
149
+ : '';
150
+ // The mark makes this a sequence, which has to stay wrapped to pass as one argument.
151
+ // Without one there is nothing to wrap, and a production build never has one.
152
+ return `createMemo(${paren(`${mark}() => createComponent(${name}, ${obj})`, 'value')})`;
119
153
  }
120
154
  /** `el.setAttribute("class", "card")` for a compile-time constant. */
121
155
  function staticAttrAssignment(el, prop) {
@@ -133,18 +167,25 @@ function emitNode(node, used, templates) {
133
167
  switch (node.kind) {
134
168
  case 'text':
135
169
  return JSON.stringify(node.value);
136
- case 'expr':
137
- return node.reactive ? `() => (${node.code})` : `(${node.code})`;
170
+ case 'expr': {
171
+ if (!node.reactive)
172
+ return paren(node.code, 'value');
173
+ const accessor = `() => ${paren(node.code, 'arrowBody')}`;
174
+ return node.at ? markHole(accessor, node.at.line, node.at.column) : accessor;
175
+ }
138
176
  case 'fragment':
139
177
  if (node.children.length === 0)
140
178
  return 'null';
141
179
  return emitChildren(node.children, used, templates);
142
180
  case 'component':
143
- return emitComponent(node.name, node.props, node.children, used, templates);
181
+ // No reactive prop means no `bindAt`, which is most tags. The insert that places the
182
+ // subtree still has to report somewhere, and the tag itself is where it was written —
183
+ // without this it reports whatever the runtime stack says, a line in the compiled file.
184
+ return markBind(emitComponent(node.name, node.props, node.children, used, templates, node.at), node.bindAt ?? node.at);
144
185
  case 'control': {
145
186
  const name = CONTROL_COMPONENT[node.control] ?? node.control;
146
187
  used.add(name);
147
- return emitComponent(name, node.props, node.children, used, templates);
188
+ return markBind(emitComponent(name, node.props, node.children, used, templates), node.bindAt);
148
189
  }
149
190
  case 'element': {
150
191
  // A static subtree is parsed once into a <template> and cloned per instance:
@@ -157,7 +198,12 @@ function emitNode(node, used, templates) {
157
198
  used.add('templateNode');
158
199
  const id = `_tmpl$${templates.length}`;
159
200
  templates.push({ id, html: serializeStatic(node), tag: node.tag, svg: false });
160
- return `templateNode(${id}, ${JSON.stringify(node.tag)})`;
201
+ // The positions ride along so devtools can name the line each element was written
202
+ // on; the template string itself maps back to the root and nothing finer.
203
+ const at = templatePositions(node);
204
+ return at
205
+ ? `templateNode(${id}, ${JSON.stringify(node.tag)}, false, false, ${JSON.stringify(at)})`
206
+ : `templateNode(${id}, ${JSON.stringify(node.tag)})`;
161
207
  }
162
208
  // Structure static, contents dynamic — the common shape. One template for the
163
209
  // structure, then each hole filled through a reference into the clone. Every
@@ -172,7 +218,10 @@ function emitNode(node, used, templates) {
172
218
  used.add('holeScope');
173
219
  const id = `_tmpl$${templates.length}`;
174
220
  templates.push({ id, html: plan.html, tag: plan.tag, svg: false });
175
- const lines = [`const _el$ = templateNode(${id}, ${JSON.stringify(plan.tag)}, true);`];
221
+ const at = templatePositions(node);
222
+ const lines = [
223
+ `const _el$ = templateNode(${id}, ${JSON.stringify(plan.tag)}, true${at ? `, false, ${JSON.stringify(at)}` : ''});`,
224
+ ];
176
225
  // Every reference first: inserting shifts what follows, so the walk has to be
177
226
  // complete before any content goes in.
178
227
  for (const step of plan.steps)
@@ -184,7 +233,7 @@ function emitNode(node, used, templates) {
184
233
  // `holeScope` places the hydration cursor at what the server rendered for
185
234
  // this hole, so anything the content builds internally adopts too.
186
235
  lines.push(`insert(${hole.parentRef}, holeScope(${hole.startRef}, () => ` +
187
- `(${emitNode(hole.node, used, templates)})), ` +
236
+ `${paren(emitNode(hole.node, used, templates), 'arrowBody')}), ` +
188
237
  `${hole.endRef}, holeContent(${hole.startRef}, ${hole.endRef}));`);
189
238
  }
190
239
  lines.push('return _el$;');
@@ -195,7 +244,13 @@ function emitNode(node, used, templates) {
195
244
  const tag = JSON.stringify(node.tag);
196
245
  const el = '_el$';
197
246
  const parts = [];
198
- const createArgs = node.svg ? `${tag}, true` : tag;
247
+ // The third argument is where the tag was written. An element built this way is not
248
+ // in a template, so nothing else records it.
249
+ const createArgs = node.at
250
+ ? `${tag}, ${node.svg}, ${JSON.stringify(node.at)}`
251
+ : node.svg
252
+ ? `${tag}, true`
253
+ : tag;
199
254
  parts.push(`const ${el} = createNativeElement(${createArgs});`);
200
255
  if (node.props.length > 0) {
201
256
  // Literal attributes are written straight on. `spread` is a generic helper that