@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.
- package/README.md +162 -162
- package/package.json +3 -2
- package/src/analysis/hydration.ts +899 -0
- package/src/babel/handlers/dom/state.ts +106 -106
- package/src/babel/index.ts +685 -667
- package/src/babel/jsx/anchor-mount.ts +426 -426
- package/src/babel/jsx/children.ts +116 -116
- package/src/babel/jsx/element.ts +1027 -960
- package/src/babel/jsx/fragment.ts +271 -271
- package/src/babel/jsx/keyed-list.ts +317 -317
- package/src/babel/jsx/ssr.ts +307 -297
- package/src/babel/jsx/utils.ts +355 -333
- package/src/babel/util/bind.ts +143 -143
- package/src/babel/util/compile-state.ts +5 -0
- package/src/babel/util/css.ts +208 -208
- package/src/babel/util/props.ts +256 -256
- package/src/babel/util/reactive-fns.ts +110 -0
- package/src/babel/util/static-assertion.ts +51 -0
- package/src/bun-plugin.ts +103 -103
- package/src/vite/index.ts +61 -61
- package/test/bun-plugin.test.ts +45 -45
- package/test/hydration-analysis.test.ts +133 -0
- package/test/hydration.test.ts +277 -277
- package/test/jsx.test.ts +254 -254
- package/test/reactive-helpers.test.ts +135 -0
- package/test/render-parity.test.ts +827 -827
- package/test/scoped-css.test.ts +166 -166
- package/test/ssr-boolean-attrs.test.ts +56 -56
- package/test/ssr-raw-text.test.ts +68 -68
- package/test/ssr.test.ts +130 -130
- package/test/static-assertion.test.ts +123 -0
- package/test/static-skip.test.ts +292 -0
- package/test/style-object.test.ts +36 -36
package/src/babel/jsx/element.ts
CHANGED
|
@@ -1,960 +1,1027 @@
|
|
|
1
|
-
import { types as t } from "@babel/core";
|
|
2
|
-
//@ts-expect-error Not our problem babel forgot tp export types.
|
|
3
|
-
import { generate } from "@babel/generator";
|
|
4
|
-
import {
|
|
5
|
-
handleGlobalComponent,
|
|
6
|
-
isGlobalComponent,
|
|
7
|
-
} from "../handlers/dom/globals";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
t.
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
statements.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
//
|
|
198
|
-
//
|
|
199
|
-
//
|
|
200
|
-
// the
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
//
|
|
247
|
-
//
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
),
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
t.identifier(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
t.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
t.
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
t.
|
|
783
|
-
|
|
784
|
-
t.
|
|
785
|
-
t.
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
)
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
if (hydrate) {
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
t.
|
|
945
|
-
t.
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
1
|
+
import { types as t } from "@babel/core";
|
|
2
|
+
//@ts-expect-error Not our problem babel forgot tp export types.
|
|
3
|
+
import { generate } from "@babel/generator";
|
|
4
|
+
import {
|
|
5
|
+
handleGlobalComponent,
|
|
6
|
+
isGlobalComponent,
|
|
7
|
+
} from "../handlers/dom/globals";
|
|
8
|
+
import { STATIC_USES } from "../../analysis/hydration.ts";
|
|
9
|
+
import { buildBind, buildProxyBind } from "../util/bind";
|
|
10
|
+
import { compileState } from "../util/compile-state.ts";
|
|
11
|
+
import { isPropRead } from "../util/props.ts";
|
|
12
|
+
import { buildAnchorMount } from "./anchor-mount";
|
|
13
|
+
import { collectChildren } from "./children";
|
|
14
|
+
import { processFragment } from "./fragment";
|
|
15
|
+
import { buildKeyedList, findKeyedMapExpr } from "./keyed-list";
|
|
16
|
+
import { buildTextNode } from "./text-node";
|
|
17
|
+
import {
|
|
18
|
+
ATTR_MAP,
|
|
19
|
+
buildHydrationScope,
|
|
20
|
+
containsSignal,
|
|
21
|
+
getCreateElement,
|
|
22
|
+
hasJSX,
|
|
23
|
+
isPrimitive,
|
|
24
|
+
jsxText,
|
|
25
|
+
} from "./utils";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Dashed names (data-*, aria-*, custom attributes) have no IDL property —
|
|
29
|
+
* `el["data-x"] = v` sets a bare JS property the DOM never reflects, so the
|
|
30
|
+
* attribute is invisible to selectors, getAttribute, and CSS. They must go
|
|
31
|
+
* through setAttribute.
|
|
32
|
+
*/
|
|
33
|
+
function isDashedAttr(attrName: string): boolean {
|
|
34
|
+
return attrName.includes("-");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function setAttrCall(
|
|
38
|
+
varName: string,
|
|
39
|
+
attrName: string,
|
|
40
|
+
value: t.Expression,
|
|
41
|
+
): t.CallExpression {
|
|
42
|
+
return t.callExpression(
|
|
43
|
+
t.memberExpression(t.identifier(varName), t.identifier("setAttribute")),
|
|
44
|
+
[t.stringLiteral(attrName), value],
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Route a prop write through the runtime setProp() helper. On HTML elements
|
|
50
|
+
* this is today's blind `el[name] = value`; on SVG-namespace elements it
|
|
51
|
+
* goes through setAttribute instead — IDL property assignment throws on real
|
|
52
|
+
* SVG elements (`svg.width = 15` hits a getter-only property), which crashed
|
|
53
|
+
* CSR renders the moment claim() started creating true-namespaced SVG.
|
|
54
|
+
*/
|
|
55
|
+
function setPropCall(
|
|
56
|
+
varName: string,
|
|
57
|
+
attrName: string,
|
|
58
|
+
value: t.Expression,
|
|
59
|
+
): t.CallExpression {
|
|
60
|
+
return t.callExpression(t.identifier("setProp"), [
|
|
61
|
+
t.identifier(varName),
|
|
62
|
+
t.stringLiteral(attrName),
|
|
63
|
+
value,
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function isClaimedCall(varName: string): t.CallExpression {
|
|
68
|
+
return t.callExpression(t.identifier("isClaimed"), [t.identifier(varName)]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function effect(body: t.Statement[]): t.ExpressionStatement {
|
|
72
|
+
return t.expressionStatement(
|
|
73
|
+
t.callExpression(t.identifier("createEffect"), [
|
|
74
|
+
t.arrowFunctionExpression([], t.blockStatement(body)),
|
|
75
|
+
]),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Emit fresh-element-only writes; hydration guards them with isClaimed(). */
|
|
80
|
+
function pushInit(
|
|
81
|
+
varName: string,
|
|
82
|
+
init: t.Statement[],
|
|
83
|
+
statements: t.Statement[],
|
|
84
|
+
hydrate?: boolean,
|
|
85
|
+
): void {
|
|
86
|
+
if (!init.length) return;
|
|
87
|
+
if (hydrate) {
|
|
88
|
+
statements.push(
|
|
89
|
+
t.ifStatement(
|
|
90
|
+
t.unaryExpression("!", isClaimedCall(varName)),
|
|
91
|
+
t.blockStatement(init),
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
} else {
|
|
95
|
+
statements.push(...init);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** A <script>'s children as one string expression, or null if it has none. */
|
|
100
|
+
function scriptText(node: t.JSXElement): t.Expression | null {
|
|
101
|
+
const parts: t.Expression[] = [];
|
|
102
|
+
for (const child of node.children) {
|
|
103
|
+
if (t.isJSXText(child)) {
|
|
104
|
+
const text = jsxText(child);
|
|
105
|
+
if (text !== null) parts.push(t.stringLiteral(text));
|
|
106
|
+
} else if (
|
|
107
|
+
t.isJSXExpressionContainer(child) &&
|
|
108
|
+
!t.isJSXEmptyExpression(child.expression)
|
|
109
|
+
) {
|
|
110
|
+
parts.push(
|
|
111
|
+
t.logicalExpression("??", child.expression, t.stringLiteral("")),
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (!parts.length) return null;
|
|
116
|
+
return parts.reduce(
|
|
117
|
+
(a, b) => t.binaryExpression("+", a, b),
|
|
118
|
+
t.stringLiteral(""),
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Build an object property key (identifier for valid names, string literal for dashed).
|
|
124
|
+
*/
|
|
125
|
+
function attrKey(attrName: string): t.Identifier | t.StringLiteral {
|
|
126
|
+
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(attrName)) {
|
|
127
|
+
return t.identifier(attrName);
|
|
128
|
+
}
|
|
129
|
+
return t.stringLiteral(attrName);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Add classList.add(hash) statement for scoped CSS.
|
|
134
|
+
*/
|
|
135
|
+
function addScopedClass(
|
|
136
|
+
varName: string,
|
|
137
|
+
hash: string,
|
|
138
|
+
statements: t.Statement[],
|
|
139
|
+
): void {
|
|
140
|
+
statements.push(
|
|
141
|
+
t.expressionStatement(
|
|
142
|
+
t.callExpression(
|
|
143
|
+
t.memberExpression(
|
|
144
|
+
t.memberExpression(t.identifier(varName), t.identifier("classList")),
|
|
145
|
+
t.identifier("add"),
|
|
146
|
+
),
|
|
147
|
+
[t.stringLiteral(hash)],
|
|
148
|
+
),
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function processElement(
|
|
154
|
+
node: t.JSXElement,
|
|
155
|
+
statements: t.Statement[],
|
|
156
|
+
genId: () => string,
|
|
157
|
+
signals: Set<string>,
|
|
158
|
+
hash?: string,
|
|
159
|
+
hydrate?: boolean,
|
|
160
|
+
nodesVar?: string,
|
|
161
|
+
parentVar?: string,
|
|
162
|
+
): string {
|
|
163
|
+
const varName = genId();
|
|
164
|
+
const tag = (node.openingElement.name as t.JSXIdentifier).name;
|
|
165
|
+
const isComponent = /^[A-Z]/.test(tag);
|
|
166
|
+
|
|
167
|
+
if (isComponent) {
|
|
168
|
+
// Global components: Window, Document, Body
|
|
169
|
+
if (isGlobalComponent(tag)) {
|
|
170
|
+
return handleGlobalComponent(tag, node, statements, genId);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Component: call the function with a props object
|
|
174
|
+
const propsObj = t.objectExpression([]);
|
|
175
|
+
|
|
176
|
+
// Add attributes to props (including spread)
|
|
177
|
+
for (const attr of node.openingElement.attributes) {
|
|
178
|
+
if (t.isJSXSpreadAttribute(attr)) {
|
|
179
|
+
// {…obj} — spread into props
|
|
180
|
+
propsObj.properties.push(t.spreadElement(attr.argument));
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (!t.isJSXAttribute(attr)) continue;
|
|
184
|
+
const attrName = (attr.name as t.JSXIdentifier).name;
|
|
185
|
+
|
|
186
|
+
if (attr.value === null) {
|
|
187
|
+
// <Comp disabled /> → { disabled: true }
|
|
188
|
+
propsObj.properties.push(
|
|
189
|
+
t.objectProperty(attrKey(attrName), t.booleanLiteral(true)),
|
|
190
|
+
);
|
|
191
|
+
} else if (t.isStringLiteral(attr.value)) {
|
|
192
|
+
propsObj.properties.push(
|
|
193
|
+
t.objectProperty(attrKey(attrName), attr.value),
|
|
194
|
+
);
|
|
195
|
+
} else if (t.isJSXExpressionContainer(attr.value)) {
|
|
196
|
+
const expr = attr.value.expression as t.Expression;
|
|
197
|
+
// JSX in a prop (icon={<Icon />}, actions={<>…</>}) belongs
|
|
198
|
+
// wherever the component puts it, inside its own root. Built
|
|
199
|
+
// now, during hydration, it would claim from the caller's pool
|
|
200
|
+
// and could take the component's root element. Defer it like
|
|
201
|
+
// children: the component's {prop} slot runs the thunk against
|
|
202
|
+
// the right nodes.
|
|
203
|
+
if (hydrate && hasJSX(expr)) {
|
|
204
|
+
propsObj.properties.push(
|
|
205
|
+
t.objectProperty(
|
|
206
|
+
attrKey(attrName),
|
|
207
|
+
t.arrowFunctionExpression([], expr),
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
} else if (containsSignal(expr, signals)) {
|
|
211
|
+
// a prop that reads state is passed as a getter, so the
|
|
212
|
+
// component reads the current value wherever it uses it
|
|
213
|
+
propsObj.properties.push(
|
|
214
|
+
t.objectMethod(
|
|
215
|
+
"get",
|
|
216
|
+
attrKey(attrName),
|
|
217
|
+
[],
|
|
218
|
+
t.blockStatement([t.returnStatement(expr)]),
|
|
219
|
+
),
|
|
220
|
+
);
|
|
221
|
+
} else {
|
|
222
|
+
propsObj.properties.push(t.objectProperty(attrKey(attrName), expr));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Add children to props
|
|
228
|
+
const childrenExpr = collectChildren(
|
|
229
|
+
node,
|
|
230
|
+
statements,
|
|
231
|
+
genId,
|
|
232
|
+
signals,
|
|
233
|
+
hash,
|
|
234
|
+
hydrate,
|
|
235
|
+
nodesVar,
|
|
236
|
+
);
|
|
237
|
+
if (childrenExpr) {
|
|
238
|
+
propsObj.properties.push(
|
|
239
|
+
t.objectProperty(t.identifier("children"), childrenExpr),
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const componentCall = t.callExpression(t.identifier(tag), [propsObj]);
|
|
244
|
+
|
|
245
|
+
if (hydrate && nodesVar && STATIC_USES.has(node)) {
|
|
246
|
+
// The analysis proved this use produces only HTML, and the server
|
|
247
|
+
// fenced it in <!--s-->…<!--/s-->. Cut that run out of the pool and
|
|
248
|
+
// never call the component: no claiming, no effects, no listeners.
|
|
249
|
+
// With nothing to skip (a client render, an empty pool) skipStatic
|
|
250
|
+
// returns null and the component runs as it always did.
|
|
251
|
+
statements.push(
|
|
252
|
+
t.variableDeclaration("let", [
|
|
253
|
+
t.variableDeclarator(
|
|
254
|
+
t.identifier(varName),
|
|
255
|
+
t.callExpression(t.identifier("skipStatic"), [t.identifier(nodesVar)]),
|
|
256
|
+
),
|
|
257
|
+
]),
|
|
258
|
+
);
|
|
259
|
+
const render: t.Statement[] = [
|
|
260
|
+
t.expressionStatement(
|
|
261
|
+
t.callExpression(t.identifier("pushHydrationNodes"), [t.identifier(nodesVar)]),
|
|
262
|
+
),
|
|
263
|
+
t.expressionStatement(
|
|
264
|
+
t.assignmentExpression("=", t.identifier(varName), componentCall),
|
|
265
|
+
),
|
|
266
|
+
t.expressionStatement(
|
|
267
|
+
t.callExpression(t.identifier("popHydrationNodes"), []),
|
|
268
|
+
),
|
|
269
|
+
];
|
|
270
|
+
if (parentVar) {
|
|
271
|
+
render.push(
|
|
272
|
+
t.ifStatement(
|
|
273
|
+
t.binaryExpression(
|
|
274
|
+
"===",
|
|
275
|
+
t.memberExpression(t.identifier(nodesVar), t.identifier("length")),
|
|
276
|
+
t.numericLiteral(0),
|
|
277
|
+
),
|
|
278
|
+
t.expressionStatement(
|
|
279
|
+
t.callExpression(t.identifier("insert"), [
|
|
280
|
+
t.identifier(parentVar),
|
|
281
|
+
t.identifier(varName),
|
|
282
|
+
]),
|
|
283
|
+
),
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
// Dev: render the skipped component once, detached, and throw if it was
|
|
288
|
+
// not really static. The analysis is conservative, and this is how a
|
|
289
|
+
// mistake in it shows up before it reaches production.
|
|
290
|
+
const probe = compileState.dev
|
|
291
|
+
? t.blockStatement([
|
|
292
|
+
t.expressionStatement(
|
|
293
|
+
t.callExpression(t.identifier("probeStatic"), [
|
|
294
|
+
t.stringLiteral(tag),
|
|
295
|
+
t.arrowFunctionExpression([], t.cloneNode(componentCall, true)),
|
|
296
|
+
]),
|
|
297
|
+
),
|
|
298
|
+
])
|
|
299
|
+
: null;
|
|
300
|
+
statements.push(
|
|
301
|
+
t.ifStatement(
|
|
302
|
+
t.unaryExpression("!", t.identifier(varName)),
|
|
303
|
+
t.blockStatement(render),
|
|
304
|
+
probe,
|
|
305
|
+
),
|
|
306
|
+
);
|
|
307
|
+
return varName;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (hydrate && nodesVar) {
|
|
311
|
+
// Push the parent's child pool before calling the component so that
|
|
312
|
+
// getHydrationNodes() inside the component returns the right scope.
|
|
313
|
+
// In SSR hydration the component claims its root node from that pool
|
|
314
|
+
// (it's already in the DOM). In empty-pool / SPA mode the component
|
|
315
|
+
// creates a fresh node, so we explicitly insert it when the pool is empty.
|
|
316
|
+
statements.push(
|
|
317
|
+
t.expressionStatement(
|
|
318
|
+
t.callExpression(t.identifier("pushHydrationNodes"), [
|
|
319
|
+
t.identifier(nodesVar),
|
|
320
|
+
]),
|
|
321
|
+
),
|
|
322
|
+
);
|
|
323
|
+
statements.push(
|
|
324
|
+
t.variableDeclaration("const", [
|
|
325
|
+
t.variableDeclarator(t.identifier(varName), componentCall),
|
|
326
|
+
]),
|
|
327
|
+
);
|
|
328
|
+
statements.push(
|
|
329
|
+
t.expressionStatement(
|
|
330
|
+
t.callExpression(t.identifier("popHydrationNodes"), []),
|
|
331
|
+
),
|
|
332
|
+
);
|
|
333
|
+
if (parentVar) {
|
|
334
|
+
// Insert only when the pool was empty (fresh DOM); if the pool had
|
|
335
|
+
// nodes the component already claimed its SSR element (already in DOM).
|
|
336
|
+
statements.push(
|
|
337
|
+
t.ifStatement(
|
|
338
|
+
t.binaryExpression(
|
|
339
|
+
"===",
|
|
340
|
+
t.memberExpression(
|
|
341
|
+
t.identifier(nodesVar),
|
|
342
|
+
t.identifier("length"),
|
|
343
|
+
),
|
|
344
|
+
t.numericLiteral(0),
|
|
345
|
+
),
|
|
346
|
+
t.expressionStatement(
|
|
347
|
+
t.callExpression(t.identifier("insert"), [
|
|
348
|
+
t.identifier(parentVar),
|
|
349
|
+
t.identifier(varName),
|
|
350
|
+
]),
|
|
351
|
+
),
|
|
352
|
+
),
|
|
353
|
+
);
|
|
354
|
+
}
|
|
355
|
+
} else {
|
|
356
|
+
statements.push(
|
|
357
|
+
t.variableDeclaration("const", [
|
|
358
|
+
t.variableDeclarator(t.identifier(varName), componentCall),
|
|
359
|
+
]),
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return varName;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// Native element: claim (hydrate) or create (dom)
|
|
367
|
+
const currentNodesVar = nodesVar ?? "__nodes";
|
|
368
|
+
statements.push(
|
|
369
|
+
t.variableDeclaration("const", [
|
|
370
|
+
t.variableDeclarator(
|
|
371
|
+
t.identifier(varName),
|
|
372
|
+
getCreateElement(
|
|
373
|
+
tag,
|
|
374
|
+
!!hydrate,
|
|
375
|
+
currentNodesVar,
|
|
376
|
+
hydrate ? parentVar : undefined,
|
|
377
|
+
),
|
|
378
|
+
),
|
|
379
|
+
]),
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
// In hydrate mode, scope to this element's children for descendants
|
|
383
|
+
let childNodesVar: string | undefined;
|
|
384
|
+
if (hydrate) {
|
|
385
|
+
childNodesVar = genId();
|
|
386
|
+
buildHydrationScope(varName, statements, childNodesVar);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Attribute writes that only matter on a fresh element. When hydration
|
|
390
|
+
// claims server HTML they already happened there, and redoing them would
|
|
391
|
+
// wipe whatever a page script changed in the meantime.
|
|
392
|
+
const init: t.Statement[] = [];
|
|
393
|
+
// <select value> needs its options to exist first.
|
|
394
|
+
const initAfter: t.Statement[] = [];
|
|
395
|
+
const liveAfter: t.Statement[] = [];
|
|
396
|
+
|
|
397
|
+
// attributes
|
|
398
|
+
const seenAttrs = new Set<string>();
|
|
399
|
+
for (const attr of node.openingElement.attributes) {
|
|
400
|
+
if (t.isJSXSpreadAttribute(attr)) {
|
|
401
|
+
// {…obj}: listeners always, attributes unless hydration claimed
|
|
402
|
+
// the element (then the server already rendered them)
|
|
403
|
+
const args: t.Expression[] = [t.identifier(varName), attr.argument];
|
|
404
|
+
if (hydrate) args.push(t.unaryExpression("!", isClaimedCall(varName)));
|
|
405
|
+
statements.push(
|
|
406
|
+
t.expressionStatement(t.callExpression(t.identifier("spread"), args)),
|
|
407
|
+
);
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (!t.isJSXAttribute(attr)) continue;
|
|
411
|
+
let attrName: string;
|
|
412
|
+
let attrNamespace: string | undefined;
|
|
413
|
+
if (t.isJSXNamespacedName(attr.name)) {
|
|
414
|
+
attrNamespace = attr.name.namespace.name;
|
|
415
|
+
attrName = attr.name.name.name;
|
|
416
|
+
} else {
|
|
417
|
+
attrName = (attr.name as t.JSXIdentifier).name;
|
|
418
|
+
// bindValue -> bind:value, bindChecked -> bind:checked
|
|
419
|
+
if (/^bind[A-Z]/.test(attrName)) {
|
|
420
|
+
attrNamespace = "bind";
|
|
421
|
+
// bindScrollTop -> bind:scrollTop: only the first letter lowers
|
|
422
|
+
attrName = attrName.charAt(4).toLowerCase() + attrName.slice(5);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
const realAttr = ATTR_MAP[attrName] ?? attrName;
|
|
426
|
+
|
|
427
|
+
if (seenAttrs.has(realAttr)) {
|
|
428
|
+
throw new TypeError(
|
|
429
|
+
`Duplicate attribute "${realAttr}" (via "${attrName}"). Use class or className, not both.`,
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
seenAttrs.add(realAttr);
|
|
433
|
+
if (
|
|
434
|
+
(attrNamespace === "transition" ||
|
|
435
|
+
attrNamespace === "in" ||
|
|
436
|
+
attrNamespace === "out") &&
|
|
437
|
+
t.isJSXExpressionContainer(attr.value)
|
|
438
|
+
) {
|
|
439
|
+
// transition:fade={fade} / in:appear={x} / out:leave={[y, params]}
|
|
440
|
+
const expr = attr.value.expression as t.Expression;
|
|
441
|
+
statements.push(
|
|
442
|
+
t.expressionStatement(
|
|
443
|
+
t.callExpression(t.identifier("mountTransition"), [
|
|
444
|
+
t.identifier(varName),
|
|
445
|
+
expr,
|
|
446
|
+
t.stringLiteral(attrNamespace as "transition" | "in" | "out"),
|
|
447
|
+
]),
|
|
448
|
+
),
|
|
449
|
+
);
|
|
450
|
+
} else if (attrName === "use") {
|
|
451
|
+
// use={directive} or use={[directive, params]}
|
|
452
|
+
const expr = (attr.value as t.JSXExpressionContainer)
|
|
453
|
+
.expression as t.Expression;
|
|
454
|
+
statements.push(
|
|
455
|
+
t.expressionStatement(
|
|
456
|
+
t.callExpression(t.identifier("applyDirective"), [
|
|
457
|
+
t.identifier(varName),
|
|
458
|
+
expr,
|
|
459
|
+
]),
|
|
460
|
+
),
|
|
461
|
+
);
|
|
462
|
+
} else if (/^on[A-Z]/.test(attrName)) {
|
|
463
|
+
// Standard JSX: onClick, onSubmit, onMouseenter, etc.
|
|
464
|
+
// Convert camelCase to lowercase: onClick -> click, onMouseenter -> mouseenter
|
|
465
|
+
const event = attrName.slice(2).toLowerCase();
|
|
466
|
+
const handler = (attr.value as t.JSXExpressionContainer)
|
|
467
|
+
.expression as t.Expression;
|
|
468
|
+
statements.push(
|
|
469
|
+
t.expressionStatement(
|
|
470
|
+
t.callExpression(
|
|
471
|
+
t.memberExpression(
|
|
472
|
+
t.identifier(varName),
|
|
473
|
+
t.identifier("addEventListener"),
|
|
474
|
+
),
|
|
475
|
+
[t.stringLiteral(event), handler],
|
|
476
|
+
),
|
|
477
|
+
),
|
|
478
|
+
);
|
|
479
|
+
} else if (attrNamespace === "bind") {
|
|
480
|
+
const bindProp = attrName;
|
|
481
|
+
const signal = (attr.value as t.JSXExpressionContainer)
|
|
482
|
+
.expression as t.Expression;
|
|
483
|
+
|
|
484
|
+
if (bindProp === "this") {
|
|
485
|
+
statements.push(
|
|
486
|
+
t.expressionStatement(
|
|
487
|
+
t.callExpression(
|
|
488
|
+
t.memberExpression(
|
|
489
|
+
(signal as t.CallExpression).callee as t.Expression,
|
|
490
|
+
t.identifier("set"),
|
|
491
|
+
),
|
|
492
|
+
[t.identifier(varName)],
|
|
493
|
+
),
|
|
494
|
+
),
|
|
495
|
+
);
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (bindProp === "group") {
|
|
500
|
+
// Scan element attributes for type and value
|
|
501
|
+
let inputType = "";
|
|
502
|
+
let _inputValue: t.StringLiteral | undefined;
|
|
503
|
+
for (const a of node.openingElement.attributes) {
|
|
504
|
+
if (t.isJSXAttribute(a) && t.isJSXIdentifier(a.name)) {
|
|
505
|
+
if (a.name.name === "type" && t.isStringLiteral(a.value)) {
|
|
506
|
+
inputType = a.value.value;
|
|
507
|
+
}
|
|
508
|
+
if (a.name.name === "value" && t.isStringLiteral(a.value)) {
|
|
509
|
+
_inputValue = a.value;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (inputType === "radio" || inputType === "") {
|
|
515
|
+
const isTopLevel =
|
|
516
|
+
t.isCallExpression(signal) &&
|
|
517
|
+
t.isIdentifier((signal as t.CallExpression).callee) &&
|
|
518
|
+
signals.has(
|
|
519
|
+
((signal as t.CallExpression).callee as t.Identifier).name,
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
if (isTopLevel) {
|
|
523
|
+
const signalId = (signal as t.CallExpression)
|
|
524
|
+
.callee as t.Identifier;
|
|
525
|
+
statements.push(
|
|
526
|
+
t.expressionStatement(
|
|
527
|
+
t.callExpression(
|
|
528
|
+
t.memberExpression(
|
|
529
|
+
t.identifier(varName),
|
|
530
|
+
t.identifier("addEventListener"),
|
|
531
|
+
),
|
|
532
|
+
[
|
|
533
|
+
t.stringLiteral("change"),
|
|
534
|
+
t.arrowFunctionExpression(
|
|
535
|
+
[],
|
|
536
|
+
t.callExpression(
|
|
537
|
+
t.memberExpression(signalId, t.identifier("set")),
|
|
538
|
+
[
|
|
539
|
+
t.memberExpression(
|
|
540
|
+
t.identifier(varName),
|
|
541
|
+
t.identifier("value"),
|
|
542
|
+
),
|
|
543
|
+
],
|
|
544
|
+
),
|
|
545
|
+
),
|
|
546
|
+
],
|
|
547
|
+
),
|
|
548
|
+
),
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
} else if (inputType === "checkbox") {
|
|
552
|
+
const isTopLevel =
|
|
553
|
+
t.isCallExpression(signal) &&
|
|
554
|
+
t.isIdentifier((signal as t.CallExpression).callee) &&
|
|
555
|
+
signals.has(
|
|
556
|
+
((signal as t.CallExpression).callee as t.Identifier).name,
|
|
557
|
+
);
|
|
558
|
+
|
|
559
|
+
if (isTopLevel) {
|
|
560
|
+
const callExpr = signal as t.CallExpression;
|
|
561
|
+
statements.push(
|
|
562
|
+
t.expressionStatement(
|
|
563
|
+
t.callExpression(
|
|
564
|
+
t.memberExpression(
|
|
565
|
+
t.identifier(varName),
|
|
566
|
+
t.identifier("addEventListener"),
|
|
567
|
+
),
|
|
568
|
+
[
|
|
569
|
+
t.stringLiteral("change"),
|
|
570
|
+
t.arrowFunctionExpression(
|
|
571
|
+
[],
|
|
572
|
+
t.blockStatement([
|
|
573
|
+
t.ifStatement(
|
|
574
|
+
t.memberExpression(
|
|
575
|
+
t.identifier(varName),
|
|
576
|
+
t.identifier("checked"),
|
|
577
|
+
),
|
|
578
|
+
// checked: push value into array
|
|
579
|
+
t.blockStatement([
|
|
580
|
+
t.expressionStatement(
|
|
581
|
+
t.callExpression(
|
|
582
|
+
t.memberExpression(
|
|
583
|
+
t.callExpression(callExpr, []),
|
|
584
|
+
t.identifier("push"),
|
|
585
|
+
),
|
|
586
|
+
[
|
|
587
|
+
t.memberExpression(
|
|
588
|
+
t.identifier(varName),
|
|
589
|
+
t.identifier("value"),
|
|
590
|
+
),
|
|
591
|
+
],
|
|
592
|
+
),
|
|
593
|
+
),
|
|
594
|
+
]),
|
|
595
|
+
// unchecked: splice value out of array
|
|
596
|
+
t.blockStatement([
|
|
597
|
+
t.expressionStatement(
|
|
598
|
+
t.callExpression(
|
|
599
|
+
t.memberExpression(
|
|
600
|
+
t.callExpression(callExpr, []),
|
|
601
|
+
t.identifier("splice"),
|
|
602
|
+
),
|
|
603
|
+
[
|
|
604
|
+
t.callExpression(
|
|
605
|
+
t.memberExpression(
|
|
606
|
+
t.callExpression(callExpr, []),
|
|
607
|
+
t.identifier("indexOf"),
|
|
608
|
+
),
|
|
609
|
+
[
|
|
610
|
+
t.memberExpression(
|
|
611
|
+
t.identifier(varName),
|
|
612
|
+
t.identifier("value"),
|
|
613
|
+
),
|
|
614
|
+
],
|
|
615
|
+
),
|
|
616
|
+
t.numericLiteral(1),
|
|
617
|
+
],
|
|
618
|
+
),
|
|
619
|
+
),
|
|
620
|
+
]),
|
|
621
|
+
),
|
|
622
|
+
]),
|
|
623
|
+
),
|
|
624
|
+
],
|
|
625
|
+
),
|
|
626
|
+
),
|
|
627
|
+
);
|
|
628
|
+
}
|
|
629
|
+
} else {
|
|
630
|
+
console.warn(
|
|
631
|
+
`[sigil] bind:group requires type="radio" or type="checkbox" on the element. ` +
|
|
632
|
+
`Got: type="${inputType}".`,
|
|
633
|
+
);
|
|
634
|
+
}
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// Generic bind:innerHTML, bind:textContent, bind:value, bind:checked, etc.
|
|
639
|
+
const isTopLevelSignal =
|
|
640
|
+
t.isCallExpression(signal) &&
|
|
641
|
+
t.isIdentifier((signal as t.CallExpression).callee) &&
|
|
642
|
+
signals.has(((signal as t.CallExpression).callee as t.Identifier).name);
|
|
643
|
+
|
|
644
|
+
const isMemberOfSignal =
|
|
645
|
+
t.isMemberExpression(signal) &&
|
|
646
|
+
t.isCallExpression((signal as t.MemberExpression).object) &&
|
|
647
|
+
t.isIdentifier(
|
|
648
|
+
((signal as t.MemberExpression).object as t.CallExpression).callee,
|
|
649
|
+
) &&
|
|
650
|
+
signals.has(
|
|
651
|
+
(
|
|
652
|
+
((signal as t.MemberExpression).object as t.CallExpression)
|
|
653
|
+
.callee as t.Identifier
|
|
654
|
+
).name,
|
|
655
|
+
);
|
|
656
|
+
|
|
657
|
+
// bind:checked={item.done} in a list row, or {book.read} where `book`
|
|
658
|
+
// is a prop: the chain is rooted at a row item or a props object,
|
|
659
|
+
// and what it ends in is a property of a $state proxy
|
|
660
|
+
let root: t.Node = signal;
|
|
661
|
+
while (t.isMemberExpression(root)) root = root.object;
|
|
662
|
+
const isMemberOfItem =
|
|
663
|
+
t.isMemberExpression(signal) &&
|
|
664
|
+
t.isIdentifier(root) &&
|
|
665
|
+
signals.has(root.name);
|
|
666
|
+
|
|
667
|
+
if (isTopLevelSignal) {
|
|
668
|
+
buildBind(varName, bindProp, attr, statements);
|
|
669
|
+
} else if (isMemberOfSignal || isMemberOfItem) {
|
|
670
|
+
buildProxyBind(varName, bindProp, attr, statements, signal);
|
|
671
|
+
} else {
|
|
672
|
+
console.warn(
|
|
673
|
+
`[sigil] bind:${bindProp}={...} requires a $state signal or $state object property. ` +
|
|
674
|
+
`Got: ${generate(signal).code}. ` +
|
|
675
|
+
`Hint: change to a $state() call.`,
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
} else if (attr.value === null) {
|
|
679
|
+
// bare attribute (<input disabled>, <div data-beacon>)
|
|
680
|
+
init.push(
|
|
681
|
+
t.expressionStatement(
|
|
682
|
+
isDashedAttr(realAttr)
|
|
683
|
+
? setAttrCall(varName, realAttr, t.stringLiteral(""))
|
|
684
|
+
: setPropCall(varName, realAttr, t.booleanLiteral(true)),
|
|
685
|
+
),
|
|
686
|
+
);
|
|
687
|
+
} else if (t.isStringLiteral(attr.value)) {
|
|
688
|
+
const stmt = t.expressionStatement(
|
|
689
|
+
setPropCall(varName, realAttr, t.stringLiteral(attr.value.value)),
|
|
690
|
+
);
|
|
691
|
+
(tag === "select" && realAttr === "value" ? initAfter : init).push(stmt);
|
|
692
|
+
} else if (t.isJSXExpressionContainer(attr.value)) {
|
|
693
|
+
const expr = attr.value.expression as t.Expression;
|
|
694
|
+
const afterChildren = tag === "select" && realAttr === "value";
|
|
695
|
+
// style={{ color: "red", fontSize: val }} — per-property writes
|
|
696
|
+
if (attrName === "style" && t.isObjectExpression(expr)) {
|
|
697
|
+
for (const prop of expr.properties) {
|
|
698
|
+
if (!t.isObjectProperty(prop)) continue;
|
|
699
|
+
const key = t.isIdentifier(prop.key)
|
|
700
|
+
? prop.key.name
|
|
701
|
+
: t.isStringLiteral(prop.key)
|
|
702
|
+
? prop.key.value
|
|
703
|
+
: null;
|
|
704
|
+
if (!key) continue;
|
|
705
|
+
const val = prop.value as t.Expression;
|
|
706
|
+
const write = t.expressionStatement(
|
|
707
|
+
t.callExpression(t.identifier("setStyleProp"), [
|
|
708
|
+
t.identifier(varName),
|
|
709
|
+
t.stringLiteral(key),
|
|
710
|
+
val,
|
|
711
|
+
]),
|
|
712
|
+
);
|
|
713
|
+
if (containsSignal(val, signals)) {
|
|
714
|
+
statements.push(effect([write]));
|
|
715
|
+
} else {
|
|
716
|
+
init.push(write);
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
} else if (containsSignal(expr, signals)) {
|
|
720
|
+
// Dynamic class with scoped CSS: use classList.value to preserve hash
|
|
721
|
+
if (attrName === "class" && hash) {
|
|
722
|
+
statements.push(
|
|
723
|
+
effect([
|
|
724
|
+
t.expressionStatement(
|
|
725
|
+
t.assignmentExpression(
|
|
726
|
+
"=",
|
|
727
|
+
t.memberExpression(
|
|
728
|
+
t.memberExpression(
|
|
729
|
+
t.identifier(varName),
|
|
730
|
+
t.identifier("classList"),
|
|
731
|
+
),
|
|
732
|
+
t.identifier("value"),
|
|
733
|
+
),
|
|
734
|
+
expr,
|
|
735
|
+
),
|
|
736
|
+
),
|
|
737
|
+
t.expressionStatement(
|
|
738
|
+
t.callExpression(
|
|
739
|
+
t.memberExpression(
|
|
740
|
+
t.memberExpression(
|
|
741
|
+
t.identifier(varName),
|
|
742
|
+
t.identifier("classList"),
|
|
743
|
+
),
|
|
744
|
+
t.identifier("add"),
|
|
745
|
+
),
|
|
746
|
+
[t.stringLiteral(hash)],
|
|
747
|
+
),
|
|
748
|
+
),
|
|
749
|
+
]),
|
|
750
|
+
);
|
|
751
|
+
} else {
|
|
752
|
+
const stmt = effect([
|
|
753
|
+
t.expressionStatement(setPropCall(varName, realAttr, expr)),
|
|
754
|
+
]);
|
|
755
|
+
(afterChildren ? liveAfter : statements).push(stmt);
|
|
756
|
+
}
|
|
757
|
+
} else {
|
|
758
|
+
const stmt = t.expressionStatement(
|
|
759
|
+
setPropCall(varName, realAttr, expr),
|
|
760
|
+
);
|
|
761
|
+
(afterChildren ? initAfter : init).push(stmt);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
pushInit(varName, init, statements, hydrate);
|
|
767
|
+
|
|
768
|
+
// Add scoped CSS hash to classList (if hash is present)
|
|
769
|
+
if (hash) {
|
|
770
|
+
addScopedClass(varName, hash, statements);
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
// children. <script> text is already in the server HTML, raw and unmarked
|
|
774
|
+
// (see ssr.ts), so hydration has nothing to claim there: the marker search
|
|
775
|
+
// would miss and append a second copy of the code.
|
|
776
|
+
if (hydrate && tag === "script") {
|
|
777
|
+
// ...but SPA navigation creates the element fresh and needs the text.
|
|
778
|
+
const text = scriptText(node);
|
|
779
|
+
if (text) {
|
|
780
|
+
const write = [
|
|
781
|
+
t.expressionStatement(
|
|
782
|
+
t.assignmentExpression(
|
|
783
|
+
"=",
|
|
784
|
+
t.memberExpression(
|
|
785
|
+
t.identifier(varName),
|
|
786
|
+
t.identifier("textContent"),
|
|
787
|
+
),
|
|
788
|
+
text,
|
|
789
|
+
),
|
|
790
|
+
),
|
|
791
|
+
];
|
|
792
|
+
pushInit(varName, write, statements, hydrate);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
for (const child of hydrate && tag === "script" ? [] : node.children) {
|
|
796
|
+
if (t.isJSXElement(child)) {
|
|
797
|
+
const childVar = processElement(
|
|
798
|
+
child,
|
|
799
|
+
statements,
|
|
800
|
+
genId,
|
|
801
|
+
signals,
|
|
802
|
+
hash,
|
|
803
|
+
hydrate,
|
|
804
|
+
childNodesVar,
|
|
805
|
+
hydrate ? varName : undefined,
|
|
806
|
+
);
|
|
807
|
+
if (!hydrate) {
|
|
808
|
+
statements.push(
|
|
809
|
+
t.expressionStatement(
|
|
810
|
+
t.callExpression(
|
|
811
|
+
t.memberExpression(t.identifier(varName), t.identifier("append")),
|
|
812
|
+
[t.identifier(childVar)],
|
|
813
|
+
),
|
|
814
|
+
),
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
} else if (t.isJSXFragment(child)) {
|
|
818
|
+
const childVar = processFragment(
|
|
819
|
+
child,
|
|
820
|
+
statements,
|
|
821
|
+
genId,
|
|
822
|
+
signals,
|
|
823
|
+
hash,
|
|
824
|
+
hydrate,
|
|
825
|
+
childNodesVar,
|
|
826
|
+
hydrate ? varName : undefined,
|
|
827
|
+
);
|
|
828
|
+
if (!hydrate) {
|
|
829
|
+
statements.push(
|
|
830
|
+
t.expressionStatement(
|
|
831
|
+
t.callExpression(
|
|
832
|
+
t.memberExpression(t.identifier(varName), t.identifier("append")),
|
|
833
|
+
[t.identifier(childVar)],
|
|
834
|
+
),
|
|
835
|
+
),
|
|
836
|
+
);
|
|
837
|
+
}
|
|
838
|
+
} else if (t.isJSXText(child)) {
|
|
839
|
+
const text = jsxText(child, node.children);
|
|
840
|
+
if (text === null) continue;
|
|
841
|
+
if (hydrate) {
|
|
842
|
+
// SSR hydration: text already in DOM from SSR, do nothing.
|
|
843
|
+
// SPA navigation: childNodesVar pool is empty, create text node.
|
|
844
|
+
const poolLen = t.memberExpression(
|
|
845
|
+
t.identifier(childNodesVar!),
|
|
846
|
+
t.identifier("length"),
|
|
847
|
+
);
|
|
848
|
+
statements.push(
|
|
849
|
+
t.ifStatement(
|
|
850
|
+
t.binaryExpression("===", poolLen, t.numericLiteral(0)),
|
|
851
|
+
t.expressionStatement(
|
|
852
|
+
t.callExpression(
|
|
853
|
+
t.memberExpression(
|
|
854
|
+
t.identifier(varName),
|
|
855
|
+
t.identifier("append"),
|
|
856
|
+
),
|
|
857
|
+
[
|
|
858
|
+
t.callExpression(
|
|
859
|
+
t.memberExpression(
|
|
860
|
+
t.identifier("document"),
|
|
861
|
+
t.identifier("createTextNode"),
|
|
862
|
+
),
|
|
863
|
+
[t.stringLiteral(text)],
|
|
864
|
+
),
|
|
865
|
+
],
|
|
866
|
+
),
|
|
867
|
+
),
|
|
868
|
+
),
|
|
869
|
+
);
|
|
870
|
+
} else {
|
|
871
|
+
statements.push(
|
|
872
|
+
t.expressionStatement(
|
|
873
|
+
t.callExpression(
|
|
874
|
+
t.memberExpression(t.identifier(varName), t.identifier("append")),
|
|
875
|
+
[
|
|
876
|
+
t.callExpression(
|
|
877
|
+
t.memberExpression(
|
|
878
|
+
t.identifier("document"),
|
|
879
|
+
t.identifier("createTextNode"),
|
|
880
|
+
),
|
|
881
|
+
[t.stringLiteral(text)],
|
|
882
|
+
),
|
|
883
|
+
],
|
|
884
|
+
),
|
|
885
|
+
),
|
|
886
|
+
);
|
|
887
|
+
}
|
|
888
|
+
} else if (t.isJSXExpressionContainer(child)) {
|
|
889
|
+
if (t.isJSXEmptyExpression(child.expression)) continue;
|
|
890
|
+
const expr = child.expression as t.Expression;
|
|
891
|
+
if (t.isJSXElement(expr)) {
|
|
892
|
+
const childVar = processElement(
|
|
893
|
+
expr,
|
|
894
|
+
statements,
|
|
895
|
+
genId,
|
|
896
|
+
signals,
|
|
897
|
+
hash,
|
|
898
|
+
hydrate,
|
|
899
|
+
childNodesVar,
|
|
900
|
+
hydrate ? varName : undefined,
|
|
901
|
+
);
|
|
902
|
+
if (!hydrate) {
|
|
903
|
+
statements.push(
|
|
904
|
+
t.expressionStatement(
|
|
905
|
+
t.callExpression(
|
|
906
|
+
t.memberExpression(
|
|
907
|
+
t.identifier(varName),
|
|
908
|
+
t.identifier("append"),
|
|
909
|
+
),
|
|
910
|
+
[t.identifier(childVar)],
|
|
911
|
+
),
|
|
912
|
+
),
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
} else if (t.isJSXFragment(expr)) {
|
|
916
|
+
const childVar = processFragment(
|
|
917
|
+
expr,
|
|
918
|
+
statements,
|
|
919
|
+
genId,
|
|
920
|
+
signals,
|
|
921
|
+
hash,
|
|
922
|
+
hydrate,
|
|
923
|
+
childNodesVar,
|
|
924
|
+
hydrate ? varName : undefined,
|
|
925
|
+
);
|
|
926
|
+
if (!hydrate) {
|
|
927
|
+
statements.push(
|
|
928
|
+
t.expressionStatement(
|
|
929
|
+
t.callExpression(
|
|
930
|
+
t.memberExpression(
|
|
931
|
+
t.identifier(varName),
|
|
932
|
+
t.identifier("append"),
|
|
933
|
+
),
|
|
934
|
+
[t.identifier(childVar)],
|
|
935
|
+
),
|
|
936
|
+
),
|
|
937
|
+
);
|
|
938
|
+
}
|
|
939
|
+
} else if (isPropRead(expr)) {
|
|
940
|
+
// a prop may hold text, nodes or a deferred child, and may be a
|
|
941
|
+
// getter over state: a live slot handles all of them
|
|
942
|
+
statements.push(
|
|
943
|
+
t.expressionStatement(
|
|
944
|
+
t.callExpression(t.identifier("liveSlot"), [
|
|
945
|
+
hydrate ? t.identifier(childNodesVar!) : t.arrayExpression([]),
|
|
946
|
+
t.identifier(varName),
|
|
947
|
+
t.arrowFunctionExpression([], expr),
|
|
948
|
+
]),
|
|
949
|
+
),
|
|
950
|
+
);
|
|
951
|
+
} else if (containsSignal(expr, signals)) {
|
|
952
|
+
if (isPrimitive(expr)) {
|
|
953
|
+
// fast path: text node + textContent
|
|
954
|
+
buildTextNode(
|
|
955
|
+
varName,
|
|
956
|
+
expr,
|
|
957
|
+
statements,
|
|
958
|
+
genId,
|
|
959
|
+
hydrate,
|
|
960
|
+
childNodesVar,
|
|
961
|
+
hydrate ? varName : undefined,
|
|
962
|
+
);
|
|
963
|
+
} else {
|
|
964
|
+
// Check for keyed list pattern
|
|
965
|
+
const keyed = findKeyedMapExpr(expr, signals);
|
|
966
|
+
if (keyed) {
|
|
967
|
+
buildKeyedList(
|
|
968
|
+
varName,
|
|
969
|
+
keyed,
|
|
970
|
+
statements,
|
|
971
|
+
genId,
|
|
972
|
+
signals,
|
|
973
|
+
processElement,
|
|
974
|
+
hash,
|
|
975
|
+
hydrate,
|
|
976
|
+
childNodesVar,
|
|
977
|
+
hydrate ? varName : undefined,
|
|
978
|
+
);
|
|
979
|
+
} else {
|
|
980
|
+
buildAnchorMount(
|
|
981
|
+
varName,
|
|
982
|
+
expr,
|
|
983
|
+
statements,
|
|
984
|
+
genId,
|
|
985
|
+
hydrate,
|
|
986
|
+
childNodesVar,
|
|
987
|
+
hydrate ? varName : undefined,
|
|
988
|
+
);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
} else {
|
|
992
|
+
// non-reactive: set once
|
|
993
|
+
if (hydrate) {
|
|
994
|
+
// hydrateSlot consumes the <!--g-->…<!--/g--> run and runs the
|
|
995
|
+
// value against the content SSR put inside it, so both deferred
|
|
996
|
+
// component children and inline JSX (`{list.map(…)}`) claim that
|
|
997
|
+
// subtree. The value must stay lazy: evaluating it as an argument
|
|
998
|
+
// would claim from the enclosing pool instead. Empty pool
|
|
999
|
+
// (SPA nav) falls back to a fresh insert.
|
|
1000
|
+
statements.push(
|
|
1001
|
+
t.expressionStatement(
|
|
1002
|
+
t.callExpression(t.identifier("hydrateSlot"), [
|
|
1003
|
+
t.identifier(childNodesVar!),
|
|
1004
|
+
t.identifier(varName),
|
|
1005
|
+
t.arrowFunctionExpression([], expr),
|
|
1006
|
+
]),
|
|
1007
|
+
),
|
|
1008
|
+
);
|
|
1009
|
+
} else {
|
|
1010
|
+
statements.push(
|
|
1011
|
+
t.expressionStatement(
|
|
1012
|
+
t.callExpression(t.identifier("insert"), [
|
|
1013
|
+
t.identifier(varName),
|
|
1014
|
+
expr,
|
|
1015
|
+
]),
|
|
1016
|
+
),
|
|
1017
|
+
);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
pushInit(varName, initAfter, statements, hydrate);
|
|
1024
|
+
statements.push(...liveAfter);
|
|
1025
|
+
|
|
1026
|
+
return varName;
|
|
1027
|
+
}
|