@sigil-dev/compiler 0.9.29 → 0.9.30

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 (38) hide show
  1. package/index.ts +6 -4
  2. package/package.json +1 -1
  3. package/src/babel/index.ts +763 -750
  4. package/src/babel/jsx/anchor-mount.ts +338 -333
  5. package/src/babel/jsx/children.ts +116 -116
  6. package/src/babel/jsx/element.ts +1040 -1034
  7. package/src/babel/jsx/fragment.ts +271 -271
  8. package/src/babel/jsx/keyed-list.ts +339 -339
  9. package/src/babel/jsx/utils.ts +356 -356
  10. package/src/babel/util/bind.ts +143 -143
  11. package/src/babel/util/css.ts +208 -208
  12. package/src/babel/util/dead-code.ts +94 -93
  13. package/src/babel/util/links.ts +101 -0
  14. package/src/babel/util/reactive-fns.ts +110 -110
  15. package/src/babel/util/runtime-names.ts +88 -0
  16. package/src/babel/util/state-imports.ts +122 -121
  17. package/src/babel/util/static-assertion.ts +51 -51
  18. package/src/babel/util/static-env.ts +84 -0
  19. package/src/vite/index.ts +61 -61
  20. package/test/bun-plugin.test.ts +45 -45
  21. package/test/context.test.ts +110 -102
  22. package/test/fixtures/stores/index.ts +2 -2
  23. package/test/hydration-analysis.test.ts +133 -133
  24. package/test/hydration.test.ts +315 -313
  25. package/test/jsx.test.ts +254 -254
  26. package/test/links.test.ts +57 -0
  27. package/test/reactive-helpers.test.ts +135 -135
  28. package/test/render-parity.test.ts +909 -907
  29. package/test/runtime-names.test.ts +60 -0
  30. package/test/scoped-css.test.ts +166 -166
  31. package/test/ssr-boolean-attrs.test.ts +56 -56
  32. package/test/ssr-raw-text.test.ts +68 -68
  33. package/test/ssr.test.ts +30 -0
  34. package/test/static-assertion.test.ts +123 -123
  35. package/test/static-env.test.ts +85 -0
  36. package/test/static-skip.test.ts +292 -292
  37. package/test/style-object.test.ts +36 -36
  38. package/test/tree-shaking.test.ts +122 -120
@@ -1,339 +1,339 @@
1
- import { types as t } from "@babel/core";
2
- import { containsSignal } from "./utils";
3
-
4
- export type ProcessElementFn = (
5
- node: t.JSXElement,
6
- statements: t.Statement[],
7
- genId: () => string,
8
- signals: Set<string>,
9
- hash?: string,
10
- hydrate?: boolean,
11
- nodesVar?: string,
12
- ) => string;
13
-
14
- /**
15
- * Detect pattern: signal.map(item => <Tag key={expr} />) — or, since unkeyed
16
- * maps are also reconciled (index-keyed), signal.map(item => <Tag />). The
17
- * callback may take the index too: signal.map((item, i) => <Tag />).
18
- * Returns info needed to generate keyed list code, or null.
19
- * `hasKey` is false for the unkeyed form; buildKeyedList then keys by index.
20
- */
21
- export function findKeyedMapExpr(
22
- expr: t.Expression,
23
- signals: Set<string>,
24
- ): {
25
- callExpr: t.CallExpression;
26
- keyExpr: t.Expression | null;
27
- itemParam: t.Identifier;
28
- /** `i` in `(item, i) => …`, or null when the callback takes only the item. */
29
- indexParam: t.Identifier | null;
30
- jsxBody: t.JSXElement;
31
- signalExpr: t.Expression;
32
- hasKey: boolean;
33
- } | null {
34
- if (!t.isCallExpression(expr)) return null;
35
- const callee = expr.callee;
36
- if (!t.isMemberExpression(callee)) return null;
37
- const prop = callee.property;
38
- if (!t.isIdentifier(prop) || prop.name !== "map") return null;
39
-
40
- const obj = callee.object;
41
- if (!t.isExpression(obj)) return null;
42
- if (!containsSignal(obj, signals)) return null;
43
-
44
- if (expr.arguments.length !== 1) return null;
45
- const arrowFn = expr.arguments[0];
46
- if (!t.isArrowFunctionExpression(arrowFn)) return null;
47
- if (arrowFn.params.length < 1 || arrowFn.params.length > 2) return null;
48
- const itemParam = arrowFn.params[0];
49
- if (!t.isIdentifier(itemParam)) return null;
50
- const second = arrowFn.params[1];
51
- if (second !== undefined && !t.isIdentifier(second)) return null;
52
- const indexParam = second ?? null;
53
-
54
- const body = arrowFn.body;
55
- if (!t.isJSXElement(body)) return null;
56
-
57
- const keyAttr = body.openingElement.attributes.find(
58
- (a) =>
59
- t.isJSXAttribute(a) && t.isJSXIdentifier(a.name) && a.name.name === "key",
60
- );
61
- if (
62
- keyAttr &&
63
- t.isJSXAttribute(keyAttr) &&
64
- t.isJSXExpressionContainer(keyAttr.value)
65
- ) {
66
- return {
67
- callExpr: expr,
68
- keyExpr: keyAttr.value.expression as t.Expression,
69
- itemParam,
70
- indexParam,
71
- jsxBody: body,
72
- signalExpr: obj,
73
- hasKey: true,
74
- };
75
- }
76
-
77
- // Unkeyed map — still reconciled, keyed by position.
78
- return {
79
- callExpr: expr,
80
- keyExpr: null,
81
- itemParam,
82
- indexParam,
83
- jsxBody: body,
84
- signalExpr: obj,
85
- hasKey: false,
86
- };
87
- }
88
-
89
- /**
90
- * Generate keyed list code using reconcile().
91
- * In hydrate mode, uses hydrateKeyedList() to claim server-rendered nodes.
92
- */
93
- export function buildKeyedList(
94
- varName: string,
95
- keyed: NonNullable<ReturnType<typeof findKeyedMapExpr>>,
96
- statements: t.Statement[],
97
- genId: () => string,
98
- signals: Set<string>,
99
- processElement: ProcessElementFn,
100
- hash?: string,
101
- hydrate?: boolean,
102
- nodesVar?: string,
103
- parentVar?: string,
104
- ): void {
105
- const anchorVar = genId();
106
- const keyMapVar = genId();
107
-
108
- // Key extractor: the user's key={} expression wrapped in an arrow, or
109
- // index-keying for unkeyed maps. reconcile passes (item, index) so
110
- // (_item, _i) => _i works.
111
- const keyFn = t.arrowFunctionExpression(
112
- keyed.hasKey
113
- ? keyed.indexParam
114
- ? [keyed.itemParam, keyed.indexParam]
115
- : [keyed.itemParam]
116
- : [t.identifier("_item"), t.identifier("_i")],
117
- keyed.keyExpr ?? t.identifier("_i"),
118
- );
119
- // The row builder gets the index when the callback asked for it, and
120
- // reconcile then rebuilds rows that move (their body baked the old index).
121
- const rowParams = keyed.indexParam
122
- ? [keyed.itemParam, keyed.indexParam]
123
- : [keyed.itemParam];
124
- const usesIndex: t.Expression[] = keyed.indexParam
125
- ? [t.booleanLiteral(true)]
126
- : [];
127
-
128
- // Inside a row, the item is an element of a $state array, which makes it a
129
- // reactive proxy: `item.done` must update the row when it changes, and
130
- // bind:checked={item.done} must write back to it. Treating the item param
131
- // as a signal gives its reads effects; a primitive item costs one effect
132
- // that never re-runs.
133
- const rowSignals = new Set(signals);
134
- rowSignals.add(keyed.itemParam.name);
135
-
136
- // Strip key prop from JSX before processing.
137
- // In SSR mode, the Babel plugin already converted key → data-key.
138
- // In DOM/hydrate mode, we don't need either.
139
- keyed.jsxBody.openingElement.attributes =
140
- keyed.jsxBody.openingElement.attributes.filter(
141
- (a) =>
142
- !(
143
- t.isJSXAttribute(a) &&
144
- t.isJSXIdentifier(a.name) &&
145
- (a.name.name === "key" || a.name.name === "data-key")
146
- ),
147
- );
148
-
149
- if (hydrate) {
150
- // ─── Hydration path: use hydrateKeyedList() ───
151
- // Strip key prop from JSX before processing
152
- keyed.jsxBody.openingElement.attributes =
153
- keyed.jsxBody.openingElement.attributes.filter(
154
- (a) =>
155
- !(
156
- t.isJSXAttribute(a) &&
157
- t.isJSXIdentifier(a.name) &&
158
- a.name.name === "key"
159
- ),
160
- );
161
-
162
- // Process the JSX element to get createNode body
163
- const createNodeStmts: t.Statement[] = [];
164
- const jsxVar = processElement(
165
- keyed.jsxBody,
166
- createNodeStmts,
167
- genId,
168
- rowSignals,
169
- hash,
170
- hydrate,
171
- nodesVar,
172
- );
173
-
174
- // const { anchor, keyMap } = hydrateKeyedList(__nodes, signal, keyFn, createNode, parent)
175
- const resultVar = genId();
176
- const hydrateArgs: t.Expression[] = [
177
- t.identifier(nodesVar ?? "__nodes"),
178
- keyed.signalExpr,
179
- keyFn,
180
- t.arrowFunctionExpression(
181
- rowParams,
182
- t.blockStatement([
183
- ...createNodeStmts,
184
- t.returnStatement(t.identifier(jsxVar)),
185
- ]),
186
- ),
187
- ];
188
- if (hydrate && parentVar) hydrateArgs.push(t.identifier(parentVar));
189
- else if (usesIndex.length) hydrateArgs.push(t.identifier("undefined"));
190
- hydrateArgs.push(...usesIndex);
191
- statements.push(
192
- t.variableDeclaration("const", [
193
- t.variableDeclarator(
194
- t.identifier(resultVar),
195
- t.callExpression(t.identifier("hydrateKeyedList"), hydrateArgs),
196
- ),
197
- ]),
198
- );
199
-
200
- // const anchor = result.anchor
201
- statements.push(
202
- t.variableDeclaration("const", [
203
- t.variableDeclarator(
204
- t.identifier(anchorVar),
205
- t.memberExpression(t.identifier(resultVar), t.identifier("anchor")),
206
- ),
207
- ]),
208
- );
209
-
210
- // const keyMap = result.keyMap
211
- statements.push(
212
- t.variableDeclaration("const", [
213
- t.variableDeclarator(
214
- t.identifier(keyMapVar),
215
- t.memberExpression(t.identifier(resultVar), t.identifier("keyMap")),
216
- ),
217
- ]),
218
- );
219
-
220
- // createEffect(() => reconcile(anchor, keyMap, signal, keyFn, createNode))
221
- statements.push(
222
- t.expressionStatement(
223
- t.callExpression(t.identifier("createEffect"), [
224
- t.arrowFunctionExpression(
225
- [],
226
- t.blockStatement([
227
- t.expressionStatement(
228
- t.callExpression(t.identifier("reconcile"), [
229
- t.identifier(anchorVar),
230
- t.identifier(keyMapVar),
231
- keyed.signalExpr,
232
- keyFn,
233
- t.arrowFunctionExpression(
234
- rowParams,
235
- t.blockStatement([
236
- ...createNodeStmts,
237
- t.returnStatement(t.identifier(jsxVar)),
238
- ]),
239
- ),
240
- ...usesIndex,
241
- ]),
242
- ),
243
- ]),
244
- ),
245
- ]),
246
- ),
247
- );
248
- return;
249
- }
250
-
251
- // ─── DOM path (existing code) ───
252
-
253
- // const _anchor = document.createComment('')
254
- statements.push(
255
- t.variableDeclaration("const", [
256
- t.variableDeclarator(
257
- t.identifier(anchorVar),
258
- t.callExpression(
259
- t.memberExpression(
260
- t.identifier("document"),
261
- t.identifier("createComment"),
262
- ),
263
- [t.stringLiteral("")],
264
- ),
265
- ),
266
- ]),
267
- );
268
-
269
- // parent.append(_anchor)
270
- statements.push(
271
- t.expressionStatement(
272
- t.callExpression(
273
- t.memberExpression(t.identifier(varName), t.identifier("append")),
274
- [t.identifier(anchorVar)],
275
- ),
276
- ),
277
- );
278
-
279
- // const _keyMap = new Map()
280
- statements.push(
281
- t.variableDeclaration("const", [
282
- t.variableDeclarator(
283
- t.identifier(keyMapVar),
284
- t.newExpression(t.identifier("Map"), []),
285
- ),
286
- ]),
287
- );
288
-
289
- // Strip key prop from JSX before processing
290
- keyed.jsxBody.openingElement.attributes =
291
- keyed.jsxBody.openingElement.attributes.filter(
292
- (a) =>
293
- !(
294
- t.isJSXAttribute(a) &&
295
- t.isJSXIdentifier(a.name) &&
296
- a.name.name === "key"
297
- ),
298
- );
299
-
300
- // Process the JSX element to get createNode body
301
- const createNodeStmts: t.Statement[] = [];
302
- const jsxVar = processElement(
303
- keyed.jsxBody,
304
- createNodeStmts,
305
- genId,
306
- rowSignals,
307
- hash,
308
- );
309
-
310
- // createEffect(() => reconcile(...))
311
- // In DOM mode, use raw key expression. Keys are compared by value.
312
- statements.push(
313
- t.expressionStatement(
314
- t.callExpression(t.identifier("createEffect"), [
315
- t.arrowFunctionExpression(
316
- [],
317
- t.blockStatement([
318
- t.expressionStatement(
319
- t.callExpression(t.identifier("reconcile"), [
320
- t.identifier(anchorVar),
321
- t.identifier(keyMapVar),
322
- keyed.signalExpr,
323
- keyFn,
324
- t.arrowFunctionExpression(
325
- rowParams,
326
- t.blockStatement([
327
- ...createNodeStmts,
328
- t.returnStatement(t.identifier(jsxVar)),
329
- ]),
330
- ),
331
- ...usesIndex,
332
- ]),
333
- ),
334
- ]),
335
- ),
336
- ]),
337
- ),
338
- );
339
- }
1
+ import { types as t } from "@babel/core";
2
+ import { containsSignal } from "./utils";
3
+
4
+ export type ProcessElementFn = (
5
+ node: t.JSXElement,
6
+ statements: t.Statement[],
7
+ genId: () => string,
8
+ signals: Set<string>,
9
+ hash?: string,
10
+ hydrate?: boolean,
11
+ nodesVar?: string,
12
+ ) => string;
13
+
14
+ /**
15
+ * Detect pattern: signal.map(item => <Tag key={expr} />) — or, since unkeyed
16
+ * maps are also reconciled (index-keyed), signal.map(item => <Tag />). The
17
+ * callback may take the index too: signal.map((item, i) => <Tag />).
18
+ * Returns info needed to generate keyed list code, or null.
19
+ * `hasKey` is false for the unkeyed form; buildKeyedList then keys by index.
20
+ */
21
+ export function findKeyedMapExpr(
22
+ expr: t.Expression,
23
+ signals: Set<string>,
24
+ ): {
25
+ callExpr: t.CallExpression;
26
+ keyExpr: t.Expression | null;
27
+ itemParam: t.Identifier;
28
+ /** `i` in `(item, i) => …`, or null when the callback takes only the item. */
29
+ indexParam: t.Identifier | null;
30
+ jsxBody: t.JSXElement;
31
+ signalExpr: t.Expression;
32
+ hasKey: boolean;
33
+ } | null {
34
+ if (!t.isCallExpression(expr)) return null;
35
+ const callee = expr.callee;
36
+ if (!t.isMemberExpression(callee)) return null;
37
+ const prop = callee.property;
38
+ if (!t.isIdentifier(prop) || prop.name !== "map") return null;
39
+
40
+ const obj = callee.object;
41
+ if (!t.isExpression(obj)) return null;
42
+ if (!containsSignal(obj, signals)) return null;
43
+
44
+ if (expr.arguments.length !== 1) return null;
45
+ const arrowFn = expr.arguments[0];
46
+ if (!t.isArrowFunctionExpression(arrowFn)) return null;
47
+ if (arrowFn.params.length < 1 || arrowFn.params.length > 2) return null;
48
+ const itemParam = arrowFn.params[0];
49
+ if (!t.isIdentifier(itemParam)) return null;
50
+ const second = arrowFn.params[1];
51
+ if (second !== undefined && !t.isIdentifier(second)) return null;
52
+ const indexParam = second ?? null;
53
+
54
+ const body = arrowFn.body;
55
+ if (!t.isJSXElement(body)) return null;
56
+
57
+ const keyAttr = body.openingElement.attributes.find(
58
+ (a) =>
59
+ t.isJSXAttribute(a) && t.isJSXIdentifier(a.name) && a.name.name === "key",
60
+ );
61
+ if (
62
+ keyAttr &&
63
+ t.isJSXAttribute(keyAttr) &&
64
+ t.isJSXExpressionContainer(keyAttr.value)
65
+ ) {
66
+ return {
67
+ callExpr: expr,
68
+ keyExpr: keyAttr.value.expression as t.Expression,
69
+ itemParam,
70
+ indexParam,
71
+ jsxBody: body,
72
+ signalExpr: obj,
73
+ hasKey: true,
74
+ };
75
+ }
76
+
77
+ // Unkeyed map — still reconciled, keyed by position.
78
+ return {
79
+ callExpr: expr,
80
+ keyExpr: null,
81
+ itemParam,
82
+ indexParam,
83
+ jsxBody: body,
84
+ signalExpr: obj,
85
+ hasKey: false,
86
+ };
87
+ }
88
+
89
+ /**
90
+ * Generate keyed list code using reconcile().
91
+ * In hydrate mode, uses hydrateKeyedList() to claim server-rendered nodes.
92
+ */
93
+ export function buildKeyedList(
94
+ varName: string,
95
+ keyed: NonNullable<ReturnType<typeof findKeyedMapExpr>>,
96
+ statements: t.Statement[],
97
+ genId: () => string,
98
+ signals: Set<string>,
99
+ processElement: ProcessElementFn,
100
+ hash?: string,
101
+ hydrate?: boolean,
102
+ nodesVar?: string,
103
+ parentVar?: string,
104
+ ): void {
105
+ const anchorVar = genId();
106
+ const keyMapVar = genId();
107
+
108
+ // Key extractor: the user's key={} expression wrapped in an arrow, or
109
+ // index-keying for unkeyed maps. reconcile passes (item, index) so
110
+ // (_item, _i) => _i works.
111
+ const keyFn = t.arrowFunctionExpression(
112
+ keyed.hasKey
113
+ ? keyed.indexParam
114
+ ? [keyed.itemParam, keyed.indexParam]
115
+ : [keyed.itemParam]
116
+ : [t.identifier("_item"), t.identifier("_i")],
117
+ keyed.keyExpr ?? t.identifier("_i"),
118
+ );
119
+ // The row builder gets the index when the callback asked for it, and
120
+ // reconcile then rebuilds rows that move (their body baked the old index).
121
+ const rowParams = keyed.indexParam
122
+ ? [keyed.itemParam, keyed.indexParam]
123
+ : [keyed.itemParam];
124
+ const usesIndex: t.Expression[] = keyed.indexParam
125
+ ? [t.booleanLiteral(true)]
126
+ : [];
127
+
128
+ // Inside a row, the item is an element of a $state array, which makes it a
129
+ // reactive proxy: `item.done` must update the row when it changes, and
130
+ // bind:checked={item.done} must write back to it. Treating the item param
131
+ // as a signal gives its reads effects; a primitive item costs one effect
132
+ // that never re-runs.
133
+ const rowSignals = new Set(signals);
134
+ rowSignals.add(keyed.itemParam.name);
135
+
136
+ // Strip key prop from JSX before processing.
137
+ // In SSR mode, the Babel plugin already converted key → data-key.
138
+ // In DOM/hydrate mode, we don't need either.
139
+ keyed.jsxBody.openingElement.attributes =
140
+ keyed.jsxBody.openingElement.attributes.filter(
141
+ (a) =>
142
+ !(
143
+ t.isJSXAttribute(a) &&
144
+ t.isJSXIdentifier(a.name) &&
145
+ (a.name.name === "key" || a.name.name === "data-key")
146
+ ),
147
+ );
148
+
149
+ if (hydrate) {
150
+ // ─── Hydration path: use hydrateKeyedList() ───
151
+ // Strip key prop from JSX before processing
152
+ keyed.jsxBody.openingElement.attributes =
153
+ keyed.jsxBody.openingElement.attributes.filter(
154
+ (a) =>
155
+ !(
156
+ t.isJSXAttribute(a) &&
157
+ t.isJSXIdentifier(a.name) &&
158
+ a.name.name === "key"
159
+ ),
160
+ );
161
+
162
+ // Process the JSX element to get createNode body
163
+ const createNodeStmts: t.Statement[] = [];
164
+ const jsxVar = processElement(
165
+ keyed.jsxBody,
166
+ createNodeStmts,
167
+ genId,
168
+ rowSignals,
169
+ hash,
170
+ hydrate,
171
+ nodesVar,
172
+ );
173
+
174
+ // const { anchor, keyMap } = hydrateKeyedList(__nodes, signal, keyFn, createNode, parent)
175
+ const resultVar = genId();
176
+ const hydrateArgs: t.Expression[] = [
177
+ t.identifier(nodesVar ?? "__nodes"),
178
+ keyed.signalExpr,
179
+ keyFn,
180
+ t.arrowFunctionExpression(
181
+ rowParams,
182
+ t.blockStatement([
183
+ ...createNodeStmts,
184
+ t.returnStatement(t.identifier(jsxVar)),
185
+ ]),
186
+ ),
187
+ ];
188
+ if (hydrate && parentVar) hydrateArgs.push(t.identifier(parentVar));
189
+ else if (usesIndex.length) hydrateArgs.push(t.identifier("undefined"));
190
+ hydrateArgs.push(...usesIndex);
191
+ statements.push(
192
+ t.variableDeclaration("const", [
193
+ t.variableDeclarator(
194
+ t.identifier(resultVar),
195
+ t.callExpression(t.identifier("hydrateKeyedList"), hydrateArgs),
196
+ ),
197
+ ]),
198
+ );
199
+
200
+ // const anchor = result.anchor
201
+ statements.push(
202
+ t.variableDeclaration("const", [
203
+ t.variableDeclarator(
204
+ t.identifier(anchorVar),
205
+ t.memberExpression(t.identifier(resultVar), t.identifier("anchor")),
206
+ ),
207
+ ]),
208
+ );
209
+
210
+ // const keyMap = result.keyMap
211
+ statements.push(
212
+ t.variableDeclaration("const", [
213
+ t.variableDeclarator(
214
+ t.identifier(keyMapVar),
215
+ t.memberExpression(t.identifier(resultVar), t.identifier("keyMap")),
216
+ ),
217
+ ]),
218
+ );
219
+
220
+ // createEffect(() => reconcile(anchor, keyMap, signal, keyFn, createNode))
221
+ statements.push(
222
+ t.expressionStatement(
223
+ t.callExpression(t.identifier("createEffect"), [
224
+ t.arrowFunctionExpression(
225
+ [],
226
+ t.blockStatement([
227
+ t.expressionStatement(
228
+ t.callExpression(t.identifier("reconcile"), [
229
+ t.identifier(anchorVar),
230
+ t.identifier(keyMapVar),
231
+ keyed.signalExpr,
232
+ keyFn,
233
+ t.arrowFunctionExpression(
234
+ rowParams,
235
+ t.blockStatement([
236
+ ...createNodeStmts,
237
+ t.returnStatement(t.identifier(jsxVar)),
238
+ ]),
239
+ ),
240
+ ...usesIndex,
241
+ ]),
242
+ ),
243
+ ]),
244
+ ),
245
+ ]),
246
+ ),
247
+ );
248
+ return;
249
+ }
250
+
251
+ // ─── DOM path (existing code) ───
252
+
253
+ // const _anchor = document.createComment('')
254
+ statements.push(
255
+ t.variableDeclaration("const", [
256
+ t.variableDeclarator(
257
+ t.identifier(anchorVar),
258
+ t.callExpression(
259
+ t.memberExpression(
260
+ t.identifier("document"),
261
+ t.identifier("createComment"),
262
+ ),
263
+ [t.stringLiteral("")],
264
+ ),
265
+ ),
266
+ ]),
267
+ );
268
+
269
+ // parent.append(_anchor)
270
+ statements.push(
271
+ t.expressionStatement(
272
+ t.callExpression(
273
+ t.memberExpression(t.identifier(varName), t.identifier("append")),
274
+ [t.identifier(anchorVar)],
275
+ ),
276
+ ),
277
+ );
278
+
279
+ // const _keyMap = new Map()
280
+ statements.push(
281
+ t.variableDeclaration("const", [
282
+ t.variableDeclarator(
283
+ t.identifier(keyMapVar),
284
+ t.newExpression(t.identifier("Map"), []),
285
+ ),
286
+ ]),
287
+ );
288
+
289
+ // Strip key prop from JSX before processing
290
+ keyed.jsxBody.openingElement.attributes =
291
+ keyed.jsxBody.openingElement.attributes.filter(
292
+ (a) =>
293
+ !(
294
+ t.isJSXAttribute(a) &&
295
+ t.isJSXIdentifier(a.name) &&
296
+ a.name.name === "key"
297
+ ),
298
+ );
299
+
300
+ // Process the JSX element to get createNode body
301
+ const createNodeStmts: t.Statement[] = [];
302
+ const jsxVar = processElement(
303
+ keyed.jsxBody,
304
+ createNodeStmts,
305
+ genId,
306
+ rowSignals,
307
+ hash,
308
+ );
309
+
310
+ // createEffect(() => reconcile(...))
311
+ // In DOM mode, use raw key expression. Keys are compared by value.
312
+ statements.push(
313
+ t.expressionStatement(
314
+ t.callExpression(t.identifier("createEffect"), [
315
+ t.arrowFunctionExpression(
316
+ [],
317
+ t.blockStatement([
318
+ t.expressionStatement(
319
+ t.callExpression(t.identifier("reconcile"), [
320
+ t.identifier(anchorVar),
321
+ t.identifier(keyMapVar),
322
+ keyed.signalExpr,
323
+ keyFn,
324
+ t.arrowFunctionExpression(
325
+ rowParams,
326
+ t.blockStatement([
327
+ ...createNodeStmts,
328
+ t.returnStatement(t.identifier(jsxVar)),
329
+ ]),
330
+ ),
331
+ ...usesIndex,
332
+ ]),
333
+ ),
334
+ ]),
335
+ ),
336
+ ]),
337
+ ),
338
+ );
339
+ }