@sigil-dev/compiler 0.9.21 → 0.9.22

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.
@@ -1,426 +1,426 @@
1
- import { types as t } from "@babel/core";
2
-
3
- /**
4
- * Mount dynamic (non-primitive, non-keyed) content using an anchor comment node.
5
- * Generates a mount function that handles arrays, Nodes, and primitive values,
6
- * plus a createEffect that diffs by removing previous nodes and re-mounting.
7
- * In hydrate mode, claims the comment from the pool instead of creating.
8
- */
9
- export function buildAnchorMount(
10
- varName: string,
11
- expr: t.Expression,
12
- statements: t.Statement[],
13
- genId: () => string,
14
- hydrate?: boolean,
15
- nodesVar?: string,
16
- parentVar?: string,
17
- ): void {
18
- const anchorVar = genId();
19
- const prevVar = genId();
20
- const mountFn = genId();
21
-
22
- if (hydrate) {
23
- // Claim opening <!--g--> delimiter as anchor from pool
24
- const args: t.Expression[] = [
25
- t.identifier(nodesVar ?? "__nodes"),
26
- t.stringLiteral("g"),
27
- ];
28
- if (parentVar) args.push(t.identifier(parentVar));
29
- statements.push(
30
- t.variableDeclaration("const", [
31
- t.variableDeclarator(
32
- t.identifier(anchorVar),
33
- t.callExpression(t.identifier("claimComment"), args),
34
- ),
35
- ]),
36
- );
37
- // Consume closing <!--/g--> delimiter from pool
38
- const closeArgs: t.Expression[] = [
39
- t.identifier(nodesVar ?? "__nodes"),
40
- t.stringLiteral("/g"),
41
- ];
42
- if (parentVar) closeArgs.push(t.identifier(parentVar));
43
- statements.push(
44
- t.expressionStatement(
45
- t.callExpression(t.identifier("claimComment"), closeArgs),
46
- ),
47
- );
48
- // Collect and remove SSR content between <!--g--> and <!--/g-->
49
- // so the effect doesn't duplicate it on first run.
50
- // Generates: let _prev = []; { let _n = anchor.nextSibling; while (_n) {
51
- // const _cur = _n; _n = _n.nextSibling;
52
- // if (_cur instanceof Comment && _cur.data === "/g") { _cur.remove(); break; }
53
- // _cur.remove(); _prev.push(_cur); } }
54
- const nextVar = genId();
55
- const curVar = genId();
56
- statements.push(
57
- t.variableDeclaration("let", [
58
- t.variableDeclarator(t.identifier(prevVar), t.arrayExpression([])),
59
- ]),
60
- );
61
- statements.push(
62
- t.blockStatement([
63
- // let _n = anchor.nextSibling
64
- t.variableDeclaration("let", [
65
- t.variableDeclarator(
66
- t.identifier(nextVar),
67
- t.memberExpression(
68
- t.identifier(anchorVar),
69
- t.identifier("nextSibling"),
70
- ),
71
- ),
72
- ]),
73
- // while (_n) { ... }
74
- t.whileStatement(
75
- t.identifier(nextVar),
76
- t.blockStatement([
77
- // const _cur = _n
78
- t.variableDeclaration("const", [
79
- t.variableDeclarator(t.identifier(curVar), t.identifier(nextVar)),
80
- ]),
81
- // _n = _n.nextSibling
82
- t.expressionStatement(
83
- t.assignmentExpression(
84
- "=",
85
- t.identifier(nextVar),
86
- t.memberExpression(
87
- t.identifier(curVar),
88
- t.identifier("nextSibling"),
89
- ),
90
- ),
91
- ),
92
- // if (_cur instanceof Comment && _cur.data === "/g") { _cur.remove(); break; }
93
- t.ifStatement(
94
- t.logicalExpression(
95
- "&&",
96
- t.binaryExpression(
97
- "instanceof",
98
- t.identifier(curVar),
99
- t.identifier("Comment"),
100
- ),
101
- t.binaryExpression(
102
- "===",
103
- t.memberExpression(
104
- t.identifier(curVar),
105
- t.identifier("data"),
106
- ),
107
- t.stringLiteral("/g"),
108
- ),
109
- ),
110
- t.blockStatement([
111
- t.expressionStatement(
112
- t.callExpression(
113
- t.memberExpression(
114
- t.identifier(curVar),
115
- t.identifier("remove"),
116
- ),
117
- [],
118
- ),
119
- ),
120
- t.breakStatement(),
121
- ]),
122
- ),
123
- // _cur.remove()
124
- t.expressionStatement(
125
- t.callExpression(
126
- t.memberExpression(
127
- t.identifier(curVar),
128
- t.identifier("remove"),
129
- ),
130
- [],
131
- ),
132
- ),
133
- // _prev.push(_cur)
134
- t.expressionStatement(
135
- t.callExpression(
136
- t.memberExpression(t.identifier(prevVar), t.identifier("push")),
137
- [t.identifier(curVar)],
138
- ),
139
- ),
140
- ]),
141
- ),
142
- ]),
143
- );
144
- } else {
145
- // const _anchor = document.createComment('')
146
- statements.push(
147
- t.variableDeclaration("const", [
148
- t.variableDeclarator(
149
- t.identifier(anchorVar),
150
- t.callExpression(
151
- t.memberExpression(
152
- t.identifier("document"),
153
- t.identifier("createComment"),
154
- ),
155
- [t.stringLiteral("")],
156
- ),
157
- ),
158
- ]),
159
- );
160
-
161
- // parent.append(_anchor)
162
- statements.push(
163
- t.expressionStatement(
164
- t.callExpression(
165
- t.memberExpression(t.identifier(varName), t.identifier("append")),
166
- [t.identifier(anchorVar)],
167
- ),
168
- ),
169
- );
170
- }
171
-
172
- // let _prev = [] — already declared in hydrate block above
173
- if (!hydrate) {
174
- statements.push(
175
- t.variableDeclaration("let", [
176
- t.variableDeclarator(t.identifier(prevVar), t.arrayExpression([])),
177
- ]),
178
- );
179
- }
180
-
181
- // typeof x === "function" ? x() : x — hydrate-mode component children are
182
- // thunks, so a dynamic slot must call them instead of stringifying them.
183
- const unwrapThunk = (name: string): t.Expression =>
184
- t.conditionalExpression(
185
- t.binaryExpression(
186
- "===",
187
- t.unaryExpression("typeof", t.identifier(name)),
188
- t.stringLiteral("function"),
189
- ),
190
- t.callExpression(t.identifier(name), []),
191
- t.identifier(name),
192
- );
193
-
194
- // const _k = x.nodeType === 11 ? Array.from(x.childNodes) : [x]
195
- // A fragment empties into the page when inserted, and cannot be removed
196
- // itself: what must be removed later is the nodes it held.
197
- const keepNodes = (name: string): t.Statement =>
198
- t.variableDeclaration("const", [
199
- t.variableDeclarator(
200
- t.identifier("_k"),
201
- t.conditionalExpression(
202
- t.binaryExpression(
203
- "===",
204
- t.memberExpression(t.identifier(name), t.identifier("nodeType")),
205
- t.numericLiteral(11),
206
- ),
207
- t.callExpression(
208
- t.memberExpression(t.identifier("Array"), t.identifier("from")),
209
- [t.memberExpression(t.identifier(name), t.identifier("childNodes"))],
210
- ),
211
- t.arrayExpression([t.identifier(name)]),
212
- ),
213
- ),
214
- ]);
215
- const pushKept = (): t.Statement =>
216
- t.expressionStatement(
217
- t.callExpression(
218
- t.memberExpression(t.identifier("_nodes"), t.identifier("push")),
219
- [t.spreadElement(t.identifier("_k"))],
220
- ),
221
- );
222
-
223
- // function _mountFn(_v, _a) { ... }
224
- const mountBody = t.blockStatement([
225
- t.expressionStatement(
226
- t.assignmentExpression("=", t.identifier("_v"), unwrapThunk("_v")),
227
- ),
228
- t.variableDeclaration("const", [
229
- t.variableDeclarator(t.identifier("_nodes"), t.arrayExpression([])),
230
- ]),
231
- t.ifStatement(
232
- t.callExpression(
233
- t.memberExpression(t.identifier("Array"), t.identifier("isArray")),
234
- [t.identifier("_v")],
235
- ),
236
- t.blockStatement([
237
- t.forOfStatement(
238
- t.variableDeclaration("let", [
239
- t.variableDeclarator(t.identifier("_item")),
240
- ]),
241
- t.identifier("_v"),
242
- t.blockStatement([
243
- t.expressionStatement(
244
- t.assignmentExpression(
245
- "=",
246
- t.identifier("_item"),
247
- unwrapThunk("_item"),
248
- ),
249
- ),
250
- t.variableDeclaration("const", [
251
- t.variableDeclarator(
252
- t.identifier("_n"),
253
- t.conditionalExpression(
254
- t.binaryExpression(
255
- "instanceof",
256
- t.identifier("_item"),
257
- t.identifier("Node"),
258
- ),
259
- t.identifier("_item"),
260
- t.callExpression(
261
- t.memberExpression(
262
- t.identifier("document"),
263
- t.identifier("createTextNode"),
264
- ),
265
- [
266
- t.callExpression(t.identifier("String"), [
267
- t.logicalExpression(
268
- "??",
269
- t.identifier("_item"),
270
- t.stringLiteral(""),
271
- ),
272
- ]),
273
- ],
274
- ),
275
- ),
276
- ),
277
- ]),
278
- keepNodes("_n"),
279
- t.expressionStatement(
280
- t.callExpression(
281
- t.memberExpression(t.identifier("_a"), t.identifier("before")),
282
- [t.identifier("_n")],
283
- ),
284
- ),
285
- pushKept(),
286
- ]),
287
- ),
288
- ]),
289
- t.ifStatement(
290
- t.binaryExpression(
291
- "instanceof",
292
- t.identifier("_v"),
293
- t.identifier("Node"),
294
- ),
295
- t.blockStatement([
296
- keepNodes("_v"),
297
- t.expressionStatement(
298
- t.callExpression(
299
- t.memberExpression(t.identifier("_a"), t.identifier("before")),
300
- [t.identifier("_v")],
301
- ),
302
- ),
303
- pushKept(),
304
- ]),
305
- t.ifStatement(
306
- t.logicalExpression(
307
- "&&",
308
- t.logicalExpression(
309
- "&&",
310
- t.binaryExpression("!=", t.identifier("_v"), t.nullLiteral()),
311
- t.binaryExpression(
312
- "!==",
313
- t.identifier("_v"),
314
- t.booleanLiteral(false),
315
- ),
316
- ),
317
- t.binaryExpression(
318
- "!==",
319
- t.identifier("_v"),
320
- t.booleanLiteral(true),
321
- ),
322
- ),
323
- t.blockStatement([
324
- t.variableDeclaration("const", [
325
- t.variableDeclarator(
326
- t.identifier("_n"),
327
- t.callExpression(
328
- t.memberExpression(
329
- t.identifier("document"),
330
- t.identifier("createTextNode"),
331
- ),
332
- [
333
- t.callExpression(t.identifier("String"), [
334
- t.identifier("_v"),
335
- ]),
336
- ],
337
- ),
338
- ),
339
- ]),
340
- t.expressionStatement(
341
- t.callExpression(
342
- t.memberExpression(t.identifier("_a"), t.identifier("before")),
343
- [t.identifier("_n")],
344
- ),
345
- ),
346
- t.expressionStatement(
347
- t.callExpression(
348
- t.memberExpression(
349
- t.identifier("_nodes"),
350
- t.identifier("push"),
351
- ),
352
- [t.identifier("_n")],
353
- ),
354
- ),
355
- ]),
356
- ),
357
- ),
358
- ),
359
- t.returnStatement(t.identifier("_nodes")),
360
- ]);
361
-
362
- statements.push(
363
- t.functionDeclaration(
364
- t.identifier(mountFn),
365
- [t.identifier("_v"), t.identifier("_a")],
366
- mountBody,
367
- ),
368
- );
369
-
370
- const disposeVar = genId();
371
-
372
- statements.push(
373
- t.variableDeclaration("let", [
374
- t.variableDeclarator(t.identifier(disposeVar), t.nullLiteral()),
375
- ]),
376
- );
377
-
378
- statements.push(
379
- t.expressionStatement(
380
- t.callExpression(t.identifier("createEffect"), [
381
- t.arrowFunctionExpression(
382
- [],
383
- t.blockStatement([
384
- t.expressionStatement(
385
- t.optionalCallExpression(t.identifier(disposeVar), [], true),
386
- ),
387
- t.forOfStatement(
388
- t.variableDeclaration("const", [
389
- t.variableDeclarator(t.identifier("_n")),
390
- ]),
391
- t.identifier(prevVar),
392
- t.expressionStatement(
393
- t.callExpression(t.identifier("removeAnimated"), [
394
- t.identifier("_n"),
395
- ]),
396
- ),
397
- ),
398
- t.expressionStatement(
399
- t.assignmentExpression(
400
- "=",
401
- t.identifier(disposeVar),
402
- t.callExpression(t.identifier("withEffectScope"), [
403
- t.arrowFunctionExpression(
404
- [],
405
- t.blockStatement([
406
- t.expressionStatement(
407
- t.assignmentExpression(
408
- "=",
409
- t.identifier(prevVar),
410
- t.callExpression(t.identifier(mountFn), [
411
- expr,
412
- t.identifier(anchorVar),
413
- ]),
414
- ),
415
- ),
416
- ]),
417
- ),
418
- ]),
419
- ),
420
- ),
421
- ]),
422
- ),
423
- ]),
424
- ),
425
- );
426
- }
1
+ import { types as t } from "@babel/core";
2
+
3
+ /**
4
+ * Mount dynamic (non-primitive, non-keyed) content using an anchor comment node.
5
+ * Generates a mount function that handles arrays, Nodes, and primitive values,
6
+ * plus a createEffect that diffs by removing previous nodes and re-mounting.
7
+ * In hydrate mode, claims the comment from the pool instead of creating.
8
+ */
9
+ export function buildAnchorMount(
10
+ varName: string,
11
+ expr: t.Expression,
12
+ statements: t.Statement[],
13
+ genId: () => string,
14
+ hydrate?: boolean,
15
+ nodesVar?: string,
16
+ parentVar?: string,
17
+ ): void {
18
+ const anchorVar = genId();
19
+ const prevVar = genId();
20
+ const mountFn = genId();
21
+
22
+ if (hydrate) {
23
+ // Claim opening <!--g--> delimiter as anchor from pool
24
+ const args: t.Expression[] = [
25
+ t.identifier(nodesVar ?? "__nodes"),
26
+ t.stringLiteral("g"),
27
+ ];
28
+ if (parentVar) args.push(t.identifier(parentVar));
29
+ statements.push(
30
+ t.variableDeclaration("const", [
31
+ t.variableDeclarator(
32
+ t.identifier(anchorVar),
33
+ t.callExpression(t.identifier("claimComment"), args),
34
+ ),
35
+ ]),
36
+ );
37
+ // Consume closing <!--/g--> delimiter from pool
38
+ const closeArgs: t.Expression[] = [
39
+ t.identifier(nodesVar ?? "__nodes"),
40
+ t.stringLiteral("/g"),
41
+ ];
42
+ if (parentVar) closeArgs.push(t.identifier(parentVar));
43
+ statements.push(
44
+ t.expressionStatement(
45
+ t.callExpression(t.identifier("claimComment"), closeArgs),
46
+ ),
47
+ );
48
+ // Collect and remove SSR content between <!--g--> and <!--/g-->
49
+ // so the effect doesn't duplicate it on first run.
50
+ // Generates: let _prev = []; { let _n = anchor.nextSibling; while (_n) {
51
+ // const _cur = _n; _n = _n.nextSibling;
52
+ // if (_cur instanceof Comment && _cur.data === "/g") { _cur.remove(); break; }
53
+ // _cur.remove(); _prev.push(_cur); } }
54
+ const nextVar = genId();
55
+ const curVar = genId();
56
+ statements.push(
57
+ t.variableDeclaration("let", [
58
+ t.variableDeclarator(t.identifier(prevVar), t.arrayExpression([])),
59
+ ]),
60
+ );
61
+ statements.push(
62
+ t.blockStatement([
63
+ // let _n = anchor.nextSibling
64
+ t.variableDeclaration("let", [
65
+ t.variableDeclarator(
66
+ t.identifier(nextVar),
67
+ t.memberExpression(
68
+ t.identifier(anchorVar),
69
+ t.identifier("nextSibling"),
70
+ ),
71
+ ),
72
+ ]),
73
+ // while (_n) { ... }
74
+ t.whileStatement(
75
+ t.identifier(nextVar),
76
+ t.blockStatement([
77
+ // const _cur = _n
78
+ t.variableDeclaration("const", [
79
+ t.variableDeclarator(t.identifier(curVar), t.identifier(nextVar)),
80
+ ]),
81
+ // _n = _n.nextSibling
82
+ t.expressionStatement(
83
+ t.assignmentExpression(
84
+ "=",
85
+ t.identifier(nextVar),
86
+ t.memberExpression(
87
+ t.identifier(curVar),
88
+ t.identifier("nextSibling"),
89
+ ),
90
+ ),
91
+ ),
92
+ // if (_cur instanceof Comment && _cur.data === "/g") { _cur.remove(); break; }
93
+ t.ifStatement(
94
+ t.logicalExpression(
95
+ "&&",
96
+ t.binaryExpression(
97
+ "instanceof",
98
+ t.identifier(curVar),
99
+ t.identifier("Comment"),
100
+ ),
101
+ t.binaryExpression(
102
+ "===",
103
+ t.memberExpression(
104
+ t.identifier(curVar),
105
+ t.identifier("data"),
106
+ ),
107
+ t.stringLiteral("/g"),
108
+ ),
109
+ ),
110
+ t.blockStatement([
111
+ t.expressionStatement(
112
+ t.callExpression(
113
+ t.memberExpression(
114
+ t.identifier(curVar),
115
+ t.identifier("remove"),
116
+ ),
117
+ [],
118
+ ),
119
+ ),
120
+ t.breakStatement(),
121
+ ]),
122
+ ),
123
+ // _cur.remove()
124
+ t.expressionStatement(
125
+ t.callExpression(
126
+ t.memberExpression(
127
+ t.identifier(curVar),
128
+ t.identifier("remove"),
129
+ ),
130
+ [],
131
+ ),
132
+ ),
133
+ // _prev.push(_cur)
134
+ t.expressionStatement(
135
+ t.callExpression(
136
+ t.memberExpression(t.identifier(prevVar), t.identifier("push")),
137
+ [t.identifier(curVar)],
138
+ ),
139
+ ),
140
+ ]),
141
+ ),
142
+ ]),
143
+ );
144
+ } else {
145
+ // const _anchor = document.createComment('')
146
+ statements.push(
147
+ t.variableDeclaration("const", [
148
+ t.variableDeclarator(
149
+ t.identifier(anchorVar),
150
+ t.callExpression(
151
+ t.memberExpression(
152
+ t.identifier("document"),
153
+ t.identifier("createComment"),
154
+ ),
155
+ [t.stringLiteral("")],
156
+ ),
157
+ ),
158
+ ]),
159
+ );
160
+
161
+ // parent.append(_anchor)
162
+ statements.push(
163
+ t.expressionStatement(
164
+ t.callExpression(
165
+ t.memberExpression(t.identifier(varName), t.identifier("append")),
166
+ [t.identifier(anchorVar)],
167
+ ),
168
+ ),
169
+ );
170
+ }
171
+
172
+ // let _prev = [] — already declared in hydrate block above
173
+ if (!hydrate) {
174
+ statements.push(
175
+ t.variableDeclaration("let", [
176
+ t.variableDeclarator(t.identifier(prevVar), t.arrayExpression([])),
177
+ ]),
178
+ );
179
+ }
180
+
181
+ // typeof x === "function" ? x() : x — hydrate-mode component children are
182
+ // thunks, so a dynamic slot must call them instead of stringifying them.
183
+ const unwrapThunk = (name: string): t.Expression =>
184
+ t.conditionalExpression(
185
+ t.binaryExpression(
186
+ "===",
187
+ t.unaryExpression("typeof", t.identifier(name)),
188
+ t.stringLiteral("function"),
189
+ ),
190
+ t.callExpression(t.identifier(name), []),
191
+ t.identifier(name),
192
+ );
193
+
194
+ // const _k = x.nodeType === 11 ? Array.from(x.childNodes) : [x]
195
+ // A fragment empties into the page when inserted, and cannot be removed
196
+ // itself: what must be removed later is the nodes it held.
197
+ const keepNodes = (name: string): t.Statement =>
198
+ t.variableDeclaration("const", [
199
+ t.variableDeclarator(
200
+ t.identifier("_k"),
201
+ t.conditionalExpression(
202
+ t.binaryExpression(
203
+ "===",
204
+ t.memberExpression(t.identifier(name), t.identifier("nodeType")),
205
+ t.numericLiteral(11),
206
+ ),
207
+ t.callExpression(
208
+ t.memberExpression(t.identifier("Array"), t.identifier("from")),
209
+ [t.memberExpression(t.identifier(name), t.identifier("childNodes"))],
210
+ ),
211
+ t.arrayExpression([t.identifier(name)]),
212
+ ),
213
+ ),
214
+ ]);
215
+ const pushKept = (): t.Statement =>
216
+ t.expressionStatement(
217
+ t.callExpression(
218
+ t.memberExpression(t.identifier("_nodes"), t.identifier("push")),
219
+ [t.spreadElement(t.identifier("_k"))],
220
+ ),
221
+ );
222
+
223
+ // function _mountFn(_v, _a) { ... }
224
+ const mountBody = t.blockStatement([
225
+ t.expressionStatement(
226
+ t.assignmentExpression("=", t.identifier("_v"), unwrapThunk("_v")),
227
+ ),
228
+ t.variableDeclaration("const", [
229
+ t.variableDeclarator(t.identifier("_nodes"), t.arrayExpression([])),
230
+ ]),
231
+ t.ifStatement(
232
+ t.callExpression(
233
+ t.memberExpression(t.identifier("Array"), t.identifier("isArray")),
234
+ [t.identifier("_v")],
235
+ ),
236
+ t.blockStatement([
237
+ t.forOfStatement(
238
+ t.variableDeclaration("let", [
239
+ t.variableDeclarator(t.identifier("_item")),
240
+ ]),
241
+ t.identifier("_v"),
242
+ t.blockStatement([
243
+ t.expressionStatement(
244
+ t.assignmentExpression(
245
+ "=",
246
+ t.identifier("_item"),
247
+ unwrapThunk("_item"),
248
+ ),
249
+ ),
250
+ t.variableDeclaration("const", [
251
+ t.variableDeclarator(
252
+ t.identifier("_n"),
253
+ t.conditionalExpression(
254
+ t.binaryExpression(
255
+ "instanceof",
256
+ t.identifier("_item"),
257
+ t.identifier("Node"),
258
+ ),
259
+ t.identifier("_item"),
260
+ t.callExpression(
261
+ t.memberExpression(
262
+ t.identifier("document"),
263
+ t.identifier("createTextNode"),
264
+ ),
265
+ [
266
+ t.callExpression(t.identifier("String"), [
267
+ t.logicalExpression(
268
+ "??",
269
+ t.identifier("_item"),
270
+ t.stringLiteral(""),
271
+ ),
272
+ ]),
273
+ ],
274
+ ),
275
+ ),
276
+ ),
277
+ ]),
278
+ keepNodes("_n"),
279
+ t.expressionStatement(
280
+ t.callExpression(
281
+ t.memberExpression(t.identifier("_a"), t.identifier("before")),
282
+ [t.identifier("_n")],
283
+ ),
284
+ ),
285
+ pushKept(),
286
+ ]),
287
+ ),
288
+ ]),
289
+ t.ifStatement(
290
+ t.binaryExpression(
291
+ "instanceof",
292
+ t.identifier("_v"),
293
+ t.identifier("Node"),
294
+ ),
295
+ t.blockStatement([
296
+ keepNodes("_v"),
297
+ t.expressionStatement(
298
+ t.callExpression(
299
+ t.memberExpression(t.identifier("_a"), t.identifier("before")),
300
+ [t.identifier("_v")],
301
+ ),
302
+ ),
303
+ pushKept(),
304
+ ]),
305
+ t.ifStatement(
306
+ t.logicalExpression(
307
+ "&&",
308
+ t.logicalExpression(
309
+ "&&",
310
+ t.binaryExpression("!=", t.identifier("_v"), t.nullLiteral()),
311
+ t.binaryExpression(
312
+ "!==",
313
+ t.identifier("_v"),
314
+ t.booleanLiteral(false),
315
+ ),
316
+ ),
317
+ t.binaryExpression(
318
+ "!==",
319
+ t.identifier("_v"),
320
+ t.booleanLiteral(true),
321
+ ),
322
+ ),
323
+ t.blockStatement([
324
+ t.variableDeclaration("const", [
325
+ t.variableDeclarator(
326
+ t.identifier("_n"),
327
+ t.callExpression(
328
+ t.memberExpression(
329
+ t.identifier("document"),
330
+ t.identifier("createTextNode"),
331
+ ),
332
+ [
333
+ t.callExpression(t.identifier("String"), [
334
+ t.identifier("_v"),
335
+ ]),
336
+ ],
337
+ ),
338
+ ),
339
+ ]),
340
+ t.expressionStatement(
341
+ t.callExpression(
342
+ t.memberExpression(t.identifier("_a"), t.identifier("before")),
343
+ [t.identifier("_n")],
344
+ ),
345
+ ),
346
+ t.expressionStatement(
347
+ t.callExpression(
348
+ t.memberExpression(
349
+ t.identifier("_nodes"),
350
+ t.identifier("push"),
351
+ ),
352
+ [t.identifier("_n")],
353
+ ),
354
+ ),
355
+ ]),
356
+ ),
357
+ ),
358
+ ),
359
+ t.returnStatement(t.identifier("_nodes")),
360
+ ]);
361
+
362
+ statements.push(
363
+ t.functionDeclaration(
364
+ t.identifier(mountFn),
365
+ [t.identifier("_v"), t.identifier("_a")],
366
+ mountBody,
367
+ ),
368
+ );
369
+
370
+ const disposeVar = genId();
371
+
372
+ statements.push(
373
+ t.variableDeclaration("let", [
374
+ t.variableDeclarator(t.identifier(disposeVar), t.nullLiteral()),
375
+ ]),
376
+ );
377
+
378
+ statements.push(
379
+ t.expressionStatement(
380
+ t.callExpression(t.identifier("createEffect"), [
381
+ t.arrowFunctionExpression(
382
+ [],
383
+ t.blockStatement([
384
+ t.expressionStatement(
385
+ t.optionalCallExpression(t.identifier(disposeVar), [], true),
386
+ ),
387
+ t.forOfStatement(
388
+ t.variableDeclaration("const", [
389
+ t.variableDeclarator(t.identifier("_n")),
390
+ ]),
391
+ t.identifier(prevVar),
392
+ t.expressionStatement(
393
+ t.callExpression(t.identifier("removeAnimated"), [
394
+ t.identifier("_n"),
395
+ ]),
396
+ ),
397
+ ),
398
+ t.expressionStatement(
399
+ t.assignmentExpression(
400
+ "=",
401
+ t.identifier(disposeVar),
402
+ t.callExpression(t.identifier("withEffectScope"), [
403
+ t.arrowFunctionExpression(
404
+ [],
405
+ t.blockStatement([
406
+ t.expressionStatement(
407
+ t.assignmentExpression(
408
+ "=",
409
+ t.identifier(prevVar),
410
+ t.callExpression(t.identifier(mountFn), [
411
+ expr,
412
+ t.identifier(anchorVar),
413
+ ]),
414
+ ),
415
+ ),
416
+ ]),
417
+ ),
418
+ ]),
419
+ ),
420
+ ),
421
+ ]),
422
+ ),
423
+ ]),
424
+ ),
425
+ );
426
+ }