@sigil-dev/compiler 0.9.25 → 0.9.27
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/package.json +1 -1
- package/src/analysis/hydration.ts +1012 -899
- package/src/babel/handlers/dom/derived.ts +2 -0
- package/src/babel/handlers/dom/state.ts +108 -106
- package/src/babel/handlers/ssr/derived.ts +2 -0
- package/src/babel/index.ts +750 -685
- package/src/babel/jsx/anchor-mount.ts +333 -426
- package/src/babel/jsx/element.ts +1034 -1027
- package/src/babel/jsx/ssr.ts +317 -307
- package/src/babel/jsx/utils.ts +356 -355
- package/src/babel/util/compile-state.ts +11 -5
- package/src/babel/util/dead-code.ts +85 -20
- package/src/babel/util/owner-awaits.ts +64 -0
- package/src/babel/util/props.ts +202 -256
- package/src/babel/util/shadowed-globals.ts +31 -0
- package/src/babel/util/state-imports.ts +121 -0
- package/src/babel/util/svg-attrs.ts +86 -0
- package/src/babel/util/warn.ts +36 -0
- package/src/bun-plugin.ts +106 -103
- package/test/bun-plugin.test.ts +3 -1
- package/test/components.test.ts +4 -4
- package/test/context.test.ts +102 -0
- package/test/fixtures/stores/cart.ts +1 -0
- package/test/fixtures/stores/counter.ts +8 -0
- package/test/fixtures/stores/index.ts +2 -0
- package/test/fixtures/stores/macros.d.ts +3 -0
- package/test/fixtures/stores/plain.ts +4 -0
- package/test/hydration.test.ts +313 -277
- package/test/render-parity.test.ts +907 -882
- package/test/shadowed-globals.test.ts +47 -0
- package/test/ssr.test.ts +130 -130
- package/test/state-imports.test.ts +92 -0
- package/test/tree-shaking.test.ts +45 -3
|
@@ -1,882 +1,907 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The same JSX rendered three ways must agree: server HTML (ssr), that HTML
|
|
3
|
-
* after hydration, and a fresh client render (hydrate code with an empty pool,
|
|
4
|
-
* which is what client-side navigation runs).
|
|
5
|
-
*/
|
|
6
|
-
import { describe, expect, test } from "bun:test";
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.replace(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
host
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
runtime.
|
|
46
|
-
runtime.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
expect(
|
|
56
|
-
expect(noMarkers(r.
|
|
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
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
<p>
|
|
148
|
-
<
|
|
149
|
-
<Item />
|
|
150
|
-
<
|
|
151
|
-
<
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
<li>
|
|
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
|
-
expect(r.spa.querySelector("
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
'<
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
test("
|
|
297
|
-
expectAll(
|
|
298
|
-
`export const App = () => <p
|
|
299
|
-
|
|
300
|
-
);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
|
-
test("
|
|
304
|
-
const r =
|
|
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
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
expect(
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
expect(
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
);
|
|
389
|
-
|
|
390
|
-
expect(r.spa.innerHTML).toBe(
|
|
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
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
const
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
expect(
|
|
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
|
-
expect(
|
|
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
|
-
g.__bump!();
|
|
708
|
-
await runtime.tick();
|
|
709
|
-
expect(noMarkers(
|
|
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
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
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
|
-
const
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
)
|
|
867
|
-
const
|
|
868
|
-
expect(plain(
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
})
|
|
1
|
+
/**
|
|
2
|
+
* The same JSX rendered three ways must agree: server HTML (ssr), that HTML
|
|
3
|
+
* after hydration, and a fresh client render (hydrate code with an empty pool,
|
|
4
|
+
* which is what client-side navigation runs).
|
|
5
|
+
*/
|
|
6
|
+
import { describe, expect, test } from "bun:test";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { transformSync } from "@babel/core";
|
|
9
|
+
import * as runtime from "../../runtime/index.ts";
|
|
10
|
+
import sigilPlugin from "../src/babel/index.ts";
|
|
11
|
+
|
|
12
|
+
type Mode = "ssr" | "hydrate";
|
|
13
|
+
|
|
14
|
+
function compile(source: string, mode: Mode, hash?: string): () => unknown {
|
|
15
|
+
const code = transformSync(source, {
|
|
16
|
+
plugins: ["@babel/plugin-syntax-jsx", [sigilPlugin, { mode, hash }]],
|
|
17
|
+
filename: "t.tsx",
|
|
18
|
+
})!.code!;
|
|
19
|
+
const body = code
|
|
20
|
+
.replace(/import\s*\{[^}]*\}\s*from\s*["']@sigil-dev\/runtime["'];?/g, "")
|
|
21
|
+
.replace(/^export\s+/gm, "");
|
|
22
|
+
return new Function(
|
|
23
|
+
"document",
|
|
24
|
+
...Object.keys(runtime),
|
|
25
|
+
`${body};\nreturn App;`,
|
|
26
|
+
)(globalThis.document, ...Object.values(runtime));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const noMarkers = (html: string) => html.replace(/<!--[^>]*-->/g, "");
|
|
30
|
+
|
|
31
|
+
function render(
|
|
32
|
+
source: string,
|
|
33
|
+
opts: { hash?: string; beforeHydrate?: (host: HTMLElement) => void } = {},
|
|
34
|
+
) {
|
|
35
|
+
const ssr = String(compile(source, "ssr", opts.hash)());
|
|
36
|
+
|
|
37
|
+
const host = document.createElement("div");
|
|
38
|
+
host.innerHTML = ssr;
|
|
39
|
+
opts.beforeHydrate?.(host);
|
|
40
|
+
runtime.pushHydrationNodes(Array.from(host.childNodes));
|
|
41
|
+
compile(source, "hydrate", opts.hash)();
|
|
42
|
+
runtime.popHydrationNodes();
|
|
43
|
+
|
|
44
|
+
const spa = document.createElement("div");
|
|
45
|
+
runtime.pushHydrationNodes([]);
|
|
46
|
+
runtime.insert(spa, compile(source, "hydrate", opts.hash)());
|
|
47
|
+
runtime.popHydrationNodes();
|
|
48
|
+
|
|
49
|
+
return { ssr: noMarkers(ssr), hydrated: host, spa };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Server HTML, hydrated DOM and client render all equal `html`. */
|
|
53
|
+
function expectAll(source: string, html: string) {
|
|
54
|
+
const r = render(source);
|
|
55
|
+
expect(r.ssr).toBe(html);
|
|
56
|
+
expect(noMarkers(r.hydrated.innerHTML)).toBe(html);
|
|
57
|
+
expect(noMarkers(r.spa.innerHTML)).toBe(html);
|
|
58
|
+
return r;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe("whitespace", () => {
|
|
62
|
+
test("spaces next to elements survive inside fragments", () => {
|
|
63
|
+
expectAll(
|
|
64
|
+
`export const App = () => <div><>Hello <b>big</b> world</></div>;`,
|
|
65
|
+
"<div>Hello <b>big</b> world</div>",
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("a lone space between elements is kept", () => {
|
|
70
|
+
expectAll(
|
|
71
|
+
`export const App = () => <p><b>a</b> <i>b</i></p>;`,
|
|
72
|
+
"<p><b>a</b> <i>b</i></p>",
|
|
73
|
+
);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("a line break between text and an element reads as a space", () => {
|
|
77
|
+
expectAll(
|
|
78
|
+
`export const App = () => (
|
|
79
|
+
<p>
|
|
80
|
+
Hello
|
|
81
|
+
<b>big</b> world
|
|
82
|
+
</p>
|
|
83
|
+
);`,
|
|
84
|
+
"<p>Hello <b>big</b> world</p>",
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("a link wrapped onto its own line needs no {' '}", () => {
|
|
89
|
+
expectAll(
|
|
90
|
+
`export const App = () => (
|
|
91
|
+
<li>
|
|
92
|
+
A few assets are loaded from
|
|
93
|
+
<a href="https://sekai.best">sekai.best</a>
|
|
94
|
+
.
|
|
95
|
+
</li>
|
|
96
|
+
);`,
|
|
97
|
+
'<li>A few assets are loaded from <a href="https://sekai.best">sekai.best</a>.</li>',
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("an element then text on the next line gets a space", () => {
|
|
102
|
+
expectAll(
|
|
103
|
+
`export const App = () => (
|
|
104
|
+
<p>
|
|
105
|
+
<b>Miku</b>
|
|
106
|
+
sings
|
|
107
|
+
</p>
|
|
108
|
+
);`,
|
|
109
|
+
"<p><b>Miku</b> sings</p>",
|
|
110
|
+
);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("a line break between two inline elements is a space", () => {
|
|
114
|
+
expectAll(
|
|
115
|
+
`const LIBS = [["three.js", "the three.js authors", "MIT"]];
|
|
116
|
+
export const App = () => (
|
|
117
|
+
<ul>
|
|
118
|
+
{LIBS.map(([what, who, licence]) => (
|
|
119
|
+
<li>
|
|
120
|
+
<a href="https://threejs.org">{what}</a>
|
|
121
|
+
<span>
|
|
122
|
+
by {who}, {licence}
|
|
123
|
+
</span>
|
|
124
|
+
</li>
|
|
125
|
+
))}
|
|
126
|
+
</ul>
|
|
127
|
+
);`,
|
|
128
|
+
'<ul><li><a href="https://threejs.org">three.js</a> <span>by the three.js authors, MIT</span></li></ul>',
|
|
129
|
+
);
|
|
130
|
+
expectAll(
|
|
131
|
+
`export const App = () => (
|
|
132
|
+
<p>
|
|
133
|
+
<b>bold</b>
|
|
134
|
+
<i>italic</i>
|
|
135
|
+
<code>code</code>
|
|
136
|
+
</p>
|
|
137
|
+
);`,
|
|
138
|
+
"<p><b>bold</b> <i>italic</i> <code>code</code></p>",
|
|
139
|
+
);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("indentation between blocks and components stays nothing", () => {
|
|
143
|
+
expectAll(
|
|
144
|
+
`const Item = () => <span>x</span>;
|
|
145
|
+
export const App = () => (
|
|
146
|
+
<div>
|
|
147
|
+
<p>one</p>
|
|
148
|
+
<p>two</p>
|
|
149
|
+
<Item />
|
|
150
|
+
<Item />
|
|
151
|
+
<span>inline</span>
|
|
152
|
+
<div>block</div>
|
|
153
|
+
</div>
|
|
154
|
+
);`,
|
|
155
|
+
"<div><p>one</p><p>two</p><span>x</span><span>x</span><span>inline</span><div>block</div></div>",
|
|
156
|
+
);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("expressions count as neighbours too", () => {
|
|
160
|
+
expectAll(
|
|
161
|
+
`const n = 3;
|
|
162
|
+
export const App = () => (
|
|
163
|
+
<p>
|
|
164
|
+
showing page
|
|
165
|
+
{n}
|
|
166
|
+
of 9
|
|
167
|
+
</p>
|
|
168
|
+
);`,
|
|
169
|
+
"<p>showing page 3 of 9</p>",
|
|
170
|
+
);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("no space before closing punctuation or after an opening bracket", () => {
|
|
174
|
+
expectAll(
|
|
175
|
+
`export const App = () => (
|
|
176
|
+
<p>
|
|
177
|
+
(
|
|
178
|
+
<b>a</b>
|
|
179
|
+
), <i>b</i>
|
|
180
|
+
!
|
|
181
|
+
</p>
|
|
182
|
+
);`,
|
|
183
|
+
"<p>(<b>a</b>), <i>b</i>!</p>",
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("no space next to Japanese text", () => {
|
|
188
|
+
expectAll(
|
|
189
|
+
`export const App = () => (
|
|
190
|
+
<p>
|
|
191
|
+
これは
|
|
192
|
+
<b>テスト</b>
|
|
193
|
+
です
|
|
194
|
+
</p>
|
|
195
|
+
);`,
|
|
196
|
+
"<p>これは<b>テスト</b>です</p>",
|
|
197
|
+
);
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("lines of only whitespace between elements still vanish", () => {
|
|
201
|
+
expectAll(
|
|
202
|
+
`export const App = () => (
|
|
203
|
+
<ul>
|
|
204
|
+
<li>a</li>
|
|
205
|
+
<li>b</li>
|
|
206
|
+
</ul>
|
|
207
|
+
);`,
|
|
208
|
+
"<ul><li>a</li><li>b</li></ul>",
|
|
209
|
+
);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("an explicit {' '} still works", () => {
|
|
213
|
+
expectAll(
|
|
214
|
+
`export const App = () => <p>from{" "}<a>x</a></p>;`,
|
|
215
|
+
"<p>from <a>x</a></p>",
|
|
216
|
+
);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("comments are not neighbours", () => {
|
|
220
|
+
expectAll(
|
|
221
|
+
`export const App = () => (
|
|
222
|
+
<p>
|
|
223
|
+
{/* nothing */}
|
|
224
|
+
text
|
|
225
|
+
{/* nothing */}
|
|
226
|
+
</p>
|
|
227
|
+
);`,
|
|
228
|
+
"<p>text</p>",
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("multi-line text joins with single spaces", () => {
|
|
233
|
+
expectAll(
|
|
234
|
+
`export const App = () => (
|
|
235
|
+
<p>
|
|
236
|
+
one
|
|
237
|
+
two
|
|
238
|
+
</p>
|
|
239
|
+
);`,
|
|
240
|
+
"<p>one two</p>",
|
|
241
|
+
);
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
test("component children keep their spaces", () => {
|
|
245
|
+
expectAll(
|
|
246
|
+
`const Box = ({ children }) => <span>{children}</span>;
|
|
247
|
+
export const App = () => <div><Box>Hi <b>you</b> there</Box></div>;`,
|
|
248
|
+
"<div><span>Hi <b>you</b> there</span></div>",
|
|
249
|
+
);
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
describe("attribute values", () => {
|
|
254
|
+
test("null and undefined leave the attribute out", () => {
|
|
255
|
+
expectAll(
|
|
256
|
+
`const u = undefined, n = null; export const App = () => <a href={u} title={n} data-x={u}>x</a>;`,
|
|
257
|
+
"<a>x</a>",
|
|
258
|
+
);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
test("dashed attributes spell booleans out", () => {
|
|
262
|
+
expectAll(
|
|
263
|
+
`const t = true, f = false; export const App = () => <div aria-hidden={t} data-open={f} />;`,
|
|
264
|
+
'<div aria-hidden="true" data-open="false"></div>',
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
test("bare attributes render on the server", () => {
|
|
269
|
+
const r = render(
|
|
270
|
+
`export const App = () => <div><script src="/x.js" defer></script><details open></details></div>;`,
|
|
271
|
+
);
|
|
272
|
+
expect(r.ssr).toBe(
|
|
273
|
+
'<div><script src="/x.js" defer></script><details open></details></div>',
|
|
274
|
+
);
|
|
275
|
+
expect(r.spa.querySelector("script")!.defer).toBe(true);
|
|
276
|
+
expect(r.spa.querySelector("details")!.open).toBe(true);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
test("React-style camelCase SVG attributes become their real names", () => {
|
|
280
|
+
const html =
|
|
281
|
+
'<svg viewBox="0 0 10 10"><line stroke-width="2" stroke-linecap="round" marker-end="url(#a)"></line>' +
|
|
282
|
+
'<text text-anchor="middle" font-size="3" dominant-baseline="central">x</text>' +
|
|
283
|
+
'<path fill-opacity="0.5" stroke-dasharray="1 2"></path></svg>';
|
|
284
|
+
// static, dynamic and spread all take the same path
|
|
285
|
+
expectAll(
|
|
286
|
+
`export const App = () => <svg viewBox="0 0 10 10"><line strokeWidth="2" strokeLinecap="round" markerEnd="url(#a)" /><text textAnchor="middle" fontSize={3} dominantBaseline="central">x</text><path {...{ fillOpacity: 0.5, strokeDasharray: "1 2" }} /></svg>;`,
|
|
287
|
+
html,
|
|
288
|
+
);
|
|
289
|
+
// already-kebab names and genuinely camelCase SVG ones are untouched
|
|
290
|
+
expectAll(
|
|
291
|
+
`export const App = () => <svg viewBox="0 0 4 4"><marker refX="1" markerWidth="2" /><line stroke-width="2" /></svg>;`,
|
|
292
|
+
'<svg viewBox="0 0 4 4"><marker refX="1" markerWidth="2"></marker><line stroke-width="2"></line></svg>',
|
|
293
|
+
);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("string attributes are escaped", () => {
|
|
297
|
+
expectAll(
|
|
298
|
+
`export const App = () => <p title='say "hi" & go'>x</p>;`,
|
|
299
|
+
'<p title="say "hi" & go">x</p>',
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
test("spread attributes render on the server and the client", () => {
|
|
304
|
+
const r = expectAll(
|
|
305
|
+
`const props = { id: "s", class: "c", "aria-label": "l", hidden: false, title: undefined };
|
|
306
|
+
export const App = () => <div {...props} />;`,
|
|
307
|
+
'<div id="s" class="c" aria-label="l"></div>',
|
|
308
|
+
);
|
|
309
|
+
expect(r.spa.firstElementChild!.getAttribute("class")).toBe("c");
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
describe("text escaping", () => {
|
|
314
|
+
test("entities in static text stay text", () => {
|
|
315
|
+
expectAll(
|
|
316
|
+
`export const App = () => <p><ok> & ©</p>;`,
|
|
317
|
+
"<p><ok> & ©</p>",
|
|
318
|
+
);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
test("backticks, backslashes and ${ in static text", () => {
|
|
322
|
+
const r = render("export const App = () => <p>a `b` \\n ${'{'}c{'}'}</p>;");
|
|
323
|
+
expect(r.ssr).toBe("<p>a `b` \\n ${c}</p>");
|
|
324
|
+
expect(r.spa.textContent).toBe("a `b` \\n ${c}");
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe("styles", () => {
|
|
329
|
+
test("numbers get px on the server and the client", () => {
|
|
330
|
+
const r = render(
|
|
331
|
+
`export const App = () => <p style={{ marginTop: 4, opacity: 0.5, "--gap": 2 }}>x</p>;`,
|
|
332
|
+
);
|
|
333
|
+
expect(r.ssr).toBe('<p style="margin-top:4px;opacity:0.5;--gap:2">x</p>');
|
|
334
|
+
const style = (r.spa.firstElementChild as HTMLElement).style;
|
|
335
|
+
expect(style.marginTop).toBe("4px");
|
|
336
|
+
expect(style.opacity).toBe("0.5");
|
|
337
|
+
expect(style.getPropertyValue("--gap")).toBe("2");
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test("a style object passed as a value", () => {
|
|
341
|
+
const r = render(
|
|
342
|
+
`const s = { marginTop: 4, color: "red" }; export const App = () => <p style={s}>x</p>;`,
|
|
343
|
+
);
|
|
344
|
+
expect(r.ssr).toBe('<p style="margin-top:4px;color:red">x</p>');
|
|
345
|
+
const style = (r.spa.firstElementChild as HTMLElement).style;
|
|
346
|
+
expect(style.marginTop).toBe("4px");
|
|
347
|
+
expect(style.color).toBe("red");
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe("form values", () => {
|
|
352
|
+
test("<textarea value> is its content on the server", () => {
|
|
353
|
+
const r = render(
|
|
354
|
+
`const v = "a < b"; export const App = () => <textarea value={v} />;`,
|
|
355
|
+
);
|
|
356
|
+
expect(r.ssr).toBe("<textarea>a < b</textarea>");
|
|
357
|
+
expect((r.spa.firstElementChild as HTMLTextAreaElement).value).toBe(
|
|
358
|
+
"a < b",
|
|
359
|
+
);
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
test("<select value> selects its option everywhere", () => {
|
|
363
|
+
const src = `const v = "2"; export const App = () => (
|
|
364
|
+
<select value={v}>
|
|
365
|
+
<option value="1">1</option>
|
|
366
|
+
<option value="2">2</option>
|
|
367
|
+
</select>
|
|
368
|
+
);`;
|
|
369
|
+
const r = render(src);
|
|
370
|
+
expect(r.ssr).toBe(
|
|
371
|
+
'<select><option value="1">1</option><option value="2" selected>2</option></select>',
|
|
372
|
+
);
|
|
373
|
+
expect((r.hydrated.firstElementChild as HTMLSelectElement).value).toBe("2");
|
|
374
|
+
expect((r.spa.firstElementChild as HTMLSelectElement).value).toBe("2");
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
describe("hydration keeps the server DOM", () => {
|
|
379
|
+
test("classes and attributes added before hydration stay", () => {
|
|
380
|
+
const r = render(`export const App = () => <div class="a" data-k="1" />;`, {
|
|
381
|
+
beforeHydrate: (host) => {
|
|
382
|
+
host.firstElementChild!.classList.add("added");
|
|
383
|
+
host.firstElementChild!.setAttribute("data-ready", "1");
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
const el = r.hydrated.firstElementChild!;
|
|
387
|
+
expect(el.className).toBe("a added");
|
|
388
|
+
expect(el.getAttribute("data-ready")).toBe("1");
|
|
389
|
+
// a fresh render still sets everything
|
|
390
|
+
expect(r.spa.innerHTML).toBe('<div class="a" data-k="1"></div>');
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
test("event listeners still attach to claimed elements", () => {
|
|
394
|
+
const src = `export const App = () => <button onClick={() => (globalThis.__hit = true)}>b</button>;`;
|
|
395
|
+
const r = render(src);
|
|
396
|
+
(r.hydrated.firstElementChild as HTMLElement).click();
|
|
397
|
+
expect((globalThis as Record<string, unknown>).__hit).toBe(true);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
test("inline <script> text is created on client navigation", () => {
|
|
401
|
+
const r = render(
|
|
402
|
+
`const j = '{"a":1}'; export const App = () => <div><script type="application/json">{j}</script></div>;`,
|
|
403
|
+
);
|
|
404
|
+
expect(r.ssr).toBe(
|
|
405
|
+
'<div><script type="application/json">{"a":1}</script></div>',
|
|
406
|
+
);
|
|
407
|
+
expect(r.hydrated.innerHTML).toBe(r.ssr);
|
|
408
|
+
expect(r.spa.innerHTML).toBe(r.ssr);
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
describe("JSX passed as props", () => {
|
|
413
|
+
test("a JSX prop hydrates inside the component, not over its root", () => {
|
|
414
|
+
const src = `const Dialog = ({ title, actions, children }) => (
|
|
415
|
+
<div class="dlg"><b>{title}</b><div class="body">{children}</div>{actions && <div class="acts">{actions}</div>}</div>
|
|
416
|
+
);
|
|
417
|
+
export const App = () => (
|
|
418
|
+
<section>
|
|
419
|
+
<Dialog title="t" actions={<><div class="a">x</div><div class="a">y</div></>}>
|
|
420
|
+
body
|
|
421
|
+
</Dialog>
|
|
422
|
+
</section>
|
|
423
|
+
);`;
|
|
424
|
+
const html =
|
|
425
|
+
'<section><div class="dlg"><b>t</b><div class="body">body</div><div class="acts"><div class="a">x</div><div class="a">y</div></div></div></section>';
|
|
426
|
+
const r = expectAll(src, html);
|
|
427
|
+
expect(r.hydrated.querySelectorAll(".dlg").length).toBe(1);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
test("a conditional JSX prop", () => {
|
|
431
|
+
expectAll(
|
|
432
|
+
`const on = true;
|
|
433
|
+
const Card = ({ icon }) => <div class="card">{icon}<p>t</p></div>;
|
|
434
|
+
export const App = () => <div><Card icon={on ? <i>i</i> : <b>b</b>} /></div>;`,
|
|
435
|
+
'<div><div class="card"><i>i</i><p>t</p></div></div>',
|
|
436
|
+
);
|
|
437
|
+
});
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
describe("reactive branches", () => {
|
|
441
|
+
test("a component with text children inside a reactive conditional", () => {
|
|
442
|
+
expectAll(
|
|
443
|
+
`let on = $state(true);
|
|
444
|
+
const Toast = ({ children }) => <div class="t"><span>{children}</span></div>;
|
|
445
|
+
export const App = () => (
|
|
446
|
+
<section>{on ? <Toast>Saved</Toast> : <p>none</p>}</section>
|
|
447
|
+
);`,
|
|
448
|
+
'<section><div class="t"><span>Saved</span></div></section>',
|
|
449
|
+
);
|
|
450
|
+
});
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
describe("reactive component children", () => {
|
|
454
|
+
const src = `let on = $state(true);
|
|
455
|
+
globalThis.__flip = () => { on = !on; };
|
|
456
|
+
const Box = ({ children }) => <div class="box"><h3>t</h3>{children}</div>;
|
|
457
|
+
export const App = () => (
|
|
458
|
+
<section>
|
|
459
|
+
<Box>{on ? <b>yes</b> : <i>no</i>}</Box>
|
|
460
|
+
<p>{on ? "on" : "off"}</p>
|
|
461
|
+
</section>
|
|
462
|
+
);`;
|
|
463
|
+
const flip = () => (globalThis as unknown as { __flip: () => void }).__flip();
|
|
464
|
+
|
|
465
|
+
test("update after hydration", async () => {
|
|
466
|
+
const r = render(src);
|
|
467
|
+
expect(noMarkers(r.hydrated.innerHTML)).toBe(
|
|
468
|
+
'<section><div class="box"><h3>t</h3><b>yes</b></div><p>on</p></section>',
|
|
469
|
+
);
|
|
470
|
+
// render() compiled the module three times; the last one owns __flip,
|
|
471
|
+
// and it drives the spa copy
|
|
472
|
+
flip();
|
|
473
|
+
await runtime.tick();
|
|
474
|
+
expect(noMarkers(r.spa.innerHTML)).toBe(
|
|
475
|
+
'<section><div class="box"><h3>t</h3><i>no</i></div><p>off</p></section>',
|
|
476
|
+
);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
test("update after hydration (hydrated copy)", async () => {
|
|
480
|
+
const ssr = String(compile(src, "ssr")());
|
|
481
|
+
const host = document.createElement("div");
|
|
482
|
+
host.innerHTML = ssr;
|
|
483
|
+
runtime.pushHydrationNodes(Array.from(host.childNodes));
|
|
484
|
+
compile(src, "hydrate")();
|
|
485
|
+
runtime.popHydrationNodes();
|
|
486
|
+
flip();
|
|
487
|
+
await runtime.tick();
|
|
488
|
+
expect(noMarkers(host.innerHTML)).toBe(
|
|
489
|
+
'<section><div class="box"><h3>t</h3><i>no</i></div><p>off</p></section>',
|
|
490
|
+
);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
describe("scoped CSS", () => {
|
|
495
|
+
test("the server renders the scope class the client uses", () => {
|
|
496
|
+
const r = render(
|
|
497
|
+
`const c = "x"; export const App = () => <div class="a"><p class={c}>t</p><i /></div>;`,
|
|
498
|
+
{ hash: "s1" },
|
|
499
|
+
);
|
|
500
|
+
expect(r.ssr).toBe(
|
|
501
|
+
'<div class="a s1"><p class="x s1">t</p><i class="s1"></i></div>',
|
|
502
|
+
);
|
|
503
|
+
expect(r.spa.innerHTML).toBe(r.ssr);
|
|
504
|
+
});
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
describe("$state.raw", () => {
|
|
508
|
+
test("renders on the server and updates when replaced", async () => {
|
|
509
|
+
const src = `let items = $state.raw([1, 2]);
|
|
510
|
+
globalThis.__replace = () => { items = [...items, 3]; };
|
|
511
|
+
globalThis.__mutate = () => { items.push(99); };
|
|
512
|
+
export const App = () => <p>{items.length}: {items.join(",")}</p>;`;
|
|
513
|
+
const r = expectAll(src, "<p>2: 1,2</p>");
|
|
514
|
+
const g = globalThis as unknown as Record<string, () => void>;
|
|
515
|
+
// no proxy: mutating in place is invisible to the DOM
|
|
516
|
+
g.__mutate();
|
|
517
|
+
await runtime.tick();
|
|
518
|
+
expect(noMarkers(r.spa.innerHTML)).toBe("<p>2: 1,2</p>");
|
|
519
|
+
// replacing the value is what updates it
|
|
520
|
+
g.__replace();
|
|
521
|
+
await runtime.tick();
|
|
522
|
+
expect(noMarkers(r.spa.innerHTML)).toBe("<p>4: 1,2,99,3</p>");
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
describe("keyed lists after hydration", () => {
|
|
527
|
+
// server-rendered rows carry data-key; rows the client creates don't need it
|
|
528
|
+
const plain = (html: string) =>
|
|
529
|
+
noMarkers(html).replace(/ data-key="[^"]*"/g, "");
|
|
530
|
+
const g = globalThis as unknown as Record<string, () => void>;
|
|
531
|
+
|
|
532
|
+
function hydrated(src: string) {
|
|
533
|
+
const ssr = String(compile(src, "ssr")());
|
|
534
|
+
const host = document.createElement("div");
|
|
535
|
+
host.innerHTML = ssr;
|
|
536
|
+
runtime.pushHydrationNodes(Array.from(host.childNodes));
|
|
537
|
+
compile(src, "hydrate")();
|
|
538
|
+
runtime.popHydrationNodes();
|
|
539
|
+
return host;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
test("listeners and effects inside server-rendered rows work", async () => {
|
|
543
|
+
const host =
|
|
544
|
+
hydrated(`let items = $state([{ id: 1, done: false }, { id: 2, done: false }]);
|
|
545
|
+
export const App = () => (
|
|
546
|
+
<ul>{items.map((it) => (
|
|
547
|
+
<li key={it.id}><button onClick={() => (it.done = !it.done)}>{it.done ? "done" : "todo"}</button></li>
|
|
548
|
+
))}</ul>
|
|
549
|
+
);`);
|
|
550
|
+
host.querySelectorAll("button")[1]!.click();
|
|
551
|
+
await runtime.tick();
|
|
552
|
+
expect(plain(host.innerHTML)).toBe(
|
|
553
|
+
"<ul><li><button>todo</button></li><li><button>done</button></li></ul>",
|
|
554
|
+
);
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
test("push appends a row and keeps the existing nodes", async () => {
|
|
558
|
+
const host =
|
|
559
|
+
hydrated(`let items = $state([{ id: 1, t: "a" }, { id: 2, t: "b" }]);
|
|
560
|
+
globalThis.__push = () => items.push({ id: 3, t: "c" });
|
|
561
|
+
export const App = () => <main><ul>{items.map((it) => <li key={it.id}>{it.t}</li>)}</ul><p>{items.length}</p></main>;`);
|
|
562
|
+
const before = Array.from(host.querySelectorAll("li"));
|
|
563
|
+
g.__push();
|
|
564
|
+
await runtime.tick();
|
|
565
|
+
expect(plain(host.innerHTML)).toBe(
|
|
566
|
+
"<main><ul><li>a</li><li>b</li><li>c</li></ul><p>3</p></main>",
|
|
567
|
+
);
|
|
568
|
+
const after = Array.from(host.querySelectorAll("li"));
|
|
569
|
+
expect(after[0]).toBe(before[0]);
|
|
570
|
+
expect(after[1]).toBe(before[1]);
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
const rows = `let items = $state([{ id: 1, done: false }, { id: 2, done: false }]);
|
|
574
|
+
globalThis.__push = () => items.push({ id: 3, done: false });
|
|
575
|
+
export const App = () => (
|
|
576
|
+
<ul>{items.map((it) => (
|
|
577
|
+
<li key={it.id}>
|
|
578
|
+
<input type="checkbox" bind:checked={it.done} />
|
|
579
|
+
<button onClick={() => (it.done = !it.done)}>{it.done ? "done" : "todo"}</button>
|
|
580
|
+
</li>
|
|
581
|
+
))}</ul>
|
|
582
|
+
);`;
|
|
583
|
+
const labels = (host: Element) =>
|
|
584
|
+
Array.from(host.querySelectorAll("button"), (b) => b.textContent).join(",");
|
|
585
|
+
|
|
586
|
+
for (const mode of ["hydrated", "fresh"] as const) {
|
|
587
|
+
test(`rows stay reactive, before and after a push (${mode})`, async () => {
|
|
588
|
+
let host: Element;
|
|
589
|
+
if (mode === "hydrated") host = hydrated(rows);
|
|
590
|
+
else {
|
|
591
|
+
host = document.createElement("div");
|
|
592
|
+
runtime.pushHydrationNodes([]);
|
|
593
|
+
runtime.insert(host, compile(rows, "hydrate")());
|
|
594
|
+
runtime.popHydrationNodes();
|
|
595
|
+
}
|
|
596
|
+
host.querySelectorAll("button")[1]!.click();
|
|
597
|
+
await runtime.tick();
|
|
598
|
+
expect(labels(host)).toBe("todo,done");
|
|
599
|
+
expect(host.querySelectorAll("input")[1]!.checked).toBe(true);
|
|
600
|
+
|
|
601
|
+
g.__push();
|
|
602
|
+
await runtime.tick();
|
|
603
|
+
host.querySelectorAll("button")[0]!.click();
|
|
604
|
+
await runtime.tick();
|
|
605
|
+
expect(labels(host)).toBe("done,done,todo");
|
|
606
|
+
|
|
607
|
+
// bind:checked writes back into the item
|
|
608
|
+
const box = host.querySelectorAll("input")[2]!;
|
|
609
|
+
box.checked = true;
|
|
610
|
+
box.dispatchEvent(new Event("change"));
|
|
611
|
+
await runtime.tick();
|
|
612
|
+
expect(labels(host)).toBe("done,done,done");
|
|
613
|
+
});
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
test("an element after the list is never taken for a new row", async () => {
|
|
617
|
+
const host = hydrated(`let items = $state([{ id: 1 }]);
|
|
618
|
+
globalThis.__push = () => items.push({ id: 2 });
|
|
619
|
+
export const App = () => <ul>{items.map((it) => <li key={it.id}>{it.id}</li>)}<li class="last">end</li></ul>;`);
|
|
620
|
+
g.__push();
|
|
621
|
+
await runtime.tick();
|
|
622
|
+
expect(plain(host.innerHTML)).toBe(
|
|
623
|
+
'<ul><li>1</li><li>2</li><li class="last">end</li></ul>',
|
|
624
|
+
);
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
describe("reactive props", () => {
|
|
629
|
+
const g = globalThis as unknown as Record<string, () => void>;
|
|
630
|
+
const both = async (
|
|
631
|
+
src: string,
|
|
632
|
+
html: string,
|
|
633
|
+
act: () => void,
|
|
634
|
+
after: string,
|
|
635
|
+
) => {
|
|
636
|
+
const r = expectAll(src, html);
|
|
637
|
+
act();
|
|
638
|
+
await runtime.tick();
|
|
639
|
+
// render() compiled the module three times; the last copy (spa) is
|
|
640
|
+
// the one the globals drive
|
|
641
|
+
expect(noMarkers(r.spa.innerHTML).replace(/ data-key="[^"]*"/g, "")).toBe(
|
|
642
|
+
after,
|
|
643
|
+
);
|
|
644
|
+
};
|
|
645
|
+
|
|
646
|
+
test("a destructured prop follows the state passed in", () =>
|
|
647
|
+
both(
|
|
648
|
+
`let count = $state(1);
|
|
649
|
+
globalThis.__inc = () => count++;
|
|
650
|
+
const Label = ({ text, unit = "x" }) => <b>{text}{unit}</b>;
|
|
651
|
+
export const App = () => <p><Label text={count} /></p>;`,
|
|
652
|
+
"<p><b>1x</b></p>",
|
|
653
|
+
() => g.__inc!(),
|
|
654
|
+
"<p><b>2x</b></p>",
|
|
655
|
+
));
|
|
656
|
+
|
|
657
|
+
test("props.name reads follow too", () =>
|
|
658
|
+
both(
|
|
659
|
+
`let count = $state(1);
|
|
660
|
+
globalThis.__inc = () => count++;
|
|
661
|
+
const Label = (props) => <b class={props.n > 1 ? "many" : "one"}>{props.n}</b>;
|
|
662
|
+
export const App = () => <p><Label n={count} /></p>;`,
|
|
663
|
+
'<p><b class="one">1</b></p>',
|
|
664
|
+
() => g.__inc!(),
|
|
665
|
+
'<p><b class="many">2</b></p>',
|
|
666
|
+
));
|
|
667
|
+
|
|
668
|
+
test("bind: on a prop's field writes back to the state", async () => {
|
|
669
|
+
const r = expectAll(
|
|
670
|
+
`let books = $state([{ id: 1, read: false }]);
|
|
671
|
+
const Row = ({ book }) => <li><input type="checkbox" bind:checked={book.read} />{book.read ? "read" : "unread"}</li>;
|
|
672
|
+
export const App = () => <ul>{books.map((b) => <Row key={b.id} book={b} />)}</ul>;`,
|
|
673
|
+
'<ul><li><input type="checkbox">unread</li></ul>',
|
|
674
|
+
);
|
|
675
|
+
for (const host of [r.hydrated, r.spa]) {
|
|
676
|
+
const box = host.querySelector("input")!;
|
|
677
|
+
box.checked = true;
|
|
678
|
+
box.dispatchEvent(new Event("change"));
|
|
679
|
+
await runtime.tick();
|
|
680
|
+
expect(host.querySelector("li")!.textContent).toBe("read");
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
test("a list item passed to a row component stays live", () =>
|
|
685
|
+
both(
|
|
686
|
+
`let books = $state([{ id: 1, read: false }]);
|
|
687
|
+
globalThis.__read = () => { books[0].read = true; };
|
|
688
|
+
const Row = ({ book }) => <li class={book.read ? "read" : ""}>{book.read ? "read" : "unread"}</li>;
|
|
689
|
+
export const App = () => <ul>{books.map((b) => <Row key={b.id} book={b} />)}</ul>;`,
|
|
690
|
+
'<ul><li class="">unread</li></ul>',
|
|
691
|
+
() => g.__read!(),
|
|
692
|
+
'<ul><li class="read">read</li></ul>',
|
|
693
|
+
));
|
|
694
|
+
});
|
|
695
|
+
|
|
696
|
+
describe("slots side by side", () => {
|
|
697
|
+
test("a prop slot next to a state slot keeps its own markers", async () => {
|
|
698
|
+
const g = globalThis as unknown as Record<string, () => void>;
|
|
699
|
+
const src = `let count = $state(1);
|
|
700
|
+
globalThis.__bump = () => count++;
|
|
701
|
+
const Pair = ({ n }) => {
|
|
702
|
+
let doubled = $derived(n * 2);
|
|
703
|
+
return <p>{n} / {doubled}</p>;
|
|
704
|
+
};
|
|
705
|
+
export const App = () => <Pair n={count} />;`;
|
|
706
|
+
const r = expectAll(src, "<p>1 / 2</p>");
|
|
707
|
+
g.__bump!();
|
|
708
|
+
await runtime.tick();
|
|
709
|
+
expect(noMarkers(r.spa.innerHTML)).toBe("<p>2 / 4</p>");
|
|
710
|
+
|
|
711
|
+
// and on hydrated markup with effects deferred, as grimoire hydrates
|
|
712
|
+
const host = document.createElement("div");
|
|
713
|
+
host.innerHTML = String(compile(src, "ssr")());
|
|
714
|
+
const flags = globalThis as { __sigilDeferEffects?: boolean };
|
|
715
|
+
runtime.pushHydrationNodes(Array.from(host.childNodes));
|
|
716
|
+
flags.__sigilDeferEffects = true;
|
|
717
|
+
try {
|
|
718
|
+
compile(src, "hydrate")();
|
|
719
|
+
} finally {
|
|
720
|
+
flags.__sigilDeferEffects = false;
|
|
721
|
+
runtime.popHydrationNodes();
|
|
722
|
+
}
|
|
723
|
+
runtime.flushDeferredEffects();
|
|
724
|
+
expect(noMarkers(host.innerHTML)).toBe("<p>1 / 2</p>");
|
|
725
|
+
g.__bump!();
|
|
726
|
+
await runtime.tick();
|
|
727
|
+
expect(noMarkers(host.innerHTML)).toBe("<p>2 / 4</p>");
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
|
|
731
|
+
describe("state imported from another module", () => {
|
|
732
|
+
function evalModule(
|
|
733
|
+
source: string,
|
|
734
|
+
names: string[],
|
|
735
|
+
inject: Record<string, unknown> = {},
|
|
736
|
+
) {
|
|
737
|
+
const code = transformSync(source, {
|
|
738
|
+
plugins: ["@babel/plugin-syntax-jsx", [sigilPlugin, { mode: "hydrate" }]],
|
|
739
|
+
// importers live next to the fixture stores the compiler reads
|
|
740
|
+
filename: join(import.meta.dir, "fixtures/stores/m.tsx"),
|
|
741
|
+
})!.code!;
|
|
742
|
+
const body = code
|
|
743
|
+
.replace(/import\s*\{[^}]*\}\s*from\s*["'][^"']+["'];?/g, "")
|
|
744
|
+
.replace(/^export\s+/gm, "");
|
|
745
|
+
return new Function(
|
|
746
|
+
"document",
|
|
747
|
+
...Object.keys(runtime),
|
|
748
|
+
...Object.keys(inject),
|
|
749
|
+
`${body};\nreturn { ${names.join(", ")} };`,
|
|
750
|
+
)(globalThis.document, ...Object.values(runtime), ...Object.values(inject));
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
test("JSX reading an imported $store updates", async () => {
|
|
754
|
+
const { cart } = evalModule(`export let cart = $store({ items: [] });`, [
|
|
755
|
+
"cart",
|
|
756
|
+
]);
|
|
757
|
+
const { App } = evalModule(
|
|
758
|
+
`import { cart } from "./cart";
|
|
759
|
+
export const App = () => (
|
|
760
|
+
<p class={cart.items.length ? "full" : "empty"}>
|
|
761
|
+
{cart.items.length} items: {cart.items.join(",")}
|
|
762
|
+
</p>
|
|
763
|
+
);`,
|
|
764
|
+
["App"],
|
|
765
|
+
{ cart },
|
|
766
|
+
);
|
|
767
|
+
const host = document.createElement("div");
|
|
768
|
+
runtime.pushHydrationNodes([]);
|
|
769
|
+
runtime.insert(host, App());
|
|
770
|
+
runtime.popHydrationNodes();
|
|
771
|
+
expect(noMarkers(host.innerHTML)).toBe('<p class="empty">0 items: </p>');
|
|
772
|
+
cart().items.push("a", "b");
|
|
773
|
+
await runtime.tick();
|
|
774
|
+
expect(noMarkers(host.innerHTML)).toBe('<p class="full">2 items: a,b</p>');
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
test("an imported primitive $store reads as its value", async () => {
|
|
778
|
+
const { count, bump } = evalModule(
|
|
779
|
+
`export let count = $store(0);
|
|
780
|
+
export function bump() { count++; }`,
|
|
781
|
+
["count", "bump"],
|
|
782
|
+
);
|
|
783
|
+
// the importer below is compiled against fixtures/stores/counter.ts
|
|
784
|
+
const { App } = evalModule(
|
|
785
|
+
`import { bump, count } from "./counter";
|
|
786
|
+
export const App = () => {
|
|
787
|
+
let doubled = $derived(count * 2);
|
|
788
|
+
return <p onClick={bump}>{count} / {doubled}</p>;
|
|
789
|
+
};`,
|
|
790
|
+
["App"],
|
|
791
|
+
{ count, bump },
|
|
792
|
+
);
|
|
793
|
+
const host = document.createElement("div");
|
|
794
|
+
runtime.pushHydrationNodes([]);
|
|
795
|
+
runtime.insert(host, App());
|
|
796
|
+
runtime.popHydrationNodes();
|
|
797
|
+
expect(noMarkers(host.innerHTML)).toBe("<p>0 / 0</p>");
|
|
798
|
+
(host.firstChild as HTMLElement).click();
|
|
799
|
+
bump();
|
|
800
|
+
await runtime.tick();
|
|
801
|
+
expect(noMarkers(host.innerHTML)).toBe("<p>2 / 4</p>");
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
describe("conditional fragments", () => {
|
|
806
|
+
const source = `
|
|
807
|
+
let show = $state(true);
|
|
808
|
+
globalThis.__toggle = () => (show = !show);
|
|
809
|
+
export const App = () => (
|
|
810
|
+
<div>
|
|
811
|
+
{show && (
|
|
812
|
+
<>
|
|
813
|
+
<p>one</p>
|
|
814
|
+
<p>two</p>
|
|
815
|
+
</>
|
|
816
|
+
)}
|
|
817
|
+
<p>after</p>
|
|
818
|
+
</div>
|
|
819
|
+
);`;
|
|
820
|
+
const toggle = () =>
|
|
821
|
+
(globalThis as unknown as { __toggle: () => void }).__toggle();
|
|
822
|
+
const flush = () => new Promise((r) => setTimeout(r, 0));
|
|
823
|
+
|
|
824
|
+
test("a fragment can be hidden and shown again, hydrated or fresh", async () => {
|
|
825
|
+
const r = render(source);
|
|
826
|
+
for (const host of [r.hydrated, r.spa]) {
|
|
827
|
+
expect(noMarkers(host.innerHTML)).toBe(
|
|
828
|
+
"<div><p>one</p><p>two</p><p>after</p></div>",
|
|
829
|
+
);
|
|
830
|
+
}
|
|
831
|
+
// the hydrated page and the fresh render share one compiled module each,
|
|
832
|
+
// so toggle each through its own copy of the state
|
|
833
|
+
for (const host of [r.spa]) {
|
|
834
|
+
toggle();
|
|
835
|
+
await flush();
|
|
836
|
+
expect(noMarkers(host.innerHTML)).toBe("<div><p>after</p></div>");
|
|
837
|
+
toggle();
|
|
838
|
+
await flush();
|
|
839
|
+
expect(noMarkers(host.innerHTML)).toBe(
|
|
840
|
+
"<div><p>one</p><p>two</p><p>after</p></div>",
|
|
841
|
+
);
|
|
842
|
+
toggle();
|
|
843
|
+
await flush();
|
|
844
|
+
expect(noMarkers(host.innerHTML)).toBe("<div><p>after</p></div>");
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
describe("map callbacks that take the index", () => {
|
|
850
|
+
const plain = (html: string) =>
|
|
851
|
+
noMarkers(html).replace(/ data-key="[^"]*"/g, "");
|
|
852
|
+
const g = globalThis as unknown as Record<string, () => void>;
|
|
853
|
+
|
|
854
|
+
function hydrated(src: string) {
|
|
855
|
+
const ssr = String(compile(src, "ssr")());
|
|
856
|
+
const host = document.createElement("div");
|
|
857
|
+
host.innerHTML = ssr;
|
|
858
|
+
runtime.pushHydrationNodes(Array.from(host.childNodes));
|
|
859
|
+
compile(src, "hydrate")();
|
|
860
|
+
runtime.popHydrationNodes();
|
|
861
|
+
return host;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
test("(item, i) hydrates, and a fresh render agrees", () => {
|
|
865
|
+
const r = render(`let items = $state([{ id: 7, t: "a" }, { id: 9, t: "b" }]);
|
|
866
|
+
export const App = () => <ol>{items.map((it, i) => <li key={it.id}>{i + 1}. {it.t}</li>)}</ol>;`);
|
|
867
|
+
const html = "<ol><li>1. a</li><li>2. b</li></ol>";
|
|
868
|
+
expect(plain(r.ssr)).toBe(html);
|
|
869
|
+
expect(plain(r.hydrated.innerHTML)).toBe(html);
|
|
870
|
+
expect(plain(r.spa.innerHTML)).toBe(html);
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
// The shape that blanked a real page: an index map nested in keyed rows,
|
|
874
|
+
// inside a table, with a list in each cell.
|
|
875
|
+
test("an index map inside keyed table rows hydrates in place", () => {
|
|
876
|
+
const src = `let rows = $state([
|
|
877
|
+
{ day: 1, cells: [{ who: "Ana", jobs: ["x"] }, { who: "Bo", jobs: [] }] },
|
|
878
|
+
{ day: 2, cells: [{ who: "Ana", jobs: [] }, { who: "Bo", jobs: ["y", "z"] }] },
|
|
879
|
+
]);
|
|
880
|
+
export const App = () => (
|
|
881
|
+
<table><tbody>{rows.map((r) => (
|
|
882
|
+
<tr key={r.day}><th>{r.day}</th>{r.cells.map((c, i) => (
|
|
883
|
+
<td key={i}>{c.who}:{c.jobs.map((j) => <b key={j}>{j}</b>)}</td>
|
|
884
|
+
))}</tr>
|
|
885
|
+
))}</tbody></table>
|
|
886
|
+
);`;
|
|
887
|
+
const host = hydrated(src);
|
|
888
|
+
expect(plain(host.innerHTML)).toBe(
|
|
889
|
+
"<table><tbody><tr><th>1</th><td>Ana:<b>x</b></td><td>Bo:</td></tr>" +
|
|
890
|
+
"<tr><th>2</th><td>Ana:</td><td>Bo:<b>y</b><b>z</b></td></tr></tbody></table>",
|
|
891
|
+
);
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
test("rows renumber when an item before them goes away", async () => {
|
|
895
|
+
const host = hydrated(`let items = $state([{ id: 1, t: "a" }, { id: 2, t: "b" }, { id: 3, t: "c" }]);
|
|
896
|
+
globalThis.__dropFirst = () => items.shift();
|
|
897
|
+
export const App = () => <ol>{items.map((it, i) => <li key={it.id}>{i + 1}. {it.t}</li>)}</ol>;`);
|
|
898
|
+
g.__dropFirst();
|
|
899
|
+
await runtime.tick();
|
|
900
|
+
expect(plain(host.innerHTML)).toBe("<ol><li>1. b</li><li>2. c</li></ol>");
|
|
901
|
+
});
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
test("compiler and runtime agree on the SVG attribute names", async () => {
|
|
905
|
+
const { SVG_ATTR } = await import("../src/babel/util/svg-attrs.ts");
|
|
906
|
+
expect(runtime.SVG_ATTR).toEqual(SVG_ATTR);
|
|
907
|
+
});
|