@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
@@ -0,0 +1,330 @@
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/transform/source-locations.ts
21
+ var source_locations_exports = {};
22
+ __export(source_locations_exports, {
23
+ COMPONENT_MARKER: () => COMPONENT_MARKER,
24
+ HOLE_MARKER: () => HOLE_MARKER,
25
+ PROPS_MARKER: () => PROPS_MARKER,
26
+ SOURCE_MARKER: () => SOURCE_MARKER,
27
+ collectSourceEdits: () => collectSourceEdits,
28
+ markHole: () => markHole,
29
+ markProps: () => markProps,
30
+ mayHaveReactiveCall: () => mayHaveReactiveCall
31
+ });
32
+ module.exports = __toCommonJS(source_locations_exports);
33
+
34
+ // src/analyze/intrinsics.ts
35
+ var REACTIVE_MODULE = "@fluixi/reactive/signal";
36
+ var INTRINSICS = {
37
+ $signal: { export: "signal", module: REACTIVE_MODULE, returns: "signal-handle" },
38
+ $memo: { export: "memo", module: REACTIVE_MODULE, returns: "memo-handle" },
39
+ $effect: { export: "effect", module: REACTIVE_MODULE, returns: "effect" },
40
+ $store: { export: "store", module: "@fluixi/reactive/store", returns: "store-handle" },
41
+ $resource: { export: "resource", module: REACTIVE_MODULE, returns: "resource-handle" },
42
+ // No short runtime form for these yet, so the intrinsic stands for the `create*`
43
+ // name. Still worth having — no import to write — and when a shorter form is
44
+ // designed, the change is this line rather than a compiler pass.
45
+ $selector: { export: "createSelector", module: REACTIVE_MODULE, returns: "memo-accessor" },
46
+ $deferred: { export: "createDeferred", module: REACTIVE_MODULE, returns: "memo-accessor" },
47
+ // Not value constructors, but the compiler has to know them: they change what a read
48
+ // does. `untrack` suppresses dependency collection, which is exactly the kind of thing
49
+ // dependency analysis must not guess at.
50
+ $untrack: { export: "untrack", module: REACTIVE_MODULE, returns: "plain" },
51
+ $untrackStore: { export: "untrackStore", module: "@fluixi/reactive/store", returns: "plain" }
52
+ };
53
+ var RUNTIME_PRIMITIVES = {
54
+ signal: "signal-handle",
55
+ memo: "memo-handle",
56
+ effect: "effect",
57
+ store: "store-handle",
58
+ createSignal: ["signal-accessor", "signal-setter"],
59
+ createMemo: "memo-accessor",
60
+ createEffect: "effect",
61
+ createRenderEffect: "effect",
62
+ createStore: "reactive-object",
63
+ resource: "resource-handle",
64
+ createResource: "reactive-object",
65
+ createSelector: "memo-accessor",
66
+ createDeferred: "memo-accessor"
67
+ };
68
+ var PRIMITIVE_MODULES = [
69
+ "@fluixi/reactive",
70
+ "@fluixi/reactive/signal",
71
+ "@fluixi/reactive/store",
72
+ "@fluixi/core"
73
+ ];
74
+ var INTRINSIC_CALL = new RegExp(`\\$(?:${Object.keys(INTRINSICS).map((n) => n.slice(1)).join("|")})\\s*\\(`);
75
+ function isIntrinsicName(name) {
76
+ return Object.prototype.hasOwnProperty.call(INTRINSICS, name);
77
+ }
78
+ function isPrimitiveModule(source) {
79
+ return PRIMITIVE_MODULES.includes(source);
80
+ }
81
+
82
+ // src/analyze/reactive-bindings.ts
83
+ function patternNames(node, out) {
84
+ if (!node) return;
85
+ switch (node.type) {
86
+ case "Identifier":
87
+ out.add(node.name);
88
+ return;
89
+ case "ObjectPattern":
90
+ for (const p of node.properties ?? []) {
91
+ if (p.type === "RestElement") patternNames(p.argument, out);
92
+ else patternNames(p.value, out);
93
+ }
94
+ return;
95
+ case "ArrayPattern":
96
+ for (const e of node.elements ?? []) patternNames(e, out);
97
+ return;
98
+ case "AssignmentPattern":
99
+ patternNames(node.left, out);
100
+ return;
101
+ case "RestElement":
102
+ patternNames(node.argument, out);
103
+ return;
104
+ }
105
+ }
106
+ function walk(root, visit) {
107
+ if (!root || typeof root !== "object" || typeof root.type !== "string") return;
108
+ visit(root);
109
+ for (const key of Object.keys(root)) {
110
+ if (key === "loc" || key === "leadingComments" || key === "trailingComments") continue;
111
+ const value = root[key];
112
+ if (Array.isArray(value)) for (const item of value) walk(item, visit);
113
+ else if (value && typeof value === "object") walk(value, visit);
114
+ }
115
+ }
116
+ function calledPrimitive(node, bindings) {
117
+ if (node.type !== "CallExpression") return void 0;
118
+ const callee = node.callee;
119
+ if (callee?.type !== "Identifier") return void 0;
120
+ const name = callee.name;
121
+ const imported = bindings.primitives.get(name);
122
+ if (imported) return imported;
123
+ const intrinsic = INTRINSICS[name];
124
+ if (intrinsic && !bindings.shadowed.has(name)) return intrinsic.returns;
125
+ return void 0;
126
+ }
127
+ function classify(id, returns, kinds) {
128
+ if (Array.isArray(returns)) {
129
+ if (id.type === "ArrayPattern") {
130
+ id.elements.forEach((element, index) => {
131
+ const kind = returns[index];
132
+ if (element?.type === "Identifier" && kind) kinds.set(element.name, kind);
133
+ });
134
+ }
135
+ return;
136
+ }
137
+ if (id.type === "Identifier") kinds.set(id.name, returns);
138
+ }
139
+ function resolveReactiveBindings(program) {
140
+ const bindings = { kinds: /* @__PURE__ */ new Map(), primitives: /* @__PURE__ */ new Map(), shadowed: /* @__PURE__ */ new Set() };
141
+ const root = program;
142
+ walk(root, (node) => {
143
+ const names = /* @__PURE__ */ new Set();
144
+ if (node.type === "VariableDeclarator") patternNames(node.id, names);
145
+ else if (node.type === "FunctionDeclaration" || node.type === "ClassDeclaration") patternNames(node.id, names);
146
+ else if (node.type === "ImportDefaultSpecifier" || node.type === "ImportNamespaceSpecifier") patternNames(node.local, names);
147
+ else if (node.type === "ImportSpecifier") patternNames(node.local, names);
148
+ else if (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression" || node.type === "FunctionDeclaration") {
149
+ for (const p of node.params ?? []) patternNames(p, names);
150
+ }
151
+ for (const name of names) if (INTRINSICS[name]) bindings.shadowed.add(name);
152
+ });
153
+ for (const statement of root.body ?? []) {
154
+ if (statement.type !== "ImportDeclaration") continue;
155
+ if (!isPrimitiveModule(statement.source?.value)) continue;
156
+ for (const specifier of statement.specifiers ?? []) {
157
+ if (specifier.type !== "ImportSpecifier") continue;
158
+ const importedNode = specifier.imported;
159
+ const imported = importedNode.type === "Identifier" ? importedNode.name : importedNode.value;
160
+ const returns = RUNTIME_PRIMITIVES[imported];
161
+ if (returns) bindings.primitives.set(specifier.local.name, returns);
162
+ }
163
+ }
164
+ walk(root, (node) => {
165
+ if (node.type !== "VariableDeclarator" || !node.init) return;
166
+ const returns = calledPrimitive(node.init, bindings);
167
+ if (returns) classify(node.id, returns, bindings.kinds);
168
+ });
169
+ return bindings;
170
+ }
171
+
172
+ // src/transform/source-locations.ts
173
+ var SOURCE_MARKER = "__fx_source";
174
+ var COMPONENT_MARKER = "__fx_component";
175
+ var HOLE_MARKER = "__fx_hole";
176
+ var markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MARKER} ?? ((f) => f))(${accessor},${line},${column}${name === void 0 ? "" : `,${JSON.stringify(name)}`})`;
177
+ var PROPS_MARKER = "__fx_props";
178
+ var markProps = (object, at) => `(globalThis.${PROPS_MARKER} ?? ((p) => p))(${object},${JSON.stringify(at)})`;
179
+ var RUNTIME_PRIMITIVES2 = /* @__PURE__ */ new Set([
180
+ "signal",
181
+ "memo",
182
+ "effect",
183
+ "store",
184
+ "resource",
185
+ "watch",
186
+ "createSignal",
187
+ "createMemo",
188
+ "createEffect",
189
+ "createStore",
190
+ "createResource"
191
+ ]);
192
+ function mayHaveReactiveCall(code) {
193
+ for (const name of RUNTIME_PRIMITIVES2) {
194
+ if (code.includes(name)) return true;
195
+ }
196
+ return code.includes("$signal") || code.includes("$memo") || code.includes("$effect") || code.includes("$store");
197
+ }
198
+ var SINGLE_STATEMENT_PARENTS = /* @__PURE__ */ new Set([
199
+ "IfStatement",
200
+ "ForStatement",
201
+ "ForInStatement",
202
+ "ForOfStatement",
203
+ "WhileStatement",
204
+ "DoWhileStatement",
205
+ "LabeledStatement",
206
+ "WithStatement"
207
+ ]);
208
+ function isLoneBranch(statement, parent) {
209
+ if (!parent || statement.type === "BlockStatement") return false;
210
+ return SINGLE_STATEMENT_PARENTS.has(parent.type);
211
+ }
212
+ function isExport(node) {
213
+ return node.type === "ExportNamedDeclaration" || node.type === "ExportDefaultDeclaration";
214
+ }
215
+ function isStatement(node) {
216
+ return node.type.endsWith("Statement") || node.type === "VariableDeclaration";
217
+ }
218
+ function walk2(node, visit, stack = []) {
219
+ if (!node || typeof node.type !== "string") return;
220
+ visit(node, stack);
221
+ stack.push(node);
222
+ for (const key of Object.keys(node)) {
223
+ if (key === "loc" || key === "parent") continue;
224
+ const value = node[key];
225
+ if (Array.isArray(value)) {
226
+ for (const child of value) walk2(child, visit, stack);
227
+ } else if (value && typeof value.type === "string") {
228
+ walk2(value, visit, stack);
229
+ }
230
+ }
231
+ stack.pop();
232
+ }
233
+ function nameFor(stack) {
234
+ const declarator = stack[stack.length - 1];
235
+ if (declarator?.type !== "VariableDeclarator") return void 0;
236
+ const id = declarator.id;
237
+ if (id?.type === "Identifier") return id.name;
238
+ if (id?.type === "ArrayPattern") {
239
+ const first = id.elements?.[0];
240
+ if (first?.type === "Identifier") return first.name;
241
+ }
242
+ return void 0;
243
+ }
244
+ function componentName(node) {
245
+ if (node.type === "FunctionDeclaration") {
246
+ const name = node.id?.name;
247
+ return name && name[0] === name[0]?.toUpperCase() ? name : void 0;
248
+ }
249
+ if (node.type === "VariableDeclarator") {
250
+ const id = node.id;
251
+ const init = node.init;
252
+ if (id?.type !== "Identifier" || !init) return void 0;
253
+ if (init.type !== "ArrowFunctionExpression" && init.type !== "FunctionExpression") return void 0;
254
+ const name = id.name;
255
+ return name[0] === name[0]?.toUpperCase() ? name : void 0;
256
+ }
257
+ return void 0;
258
+ }
259
+ function collectSourceEdits(program, filename) {
260
+ const edits = [];
261
+ const claimed = /* @__PURE__ */ new Set();
262
+ const { primitives, shadowed } = resolveReactiveBindings(program);
263
+ walk2(program, (node, stack) => {
264
+ const component = componentName(node);
265
+ if (component) {
266
+ const at = node.loc?.start;
267
+ let end2 = node.end;
268
+ for (let i = stack.length - 1; i >= 0; i--) {
269
+ const up = stack[i];
270
+ if (up.type !== "VariableDeclaration" && up.type !== "ExportNamedDeclaration" && up.type !== "ExportDefaultDeclaration") {
271
+ break;
272
+ }
273
+ end2 = up.end;
274
+ }
275
+ if (at) {
276
+ edits.push({
277
+ start: end2,
278
+ end: end2,
279
+ code: `;globalThis.${COMPONENT_MARKER}?.(${JSON.stringify(component)},${JSON.stringify(filename)},${at.line},${at.column});`
280
+ });
281
+ }
282
+ }
283
+ if (node.type !== "CallExpression") return;
284
+ const callee = node.callee;
285
+ if (callee?.type !== "Identifier") return;
286
+ const name = callee.name;
287
+ const intrinsic = isIntrinsicName(name) && !shadowed.has(name) ? INTRINSICS[name] : void 0;
288
+ const imported = primitives.has(name) || RUNTIME_PRIMITIVES2.has(name);
289
+ if (!intrinsic && !imported) return;
290
+ const position = node.loc?.start;
291
+ if (!position) return;
292
+ let statement;
293
+ let parent;
294
+ let index = -1;
295
+ for (let i = stack.length - 1; i >= 0; i--) {
296
+ if (isStatement(stack[i]) || isExport(stack[i])) {
297
+ statement = stack[i];
298
+ parent = stack[i - 1];
299
+ index = i;
300
+ break;
301
+ }
302
+ }
303
+ if (!statement) return;
304
+ let start = statement.start;
305
+ let end = statement.end;
306
+ for (let i = index - 1; i >= 0; i--) {
307
+ if (!isExport(stack[i])) break;
308
+ start = stack[i].start;
309
+ end = stack[i].end;
310
+ parent = stack[i - 1];
311
+ }
312
+ if (claimed.has(start)) return;
313
+ claimed.add(start);
314
+ const label = nameFor(stack);
315
+ const args = [
316
+ JSON.stringify(filename),
317
+ String(position.line),
318
+ String(position.column),
319
+ label ? JSON.stringify(label) : void 0
320
+ ].filter((a) => a !== void 0).join(",");
321
+ const mark = `globalThis.${SOURCE_MARKER}?.(${args});`;
322
+ if (isLoneBranch(statement, parent)) {
323
+ edits.push({ start, end: start, code: `{${mark}` });
324
+ edits.push({ start: end, end, code: "}" });
325
+ return;
326
+ }
327
+ edits.push({ start, end: start, code: mark });
328
+ });
329
+ return { edits, marked: edits.length };
330
+ }
@@ -0,0 +1,43 @@
1
+ export interface SourceEdit {
2
+ start: number;
3
+ end: number;
4
+ code: string;
5
+ }
6
+ export interface SourceLocationsResult {
7
+ edits: SourceEdit[];
8
+ /** How many creation sites were marked. */
9
+ marked: number;
10
+ }
11
+ /** Installed by @fluixi/devtools; undefined everywhere else. */
12
+ export declare const SOURCE_MARKER = "__fx_source";
13
+ /** Where a component was declared. Keyed by name, since that is all the runtime carries. */
14
+ export declare const COMPONENT_MARKER = "__fx_component";
15
+ /**
16
+ * Where one reactive hole was written. This one wraps: the position has to travel with the
17
+ * accessor to wherever the dom wires it up. A template is emitted as one overwrite, so the
18
+ * source map has a single entry for the root and every hole traces back to it.
19
+ *
20
+ * `?? (f => f)` and not `?.()`: the value is the accessor, and returning undefined would
21
+ * delete the binding.
22
+ */
23
+ export declare const HOLE_MARKER = "__fx_hole";
24
+ /**
25
+ * `_(() => x(), 9, 25)`, or the accessor untouched when nothing is watching.
26
+ *
27
+ * `name` is the source text the value came from, for a `ref` where knowing which variable
28
+ * holds the element is the whole question.
29
+ */
30
+ export declare const markHole: (accessor: string, line: number, column: number, name?: string) => string;
31
+ /**
32
+ * Where each prop of a component tag was written.
33
+ *
34
+ * The props object is built as getters, so nothing in it can carry a position of its own.
35
+ * The marker takes the object and a name-to-position map, and hands the object straight
36
+ * back — devtools keeps the map, and a build without it passes the object through.
37
+ */
38
+ export declare const PROPS_MARKER = "__fx_props";
39
+ /** `_({ get a() {…} }, {"a":[9,25]})`, or the object untouched when nothing is watching. */
40
+ export declare const markProps: (object: string, at: Record<string, [number, number]>) => string;
41
+ /** Cheap enough to run before parsing. */
42
+ export declare function mayHaveReactiveCall(code: string): boolean;
43
+ export declare function collectSourceEdits(program: unknown, filename: string): SourceLocationsResult;
@@ -0,0 +1,44 @@
1
+ export interface SourceEdit {
2
+ start: number;
3
+ end: number;
4
+ code: string;
5
+ }
6
+ export interface SourceLocationsResult {
7
+ edits: SourceEdit[];
8
+ /** How many creation sites were marked. */
9
+ marked: number;
10
+ }
11
+ /** Installed by @fluixi/devtools; undefined everywhere else. */
12
+ export declare const SOURCE_MARKER = "__fx_source";
13
+ /** Where a component was declared. Keyed by name, since that is all the runtime carries. */
14
+ export declare const COMPONENT_MARKER = "__fx_component";
15
+ /**
16
+ * Where one reactive hole was written. This one wraps: the position has to travel with the
17
+ * accessor to wherever the dom wires it up. A template is emitted as one overwrite, so the
18
+ * source map has a single entry for the root and every hole traces back to it.
19
+ *
20
+ * `?? (f => f)` and not `?.()`: the value is the accessor, and returning undefined would
21
+ * delete the binding.
22
+ */
23
+ export declare const HOLE_MARKER = "__fx_hole";
24
+ /**
25
+ * `_(() => x(), 9, 25)`, or the accessor untouched when nothing is watching.
26
+ *
27
+ * `name` is the source text the value came from, for a `ref` where knowing which variable
28
+ * holds the element is the whole question.
29
+ */
30
+ export declare const markHole: (accessor: string, line: number, column: number, name?: string) => string;
31
+ /**
32
+ * Where each prop of a component tag was written.
33
+ *
34
+ * The props object is built as getters, so nothing in it can carry a position of its own.
35
+ * The marker takes the object and a name-to-position map, and hands the object straight
36
+ * back — devtools keeps the map, and a build without it passes the object through.
37
+ */
38
+ export declare const PROPS_MARKER = "__fx_props";
39
+ /** `_({ get a() {…} }, {"a":[9,25]})`, or the object untouched when nothing is watching. */
40
+ export declare const markProps: (object: string, at: Record<string, [number, number]>) => string;
41
+ /** Cheap enough to run before parsing. */
42
+ export declare function mayHaveReactiveCall(code: string): boolean;
43
+ export declare function collectSourceEdits(program: unknown, filename: string): SourceLocationsResult;
44
+ //# sourceMappingURL=source-locations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source-locations.d.ts","sourceRoot":"","sources":["../../src/transform/source-locations.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,gEAAgE;AAChE,eAAO,MAAM,aAAa,gBAAgB,CAAC;AAE3C,4FAA4F;AAC5F,eAAO,MAAM,gBAAgB,mBAAmB,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,cAAc,CAAC;AAEvC;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,GACnB,UAAU,MAAM,EAChB,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,OAAO,MAAM,KACZ,MAGE,CAAC;AAEN;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,eAAe,CAAC;AAEzC,4FAA4F;AAC5F,eAAO,MAAM,SAAS,GAAI,QAAQ,MAAM,EAAE,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,KAAG,MACF,CAAC;AAQhF,0CAA0C;AAC1C,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAKzD;AAuED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,qBAAqB,CA+G5F"}
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Record where each reactive primitive was created, for the devtools graph.
3
+ *
4
+ * const count = signal(0);
5
+ * → globalThis.__fx_source?.("src/App.ts",1,14,"count"); const count = signal(0);
6
+ *
7
+ * A statement in front of the one that creates the node, not a wrapper round the call: the
8
+ * call may already be being rewritten — `$signal` becomes `signal` — and two passes editing
9
+ * one span is a splice over a splice.
10
+ *
11
+ * A global rather than an import, so the author's modules do not each take a dependency on
12
+ * @fluixi/devtools to carry a debug string. Nothing installs it by default.
13
+ *
14
+ * Positions come from the original source, before any pass moves anything.
15
+ *
16
+ * Development only, and one mark per statement — the runtime keeps a single slot, so
17
+ * marking two calls in one statement would hand the first node the second's location.
18
+ */
19
+ import { INTRINSICS, isIntrinsicName } from '../analyze/intrinsics.js';
20
+ import { resolveReactiveBindings } from '../analyze/reactive-bindings.js';
21
+ /** Installed by @fluixi/devtools; undefined everywhere else. */
22
+ export const SOURCE_MARKER = '__fx_source';
23
+ /** Where a component was declared. Keyed by name, since that is all the runtime carries. */
24
+ export const COMPONENT_MARKER = '__fx_component';
25
+ /**
26
+ * Where one reactive hole was written. This one wraps: the position has to travel with the
27
+ * accessor to wherever the dom wires it up. A template is emitted as one overwrite, so the
28
+ * source map has a single entry for the root and every hole traces back to it.
29
+ *
30
+ * `?? (f => f)` and not `?.()`: the value is the accessor, and returning undefined would
31
+ * delete the binding.
32
+ */
33
+ export const HOLE_MARKER = '__fx_hole';
34
+ /**
35
+ * `_(() => x(), 9, 25)`, or the accessor untouched when nothing is watching.
36
+ *
37
+ * `name` is the source text the value came from, for a `ref` where knowing which variable
38
+ * holds the element is the whole question.
39
+ */
40
+ export const markHole = (accessor, line, column, name) => `(globalThis.${HOLE_MARKER} ?? ((f) => f))(${accessor},${line},${column}${name === undefined ? '' : `,${JSON.stringify(name)}`})`;
41
+ /**
42
+ * Where each prop of a component tag was written.
43
+ *
44
+ * The props object is built as getters, so nothing in it can carry a position of its own.
45
+ * The marker takes the object and a name-to-position map, and hands the object straight
46
+ * back — devtools keeps the map, and a build without it passes the object through.
47
+ */
48
+ export const PROPS_MARKER = '__fx_props';
49
+ /** `_({ get a() {…} }, {"a":[9,25]})`, or the object untouched when nothing is watching. */
50
+ export const markProps = (object, at) => `(globalThis.${PROPS_MARKER} ?? ((p) => p))(${object},${JSON.stringify(at)})`;
51
+ /** The runtime names that make a node. */
52
+ const RUNTIME_PRIMITIVES = new Set([
53
+ 'signal', 'memo', 'effect', 'store', 'resource', 'watch',
54
+ 'createSignal', 'createMemo', 'createEffect', 'createStore', 'createResource',
55
+ ]);
56
+ /** Cheap enough to run before parsing. */
57
+ export function mayHaveReactiveCall(code) {
58
+ for (const name of RUNTIME_PRIMITIVES) {
59
+ if (code.includes(name))
60
+ return true;
61
+ }
62
+ return code.includes('$signal') || code.includes('$memo') || code.includes('$effect') || code.includes('$store');
63
+ }
64
+ /** Positions where the grammar allows exactly one statement, so a second one changes it. */
65
+ const SINGLE_STATEMENT_PARENTS = new Set([
66
+ 'IfStatement', 'ForStatement', 'ForInStatement', 'ForOfStatement',
67
+ 'WhileStatement', 'DoWhileStatement', 'LabeledStatement', 'WithStatement',
68
+ ]);
69
+ function isLoneBranch(statement, parent) {
70
+ if (!parent || statement.type === 'BlockStatement')
71
+ return false;
72
+ return SINGLE_STATEMENT_PARENTS.has(parent.type);
73
+ }
74
+ function isExport(node) {
75
+ return node.type === 'ExportNamedDeclaration' || node.type === 'ExportDefaultDeclaration';
76
+ }
77
+ function isStatement(node) {
78
+ return node.type.endsWith('Statement') || node.type === 'VariableDeclaration';
79
+ }
80
+ function walk(node, visit, stack = []) {
81
+ if (!node || typeof node.type !== 'string')
82
+ return;
83
+ visit(node, stack);
84
+ stack.push(node);
85
+ for (const key of Object.keys(node)) {
86
+ if (key === 'loc' || key === 'parent')
87
+ continue;
88
+ const value = node[key];
89
+ if (Array.isArray(value)) {
90
+ for (const child of value)
91
+ walk(child, visit, stack);
92
+ }
93
+ else if (value && typeof value.type === 'string') {
94
+ walk(value, visit, stack);
95
+ }
96
+ }
97
+ stack.pop();
98
+ }
99
+ /**
100
+ * const count = signal(0) → count
101
+ * const [count, setCount] = … → count, the accessor rather than the setter
102
+ * effect(() => …) → nothing
103
+ */
104
+ function nameFor(stack) {
105
+ const declarator = stack[stack.length - 1];
106
+ if (declarator?.type !== 'VariableDeclarator')
107
+ return undefined;
108
+ const id = declarator.id;
109
+ if (id?.type === 'Identifier')
110
+ return id.name;
111
+ if (id?.type === 'ArrayPattern') {
112
+ const first = id.elements?.[0];
113
+ if (first?.type === 'Identifier')
114
+ return first.name;
115
+ }
116
+ return undefined;
117
+ }
118
+ /** A capitalised function is how JSX tells a component from an element. */
119
+ function componentName(node) {
120
+ if (node.type === 'FunctionDeclaration') {
121
+ const name = node.id?.name;
122
+ return name && name[0] === name[0]?.toUpperCase() ? name : undefined;
123
+ }
124
+ if (node.type === 'VariableDeclarator') {
125
+ const id = node.id;
126
+ const init = node.init;
127
+ if (id?.type !== 'Identifier' || !init)
128
+ return undefined;
129
+ if (init.type !== 'ArrowFunctionExpression' && init.type !== 'FunctionExpression')
130
+ return undefined;
131
+ const name = id.name;
132
+ return name[0] === name[0]?.toUpperCase() ? name : undefined;
133
+ }
134
+ return undefined;
135
+ }
136
+ export function collectSourceEdits(program, filename) {
137
+ const edits = [];
138
+ // A single slot cannot describe more than the first primitive in a statement.
139
+ const claimed = new Set();
140
+ const { primitives, shadowed } = resolveReactiveBindings(program);
141
+ walk(program, (node, stack) => {
142
+ // The compiler wraps every component in a memo, and the memo is what the graph sees. It
143
+ // has no way back to the declaration, so the declaration says where it is by name.
144
+ const component = componentName(node);
145
+ if (component) {
146
+ const at = node.loc?.start;
147
+ // After the whole declaration, not after the function: `const Row = () => <b/>` ends
148
+ // where its jsx ends, and an insertion on that boundary is inside the span the
149
+ // template pass overwrites.
150
+ //
151
+ // Only through what wraps a declaration. Anything else above it is a block or an
152
+ // argument list, and a statement appended there lands outside the grammar —
153
+ // `function Page(){}` inside `it('…', () => { … })` ended up between the `}` and the
154
+ // `)`, which is a syntax error in a file that compiled a moment earlier.
155
+ let end = node.end;
156
+ for (let i = stack.length - 1; i >= 0; i--) {
157
+ const up = stack[i];
158
+ if (up.type !== 'VariableDeclaration' &&
159
+ up.type !== 'ExportNamedDeclaration' &&
160
+ up.type !== 'ExportDefaultDeclaration') {
161
+ break;
162
+ }
163
+ end = up.end;
164
+ }
165
+ if (at) {
166
+ edits.push({
167
+ start: end,
168
+ end,
169
+ code: `;globalThis.${COMPONENT_MARKER}?.(${JSON.stringify(component)},${JSON.stringify(filename)},${at.line},${at.column});`,
170
+ });
171
+ }
172
+ }
173
+ if (node.type !== 'CallExpression')
174
+ return;
175
+ const callee = node.callee;
176
+ if (callee?.type !== 'Identifier')
177
+ return;
178
+ const name = callee.name;
179
+ // The same test the intrinsics pass makes, so the two agree on what is a primitive.
180
+ const intrinsic = isIntrinsicName(name) && !shadowed.has(name) ? INTRINSICS[name] : undefined;
181
+ // resolveReactiveBindings has followed the import, so `signal as state` is covered and
182
+ // a local function of the same name is not.
183
+ const imported = primitives.has(name) || RUNTIME_PRIMITIVES.has(name);
184
+ if (!intrinsic && !imported)
185
+ return;
186
+ const position = node.loc?.start;
187
+ if (!position)
188
+ return;
189
+ // The mark goes in front of the statement, clear of any span another pass rewrites.
190
+ let statement;
191
+ let parent;
192
+ let index = -1;
193
+ for (let i = stack.length - 1; i >= 0; i--) {
194
+ if (isStatement(stack[i]) || isExport(stack[i])) {
195
+ statement = stack[i];
196
+ parent = stack[i - 1];
197
+ index = i;
198
+ break;
199
+ }
200
+ }
201
+ if (!statement)
202
+ return;
203
+ // `export const [cart] = createStore(…)` finds the declaration, which starts after the
204
+ // keyword — a mark there splits `export` from what it exports.
205
+ let start = statement.start;
206
+ let end = statement.end;
207
+ for (let i = index - 1; i >= 0; i--) {
208
+ if (!isExport(stack[i]))
209
+ break;
210
+ start = stack[i].start;
211
+ end = stack[i].end;
212
+ parent = stack[i - 1];
213
+ }
214
+ if (claimed.has(start))
215
+ return;
216
+ claimed.add(start);
217
+ const label = nameFor(stack);
218
+ const args = [
219
+ JSON.stringify(filename),
220
+ String(position.line),
221
+ String(position.column),
222
+ label ? JSON.stringify(label) : undefined,
223
+ ]
224
+ .filter((a) => a !== undefined)
225
+ .join(',');
226
+ const mark = `globalThis.${SOURCE_MARKER}?.(${args});`;
227
+ // `if (c) effect(…)` has one statement where the grammar allows one statement, so
228
+ // putting the mark in front of it moves the branch body out of the branch. Braces are
229
+ // added around both rather than skipping the mark.
230
+ if (isLoneBranch(statement, parent)) {
231
+ edits.push({ start, end: start, code: `{${mark}` });
232
+ edits.push({ start: end, end, code: '}' });
233
+ return;
234
+ }
235
+ edits.push({ start, end: start, code: mark });
236
+ });
237
+ return { edits, marked: edits.length };
238
+ }