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