ripple 0.2.82 → 0.2.84
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/compiler/phases/1-parse/index.js +1151 -1062
- package/src/compiler/phases/2-analyze/index.js +561 -523
- package/src/compiler/phases/3-transform/client/index.js +105 -28
- package/src/compiler/phases/3-transform/server/index.js +1 -1
- package/src/compiler/utils.js +613 -595
- package/src/runtime/array.js +4 -0
- package/src/runtime/index-client.js +8 -2
- package/src/runtime/internal/client/constants.js +9 -8
- package/src/runtime/internal/client/head.js +14 -0
- package/src/runtime/internal/client/index.js +43 -34
- package/src/runtime/internal/client/operations.js +34 -30
- package/src/runtime/internal/client/runtime.js +30 -29
- package/src/utils/builders.js +1 -0
- package/tests/client/basic.test.ripple +130 -22
- package/types/index.d.ts +6 -11
|
@@ -7,963 +7,1052 @@ import { regex_newline_characters } from '../../../utils/patterns.js';
|
|
|
7
7
|
const parser = acorn.Parser.extend(tsPlugin({ allowSatisfies: true }), RipplePlugin());
|
|
8
8
|
|
|
9
9
|
function convert_from_jsx(node) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
if (node.type === 'JSXIdentifier') {
|
|
11
|
+
node.type = 'Identifier';
|
|
12
|
+
} else if (node.type === 'JSXMemberExpression') {
|
|
13
|
+
node.type = 'MemberExpression';
|
|
14
|
+
node.object = convert_from_jsx(node.object);
|
|
15
|
+
node.property = convert_from_jsx(node.property);
|
|
16
|
+
}
|
|
17
|
+
return node;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function RipplePlugin(config) {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
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
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
21
|
+
return (Parser) => {
|
|
22
|
+
const original = acorn.Parser.prototype;
|
|
23
|
+
const tt = Parser.tokTypes || acorn.tokTypes;
|
|
24
|
+
const tc = Parser.tokContexts || acorn.tokContexts;
|
|
25
|
+
|
|
26
|
+
class RippleParser extends Parser {
|
|
27
|
+
#path = [];
|
|
28
|
+
|
|
29
|
+
// Helper method to get the element name from a JSX identifier or member expression
|
|
30
|
+
getElementName(node) {
|
|
31
|
+
if (!node) return null;
|
|
32
|
+
if (node.type === 'Identifier' || node.type === 'JSXIdentifier') {
|
|
33
|
+
return node.name;
|
|
34
|
+
} else if (node.type === 'MemberExpression' || node.type === 'JSXMemberExpression') {
|
|
35
|
+
// For components like <Foo.Bar>, return "Foo.Bar"
|
|
36
|
+
return this.getElementName(node.object) + '.' + this.getElementName(node.property);
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getTokenFromCode(code) {
|
|
42
|
+
if (code === 60) {
|
|
43
|
+
// < character
|
|
44
|
+
if (this.#path.findLast((n) => n.type === 'Component')) {
|
|
45
|
+
// Check if everything before this position on the current line is whitespace
|
|
46
|
+
let lineStart = this.pos - 1;
|
|
47
|
+
while (
|
|
48
|
+
lineStart >= 0 &&
|
|
49
|
+
this.input.charCodeAt(lineStart) !== 10 &&
|
|
50
|
+
this.input.charCodeAt(lineStart) !== 13
|
|
51
|
+
) {
|
|
52
|
+
lineStart--;
|
|
53
|
+
}
|
|
54
|
+
lineStart++; // Move past the newline character
|
|
55
|
+
|
|
56
|
+
// Check if all characters from line start to current position are whitespace
|
|
57
|
+
let allWhitespace = true;
|
|
58
|
+
for (let i = lineStart; i < this.pos; i++) {
|
|
59
|
+
const ch = this.input.charCodeAt(i);
|
|
60
|
+
if (ch !== 32 && ch !== 9) {
|
|
61
|
+
allWhitespace = false;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Check if the character after < is not whitespace
|
|
67
|
+
if (allWhitespace && this.pos + 1 < this.input.length) {
|
|
68
|
+
const nextChar = this.input.charCodeAt(this.pos + 1);
|
|
69
|
+
if (nextChar !== 32 && nextChar !== 9 && nextChar !== 10 && nextChar !== 13) {
|
|
70
|
+
const tokTypes = this.acornTypeScript.tokTypes;
|
|
71
|
+
++this.pos;
|
|
72
|
+
return this.finishToken(tokTypes.jsxTagStart);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (code === 35) {
|
|
79
|
+
// # character
|
|
80
|
+
// Look ahead to see if this is followed by [ for tuple syntax
|
|
81
|
+
if (this.pos + 1 < this.input.length) {
|
|
82
|
+
const nextChar = this.input.charCodeAt(this.pos + 1);
|
|
83
|
+
if (nextChar === 91) {
|
|
84
|
+
// [ character
|
|
85
|
+
// This is a tuple literal #[
|
|
86
|
+
// Consume both # and [
|
|
87
|
+
++this.pos; // consume #
|
|
88
|
+
++this.pos; // consume [
|
|
89
|
+
return this.finishToken(tt.bracketL, '#[');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (code === 64) {
|
|
95
|
+
// @ character
|
|
96
|
+
// Look ahead to see if this is followed by a valid identifier character
|
|
97
|
+
if (this.pos + 1 < this.input.length) {
|
|
98
|
+
const nextChar = this.input.charCodeAt(this.pos + 1);
|
|
99
|
+
// Check if the next character can start an identifier
|
|
100
|
+
if (
|
|
101
|
+
(nextChar >= 65 && nextChar <= 90) || // A-Z
|
|
102
|
+
(nextChar >= 97 && nextChar <= 122) || // a-z
|
|
103
|
+
nextChar === 95 ||
|
|
104
|
+
nextChar === 36
|
|
105
|
+
) {
|
|
106
|
+
// _ or $
|
|
107
|
+
|
|
108
|
+
// Check if we're in an expression context
|
|
109
|
+
// In JSX expressions, inside parentheses, assignments, etc.
|
|
110
|
+
// we want to treat @ as an identifier prefix rather than decorator
|
|
111
|
+
const currentType = this.type;
|
|
112
|
+
const inExpression =
|
|
113
|
+
this.exprAllowed ||
|
|
114
|
+
currentType === tt.braceL || // Inside { }
|
|
115
|
+
currentType === tt.parenL || // Inside ( )
|
|
116
|
+
currentType === tt.eq || // After =
|
|
117
|
+
currentType === tt.comma || // After ,
|
|
118
|
+
currentType === tt.colon || // After :
|
|
119
|
+
currentType === tt.question || // After ?
|
|
120
|
+
currentType === tt.logicalOR || // After ||
|
|
121
|
+
currentType === tt.logicalAND || // After &&
|
|
122
|
+
currentType === tt.dot || // After . (for member expressions like obj.@prop)
|
|
123
|
+
currentType === tt.questionDot; // After ?. (for optional chaining like obj?.@prop)
|
|
124
|
+
|
|
125
|
+
if (inExpression) {
|
|
126
|
+
return this.readAtIdentifier();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return super.getTokenFromCode(code);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Read an @ prefixed identifier
|
|
135
|
+
readAtIdentifier() {
|
|
136
|
+
const start = this.pos;
|
|
137
|
+
this.pos++; // skip '@'
|
|
138
|
+
|
|
139
|
+
// Read the identifier part manually
|
|
140
|
+
let word = '';
|
|
141
|
+
while (this.pos < this.input.length) {
|
|
142
|
+
const ch = this.input.charCodeAt(this.pos);
|
|
143
|
+
if (
|
|
144
|
+
(ch >= 65 && ch <= 90) || // A-Z
|
|
145
|
+
(ch >= 97 && ch <= 122) || // a-z
|
|
146
|
+
(ch >= 48 && ch <= 57) || // 0-9
|
|
147
|
+
ch === 95 ||
|
|
148
|
+
ch === 36
|
|
149
|
+
) {
|
|
150
|
+
// _ or $
|
|
151
|
+
word += this.input[this.pos++];
|
|
152
|
+
} else {
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (word === '') {
|
|
158
|
+
this.raise(start, 'Invalid @ identifier');
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Return the full identifier including @
|
|
162
|
+
return this.finishToken(tt.name, '@' + word);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Override parseIdent to mark @ identifiers as tracked
|
|
166
|
+
parseIdent(liberal) {
|
|
167
|
+
const node = super.parseIdent(liberal);
|
|
168
|
+
if (node.name && node.name.startsWith('@')) {
|
|
169
|
+
node.name = node.name.slice(1); // Remove the '@' for internal use
|
|
170
|
+
node.tracked = true;
|
|
171
|
+
node.start++;
|
|
172
|
+
const prev_pos = this.pos;
|
|
173
|
+
this.pos = node.start;
|
|
174
|
+
node.loc.start = this.curPosition();
|
|
175
|
+
this.pos = prev_pos;
|
|
176
|
+
}
|
|
177
|
+
return node;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
parseExprAtom(refDestructuringErrors, forNew, forInit) {
|
|
181
|
+
// Check if this is a tuple literal starting with #[
|
|
182
|
+
if (this.type === tt.bracketL && this.value === '#[') {
|
|
183
|
+
return this.parseTrackedArrayExpression();
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return super.parseExprAtom(refDestructuringErrors, forNew, forInit);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
parseTrackedArrayExpression() {
|
|
190
|
+
const node = this.startNode();
|
|
191
|
+
this.next(); // consume the '#['
|
|
192
|
+
|
|
193
|
+
node.elements = [];
|
|
194
|
+
|
|
195
|
+
// Parse array elements similar to regular array parsing
|
|
196
|
+
let first = true;
|
|
197
|
+
while (!this.eat(tt.bracketR)) {
|
|
198
|
+
if (!first) {
|
|
199
|
+
this.expect(tt.comma);
|
|
200
|
+
if (this.afterTrailingComma(tt.bracketR)) break;
|
|
201
|
+
} else {
|
|
202
|
+
first = false;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (this.type === tt.comma) {
|
|
206
|
+
// Hole in array
|
|
207
|
+
node.elements.push(null);
|
|
208
|
+
} else if (this.type === tt.ellipsis) {
|
|
209
|
+
// Spread element
|
|
210
|
+
const element = this.parseSpread();
|
|
211
|
+
node.elements.push(element);
|
|
212
|
+
if (this.type === tt.comma && this.input.charCodeAt(this.pos) === 93) {
|
|
213
|
+
this.raise(this.pos, 'Trailing comma is not permitted after the rest element');
|
|
214
|
+
}
|
|
215
|
+
} else {
|
|
216
|
+
// Regular element
|
|
217
|
+
node.elements.push(this.parseMaybeAssign(false));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return this.finishNode(node, 'TrackedArrayExpression');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
parseExportDefaultDeclaration() {
|
|
225
|
+
// Check if this is "export default component"
|
|
226
|
+
if (this.value === 'component') {
|
|
227
|
+
const node = this.startNode();
|
|
228
|
+
node.type = 'Component';
|
|
229
|
+
node.css = null;
|
|
230
|
+
node.default = true;
|
|
231
|
+
this.next();
|
|
232
|
+
this.enterScope(0);
|
|
233
|
+
|
|
234
|
+
node.id = this.type.label === 'name' ? this.parseIdent() : null;
|
|
235
|
+
|
|
236
|
+
this.parseFunctionParams(node);
|
|
237
|
+
this.eat(tt.braceL);
|
|
238
|
+
node.body = [];
|
|
239
|
+
this.#path.push(node);
|
|
240
|
+
|
|
241
|
+
this.parseTemplateBody(node.body);
|
|
242
|
+
this.#path.pop();
|
|
243
|
+
this.exitScope();
|
|
244
|
+
|
|
245
|
+
this.next();
|
|
246
|
+
this.finishNode(node, 'Component');
|
|
247
|
+
this.awaitPos = 0;
|
|
248
|
+
|
|
249
|
+
return node;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
return super.parseExportDefaultDeclaration();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
parseForStatement(node) {
|
|
256
|
+
this.next();
|
|
257
|
+
let awaitAt =
|
|
258
|
+
this.options.ecmaVersion >= 9 && this.canAwait && this.eatContextual('await')
|
|
259
|
+
? this.lastTokStart
|
|
260
|
+
: -1;
|
|
261
|
+
this.labels.push({ kind: 'loop' });
|
|
262
|
+
this.enterScope(0);
|
|
263
|
+
this.expect(tt.parenL);
|
|
264
|
+
|
|
265
|
+
if (this.type === tt.semi) {
|
|
266
|
+
if (awaitAt > -1) this.unexpected(awaitAt);
|
|
267
|
+
return this.parseFor(node, null);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
let isLet = this.isLet();
|
|
271
|
+
if (this.type === tt._var || this.type === tt._const || isLet) {
|
|
272
|
+
let init = this.startNode(),
|
|
273
|
+
kind = isLet ? 'let' : this.value;
|
|
274
|
+
this.next();
|
|
275
|
+
this.parseVar(init, true, kind);
|
|
276
|
+
this.finishNode(init, 'VariableDeclaration');
|
|
277
|
+
return this.parseForAfterInitWithIndex(node, init, awaitAt);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Handle other cases like using declarations if they exist
|
|
281
|
+
let startsWithLet = this.isContextual('let'),
|
|
282
|
+
isForOf = false;
|
|
283
|
+
let usingKind =
|
|
284
|
+
this.isUsing && this.isUsing(true)
|
|
285
|
+
? 'using'
|
|
286
|
+
: this.isAwaitUsing && this.isAwaitUsing(true)
|
|
287
|
+
? 'await using'
|
|
288
|
+
: null;
|
|
289
|
+
if (usingKind) {
|
|
290
|
+
let init = this.startNode();
|
|
291
|
+
this.next();
|
|
292
|
+
if (usingKind === 'await using') {
|
|
293
|
+
if (!this.canAwait) {
|
|
294
|
+
this.raise(this.start, 'Await using cannot appear outside of async function');
|
|
295
|
+
}
|
|
296
|
+
this.next();
|
|
297
|
+
}
|
|
298
|
+
this.parseVar(init, true, usingKind);
|
|
299
|
+
this.finishNode(init, 'VariableDeclaration');
|
|
300
|
+
return this.parseForAfterInitWithIndex(node, init, awaitAt);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
let containsEsc = this.containsEsc;
|
|
304
|
+
let refDestructuringErrors = {};
|
|
305
|
+
let initPos = this.start;
|
|
306
|
+
let init =
|
|
307
|
+
awaitAt > -1
|
|
308
|
+
? this.parseExprSubscripts(refDestructuringErrors, 'await')
|
|
309
|
+
: this.parseExpression(true, refDestructuringErrors);
|
|
310
|
+
|
|
311
|
+
if (
|
|
312
|
+
this.type === tt._in ||
|
|
313
|
+
(isForOf = this.options.ecmaVersion >= 6 && this.isContextual('of'))
|
|
314
|
+
) {
|
|
315
|
+
if (awaitAt > -1) {
|
|
316
|
+
// implies `ecmaVersion >= 9`
|
|
317
|
+
if (this.type === tt._in) this.unexpected(awaitAt);
|
|
318
|
+
node.await = true;
|
|
319
|
+
} else if (isForOf && this.options.ecmaVersion >= 8) {
|
|
320
|
+
if (
|
|
321
|
+
init.start === initPos &&
|
|
322
|
+
!containsEsc &&
|
|
323
|
+
init.type === 'Identifier' &&
|
|
324
|
+
init.name === 'async'
|
|
325
|
+
)
|
|
326
|
+
this.unexpected();
|
|
327
|
+
else if (this.options.ecmaVersion >= 9) node.await = false;
|
|
328
|
+
}
|
|
329
|
+
if (startsWithLet && isForOf)
|
|
330
|
+
this.raise(init.start, "The left-hand side of a for-of loop may not start with 'let'.");
|
|
331
|
+
this.toAssignable(init, false, refDestructuringErrors);
|
|
332
|
+
this.checkLValPattern(init);
|
|
333
|
+
return this.parseForInWithIndex(node, init);
|
|
334
|
+
} else {
|
|
335
|
+
this.checkExpressionErrors(refDestructuringErrors, true);
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (awaitAt > -1) this.unexpected(awaitAt);
|
|
339
|
+
return this.parseFor(node, init);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
parseForAfterInitWithIndex(node, init, awaitAt) {
|
|
343
|
+
if (
|
|
344
|
+
(this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual('of'))) &&
|
|
345
|
+
init.declarations.length === 1
|
|
346
|
+
) {
|
|
347
|
+
if (this.options.ecmaVersion >= 9) {
|
|
348
|
+
if (this.type === tt._in) {
|
|
349
|
+
if (awaitAt > -1) this.unexpected(awaitAt);
|
|
350
|
+
} else node.await = awaitAt > -1;
|
|
351
|
+
}
|
|
352
|
+
return this.parseForInWithIndex(node, init);
|
|
353
|
+
}
|
|
354
|
+
if (awaitAt > -1) this.unexpected(awaitAt);
|
|
355
|
+
return this.parseFor(node, init);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
parseForInWithIndex(node, init) {
|
|
359
|
+
const isForIn = this.type === tt._in;
|
|
360
|
+
this.next();
|
|
361
|
+
|
|
362
|
+
if (
|
|
363
|
+
init.type === 'VariableDeclaration' &&
|
|
364
|
+
init.declarations[0].init != null &&
|
|
365
|
+
(!isForIn ||
|
|
366
|
+
this.options.ecmaVersion < 8 ||
|
|
367
|
+
this.strict ||
|
|
368
|
+
init.kind !== 'var' ||
|
|
369
|
+
init.declarations[0].id.type !== 'Identifier')
|
|
370
|
+
) {
|
|
371
|
+
this.raise(
|
|
372
|
+
init.start,
|
|
373
|
+
`${isForIn ? 'for-in' : 'for-of'} loop variable declaration may not have an initializer`,
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
node.left = init;
|
|
378
|
+
node.right = isForIn ? this.parseExpression() : this.parseMaybeAssign();
|
|
379
|
+
|
|
380
|
+
// Check for our extended syntax: "; index varName"
|
|
381
|
+
if (!isForIn && this.type === tt.semi) {
|
|
382
|
+
this.next(); // consume ';'
|
|
383
|
+
|
|
384
|
+
if (this.isContextual('index')) {
|
|
385
|
+
this.next(); // consume 'index'
|
|
386
|
+
|
|
387
|
+
if (this.type === tt.name) {
|
|
388
|
+
node.index = this.parseIdent();
|
|
389
|
+
} else {
|
|
390
|
+
this.raise(this.start, 'Expected identifier after "index" keyword');
|
|
391
|
+
}
|
|
392
|
+
} else {
|
|
393
|
+
this.raise(this.start, 'Expected "index" keyword after semicolon in for-of loop');
|
|
394
|
+
}
|
|
395
|
+
} else if (!isForIn) {
|
|
396
|
+
// Set index to null for standard for-of loops
|
|
397
|
+
node.index = null;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
this.expect(tt.parenR);
|
|
401
|
+
node.body = this.parseStatement('for');
|
|
402
|
+
this.exitScope();
|
|
403
|
+
this.labels.pop();
|
|
404
|
+
return this.finishNode(node, isForIn ? 'ForInStatement' : 'ForOfStatement');
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
shouldParseExportStatement() {
|
|
408
|
+
if (super.shouldParseExportStatement()) {
|
|
409
|
+
return true;
|
|
410
|
+
}
|
|
411
|
+
if (this.value === 'component') {
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
return this.type.keyword === 'var';
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
jsx_parseExpressionContainer() {
|
|
418
|
+
let node = this.startNode();
|
|
419
|
+
this.next();
|
|
420
|
+
|
|
421
|
+
node.expression =
|
|
422
|
+
this.type === tt.braceR ? this.jsx_parseEmptyExpression() : this.parseExpression();
|
|
423
|
+
this.expect(tt.braceR);
|
|
424
|
+
return this.finishNode(node, 'JSXExpressionContainer');
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
jsx_parseTupleContainer() {
|
|
428
|
+
var t = this.startNode();
|
|
429
|
+
return (
|
|
430
|
+
this.next(),
|
|
431
|
+
(t.expression =
|
|
432
|
+
this.type === tt.bracketR ? this.jsx_parseEmptyExpression() : this.parseExpression()),
|
|
433
|
+
this.expect(tt.bracketR),
|
|
434
|
+
this.finishNode(t, 'JSXExpressionContainer')
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
jsx_parseAttribute() {
|
|
439
|
+
let node = this.startNode();
|
|
440
|
+
|
|
441
|
+
if (this.eat(tt.braceL)) {
|
|
442
|
+
if (this.value === 'ref') {
|
|
443
|
+
this.next();
|
|
444
|
+
if (this.type === tt.braceR) {
|
|
445
|
+
this.raise(
|
|
446
|
+
this.start,
|
|
447
|
+
'"ref" is a Ripple keyword and must be used in the form {ref fn}',
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
node.argument = this.parseMaybeAssign();
|
|
451
|
+
this.expect(tt.braceR);
|
|
452
|
+
return this.finishNode(node, 'RefAttribute');
|
|
453
|
+
} else if (this.type === tt.ellipsis) {
|
|
454
|
+
this.expect(tt.ellipsis);
|
|
455
|
+
node.argument = this.parseMaybeAssign();
|
|
456
|
+
this.expect(tt.braceR);
|
|
457
|
+
return this.finishNode(node, 'SpreadAttribute');
|
|
458
|
+
} else if (this.lookahead().type === tt.ellipsis) {
|
|
459
|
+
this.expect(tt.ellipsis);
|
|
460
|
+
node.argument = this.parseMaybeAssign();
|
|
461
|
+
this.expect(tt.braceR);
|
|
462
|
+
return this.finishNode(node, 'SpreadAttribute');
|
|
463
|
+
} else {
|
|
464
|
+
const id = this.parseIdentNode();
|
|
465
|
+
id.tracked = false;
|
|
466
|
+
if (id.name.startsWith('@')) {
|
|
467
|
+
id.tracked = true;
|
|
468
|
+
id.name = id.name.slice(1);
|
|
469
|
+
}
|
|
470
|
+
this.finishNode(id, 'Identifier');
|
|
471
|
+
node.name = id;
|
|
472
|
+
node.value = id;
|
|
473
|
+
this.next();
|
|
474
|
+
this.expect(tt.braceR);
|
|
475
|
+
return this.finishNode(node, 'Attribute');
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
node.name = this.jsx_parseNamespacedName();
|
|
479
|
+
node.value = this.eat(tt.eq) ? this.jsx_parseAttributeValue() : null;
|
|
480
|
+
return this.finishNode(node, 'JSXAttribute');
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
jsx_parseNamespacedName() {
|
|
484
|
+
const base = this.jsx_parseIdentifier();
|
|
485
|
+
if (!this.eat(tt.colon)) return base;
|
|
486
|
+
const node = this.startNodeAt(base.start, base.loc.start);
|
|
487
|
+
node.namespace = base;
|
|
488
|
+
node.name = this.jsx_parseIdentifier();
|
|
489
|
+
return this.finishNode(node, 'JSXNamespacedName');
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
jsx_parseIdentifier() {
|
|
493
|
+
const node = this.startNode();
|
|
494
|
+
|
|
495
|
+
if (this.type.label === '@') {
|
|
496
|
+
this.next(); // consume @
|
|
497
|
+
|
|
498
|
+
if (this.type === tt.name || this.type.label === 'jsxName') {
|
|
499
|
+
node.name = this.value;
|
|
500
|
+
node.tracked = true;
|
|
501
|
+
this.next();
|
|
502
|
+
} else {
|
|
503
|
+
// Unexpected token after @
|
|
504
|
+
this.unexpected();
|
|
505
|
+
}
|
|
506
|
+
} else if (
|
|
507
|
+
(this.type === tt.name || this.type.label === 'jsxName') &&
|
|
508
|
+
this.value &&
|
|
509
|
+
this.value.startsWith('@')
|
|
510
|
+
) {
|
|
511
|
+
node.name = this.value.substring(1);
|
|
512
|
+
node.tracked = true;
|
|
513
|
+
this.next();
|
|
514
|
+
} else if (this.type === tt.name || this.type.keyword || this.type.label === 'jsxName') {
|
|
515
|
+
node.name = this.value;
|
|
516
|
+
node.tracked = false; // Explicitly mark as not tracked
|
|
517
|
+
this.next();
|
|
518
|
+
} else {
|
|
519
|
+
return super.jsx_parseIdentifier();
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return this.finishNode(node, 'JSXIdentifier');
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// Override jsx_parseElementName to support @ syntax in member expressions
|
|
526
|
+
jsx_parseElementName() {
|
|
527
|
+
let node = this.jsx_parseIdentifier();
|
|
528
|
+
if (this.eat(tt.dot)) {
|
|
529
|
+
let memberExpr = this.startNodeAt(node.start, node.loc && node.loc.start);
|
|
530
|
+
memberExpr.object = node;
|
|
531
|
+
memberExpr.property = this.jsx_parseIdentifier();
|
|
532
|
+
memberExpr.computed = false;
|
|
533
|
+
while (this.eat(tt.dot)) {
|
|
534
|
+
let newMemberExpr = this.startNodeAt(
|
|
535
|
+
memberExpr.start,
|
|
536
|
+
memberExpr.loc && memberExpr.loc.start,
|
|
537
|
+
);
|
|
538
|
+
newMemberExpr.object = memberExpr;
|
|
539
|
+
newMemberExpr.property = this.jsx_parseIdentifier();
|
|
540
|
+
newMemberExpr.computed = false;
|
|
541
|
+
memberExpr = this.finishNode(newMemberExpr, 'JSXMemberExpression');
|
|
542
|
+
}
|
|
543
|
+
return this.finishNode(memberExpr, 'JSXMemberExpression');
|
|
544
|
+
}
|
|
545
|
+
return node;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
jsx_parseAttributeValue() {
|
|
549
|
+
const tok = this.acornTypeScript.tokTypes;
|
|
550
|
+
|
|
551
|
+
switch (this.type) {
|
|
552
|
+
case tt.braceL:
|
|
553
|
+
var t = this.jsx_parseExpressionContainer();
|
|
554
|
+
return (
|
|
555
|
+
'JSXEmptyExpression' === t.expression.type &&
|
|
556
|
+
this.raise(t.start, 'attributes must only be assigned a non-empty expression'),
|
|
557
|
+
t
|
|
558
|
+
);
|
|
559
|
+
case tok.jsxTagStart:
|
|
560
|
+
case tt.string:
|
|
561
|
+
return this.parseExprAtom();
|
|
562
|
+
default:
|
|
563
|
+
this.raise(this.start, 'value should be either an expression or a quoted text');
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
parseTryStatement(node) {
|
|
568
|
+
this.next();
|
|
569
|
+
node.block = this.parseBlock();
|
|
570
|
+
node.handler = null;
|
|
571
|
+
|
|
572
|
+
if (this.value === 'pending') {
|
|
573
|
+
this.next();
|
|
574
|
+
node.pending = this.parseBlock();
|
|
575
|
+
} else {
|
|
576
|
+
node.pending = null;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
if (this.type === tt._catch) {
|
|
580
|
+
var clause = this.startNode();
|
|
581
|
+
this.next();
|
|
582
|
+
if (this.eat(tt.parenL)) {
|
|
583
|
+
clause.param = this.parseCatchClauseParam();
|
|
584
|
+
} else {
|
|
585
|
+
if (this.options.ecmaVersion < 10) {
|
|
586
|
+
this.unexpected();
|
|
587
|
+
}
|
|
588
|
+
clause.param = null;
|
|
589
|
+
this.enterScope(0);
|
|
590
|
+
}
|
|
591
|
+
clause.body = this.parseBlock(false);
|
|
592
|
+
this.exitScope();
|
|
593
|
+
node.handler = this.finishNode(clause, 'CatchClause');
|
|
594
|
+
}
|
|
595
|
+
node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null;
|
|
596
|
+
|
|
597
|
+
if (!node.handler && !node.finalizer && !node.pending) {
|
|
598
|
+
this.raise(node.start, 'Missing catch or finally clause');
|
|
599
|
+
}
|
|
600
|
+
return this.finishNode(node, 'TryStatement');
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
jsx_readToken() {
|
|
604
|
+
let out = '',
|
|
605
|
+
chunkStart = this.pos;
|
|
606
|
+
const tok = this.acornTypeScript.tokTypes;
|
|
607
|
+
|
|
608
|
+
for (;;) {
|
|
609
|
+
if (this.pos >= this.input.length) this.raise(this.start, 'Unterminated JSX contents');
|
|
610
|
+
let ch = this.input.charCodeAt(this.pos);
|
|
611
|
+
|
|
612
|
+
switch (ch) {
|
|
613
|
+
case 60: // '<'
|
|
614
|
+
case 123: // '{'
|
|
615
|
+
if (ch === 60 && this.exprAllowed) {
|
|
616
|
+
++this.pos;
|
|
617
|
+
return this.finishToken(tok.jsxTagStart);
|
|
618
|
+
}
|
|
619
|
+
if (ch === 123 && this.exprAllowed) {
|
|
620
|
+
return this.getTokenFromCode(ch);
|
|
621
|
+
}
|
|
622
|
+
throw new Error('TODO: Invalid syntax');
|
|
623
|
+
|
|
624
|
+
case 47: // '/'
|
|
625
|
+
// Check if this is a comment (// or /*)
|
|
626
|
+
if (this.input.charCodeAt(this.pos + 1) === 47) {
|
|
627
|
+
// '//'
|
|
628
|
+
// Line comment - handle it properly
|
|
629
|
+
const commentStart = this.pos;
|
|
630
|
+
const startLoc = this.curPosition();
|
|
631
|
+
this.pos += 2;
|
|
632
|
+
|
|
633
|
+
let commentText = '';
|
|
634
|
+
while (this.pos < this.input.length) {
|
|
635
|
+
const nextCh = this.input.charCodeAt(this.pos);
|
|
636
|
+
if (acorn.isNewLine(nextCh)) break;
|
|
637
|
+
commentText += this.input[this.pos];
|
|
638
|
+
this.pos++;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
const commentEnd = this.pos;
|
|
642
|
+
const endLoc = this.curPosition();
|
|
643
|
+
|
|
644
|
+
// Call onComment if it exists
|
|
645
|
+
if (this.options.onComment) {
|
|
646
|
+
this.options.onComment(
|
|
647
|
+
false,
|
|
648
|
+
commentText,
|
|
649
|
+
commentStart,
|
|
650
|
+
commentEnd,
|
|
651
|
+
startLoc,
|
|
652
|
+
endLoc,
|
|
653
|
+
);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// Continue processing from current position
|
|
657
|
+
break;
|
|
658
|
+
} else if (this.input.charCodeAt(this.pos + 1) === 42) {
|
|
659
|
+
// '/*'
|
|
660
|
+
// Block comment - handle it properly
|
|
661
|
+
const commentStart = this.pos;
|
|
662
|
+
const startLoc = this.curPosition();
|
|
663
|
+
this.pos += 2;
|
|
664
|
+
|
|
665
|
+
let commentText = '';
|
|
666
|
+
while (this.pos < this.input.length - 1) {
|
|
667
|
+
if (
|
|
668
|
+
this.input.charCodeAt(this.pos) === 42 &&
|
|
669
|
+
this.input.charCodeAt(this.pos + 1) === 47
|
|
670
|
+
) {
|
|
671
|
+
this.pos += 2;
|
|
672
|
+
break;
|
|
673
|
+
}
|
|
674
|
+
commentText += this.input[this.pos];
|
|
675
|
+
this.pos++;
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
const commentEnd = this.pos;
|
|
679
|
+
const endLoc = this.curPosition();
|
|
680
|
+
|
|
681
|
+
// Call onComment if it exists
|
|
682
|
+
if (this.options.onComment) {
|
|
683
|
+
this.options.onComment(
|
|
684
|
+
true,
|
|
685
|
+
commentText,
|
|
686
|
+
commentStart,
|
|
687
|
+
commentEnd,
|
|
688
|
+
startLoc,
|
|
689
|
+
endLoc,
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
// Continue processing from current position
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
// If not a comment, fall through to default case
|
|
697
|
+
this.context.push(tc.b_stat);
|
|
698
|
+
this.exprAllowed = true;
|
|
699
|
+
return original.readToken.call(this, ch);
|
|
700
|
+
|
|
701
|
+
case 38: // '&'
|
|
702
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
703
|
+
out += this.jsx_readEntity();
|
|
704
|
+
chunkStart = this.pos;
|
|
705
|
+
break;
|
|
706
|
+
|
|
707
|
+
case 62: // '>'
|
|
708
|
+
case 125: {
|
|
709
|
+
// '}'
|
|
710
|
+
if (
|
|
711
|
+
ch === 125 &&
|
|
712
|
+
(this.#path.length === 0 ||
|
|
713
|
+
this.#path.at(-1)?.type === 'Component' ||
|
|
714
|
+
this.#path.at(-1)?.type === 'Element')
|
|
715
|
+
) {
|
|
716
|
+
return original.readToken.call(this, ch);
|
|
717
|
+
}
|
|
718
|
+
this.raise(
|
|
719
|
+
this.pos,
|
|
720
|
+
'Unexpected token `' +
|
|
721
|
+
this.input[this.pos] +
|
|
722
|
+
'`. Did you mean `' +
|
|
723
|
+
(ch === 62 ? '>' : '}') +
|
|
724
|
+
'` or ' +
|
|
725
|
+
'`{"' +
|
|
726
|
+
this.input[this.pos] +
|
|
727
|
+
'"}' +
|
|
728
|
+
'`?',
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
default:
|
|
733
|
+
if (acorn.isNewLine(ch)) {
|
|
734
|
+
out += this.input.slice(chunkStart, this.pos);
|
|
735
|
+
out += this.jsx_readNewLine(true);
|
|
736
|
+
chunkStart = this.pos;
|
|
737
|
+
} else if (ch === 32 || ch === 9) {
|
|
738
|
+
++this.pos;
|
|
739
|
+
} else {
|
|
740
|
+
this.context.push(tc.b_stat);
|
|
741
|
+
this.exprAllowed = true;
|
|
742
|
+
return original.readToken.call(this, ch);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
parseElement() {
|
|
749
|
+
const inside_head = this.#path.findLast(
|
|
750
|
+
(n) => n.type === 'Element' && n.id.type === 'Identifier' && n.id.name === 'head',
|
|
751
|
+
);
|
|
752
|
+
const tok = this.acornTypeScript.tokTypes;
|
|
753
|
+
// Adjust the start so we capture the `<` as part of the element
|
|
754
|
+
const prev_pos = this.pos;
|
|
755
|
+
this.pos = this.start - 1;
|
|
756
|
+
const position = this.curPosition();
|
|
757
|
+
this.pos = prev_pos;
|
|
758
|
+
|
|
759
|
+
const element = this.startNode();
|
|
760
|
+
element.start = position.index;
|
|
761
|
+
element.loc.start = position;
|
|
762
|
+
element.type = 'Element';
|
|
763
|
+
this.#path.push(element);
|
|
764
|
+
element.children = [];
|
|
765
|
+
const open = this.jsx_parseOpeningElementAt();
|
|
766
|
+
for (const attr of open.attributes) {
|
|
767
|
+
if (attr.type === 'JSXAttribute') {
|
|
768
|
+
attr.type = 'Attribute';
|
|
769
|
+
if (attr.name.type === 'JSXIdentifier') {
|
|
770
|
+
attr.name.type = 'Identifier';
|
|
771
|
+
}
|
|
772
|
+
if (attr.value !== null) {
|
|
773
|
+
if (attr.value.type === 'JSXExpressionContainer') {
|
|
774
|
+
attr.value = attr.value.expression;
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (open.name.type === 'JSXIdentifier') {
|
|
780
|
+
open.name.type = 'Identifier';
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
element.id = convert_from_jsx(open.name);
|
|
784
|
+
element.attributes = open.attributes;
|
|
785
|
+
element.selfClosing = open.selfClosing;
|
|
786
|
+
element.metadata = {};
|
|
787
|
+
|
|
788
|
+
if (element.selfClosing) {
|
|
789
|
+
this.#path.pop();
|
|
790
|
+
|
|
791
|
+
if (this.type.label === '</>/<=/>=') {
|
|
792
|
+
this.pos--;
|
|
793
|
+
this.next();
|
|
794
|
+
}
|
|
795
|
+
} else {
|
|
796
|
+
if (open.name.name === 'style') {
|
|
797
|
+
// jsx_parseOpeningElementAt treats ID selectors (ie. #myid) or type selectors (ie. div) as identifier and read it
|
|
798
|
+
// So backtrack to the end of the <style> tag to make sure everything is included
|
|
799
|
+
const start = open.end;
|
|
800
|
+
const input = this.input.slice(start);
|
|
801
|
+
const end = input.indexOf('</style>');
|
|
802
|
+
const content = input.slice(0, end);
|
|
803
|
+
|
|
804
|
+
const component = this.#path.findLast((n) => n.type === 'Component');
|
|
805
|
+
if (!inside_head) {
|
|
806
|
+
if (component.css !== null) {
|
|
807
|
+
throw new Error('Components can only have one style tag');
|
|
808
|
+
}
|
|
809
|
+
component.css = parse_style(content);
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
const newLines = content.match(regex_newline_characters)?.length;
|
|
813
|
+
if (newLines) {
|
|
814
|
+
this.curLine = open.loc.end.line + newLines;
|
|
815
|
+
this.lineStart = start + content.lastIndexOf('\n') + 1;
|
|
816
|
+
}
|
|
817
|
+
this.pos = start + content.length + 1;
|
|
818
|
+
|
|
819
|
+
this.type = tok.jsxTagStart;
|
|
820
|
+
this.next();
|
|
821
|
+
if (this.value === '/') {
|
|
822
|
+
this.next();
|
|
823
|
+
this.jsx_parseElementName();
|
|
824
|
+
this.exprAllowed = true;
|
|
825
|
+
this.#path.pop();
|
|
826
|
+
this.next();
|
|
827
|
+
}
|
|
828
|
+
// This node is used for Prettier, we don't actually need
|
|
829
|
+
// the node for Ripple's transform process
|
|
830
|
+
if (!inside_head) {
|
|
831
|
+
element.children = [component.css];
|
|
832
|
+
}
|
|
833
|
+
// Ensure we escape JSX <tag></tag> context
|
|
834
|
+
const tokContexts = this.acornTypeScript.tokContexts;
|
|
835
|
+
const curContext = this.curContext();
|
|
836
|
+
|
|
837
|
+
if (curContext === tokContexts.tc_expr) {
|
|
838
|
+
this.context.pop();
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
element.css = content;
|
|
842
|
+
this.finishNode(element, 'Element');
|
|
843
|
+
return element;
|
|
844
|
+
} else {
|
|
845
|
+
this.enterScope(0);
|
|
846
|
+
this.parseTemplateBody(element.children);
|
|
847
|
+
this.exitScope();
|
|
848
|
+
|
|
849
|
+
// Check if this element was properly closed
|
|
850
|
+
// If we reach here and this element is still in the path, it means it was never closed
|
|
851
|
+
if (this.#path[this.#path.length - 1] === element) {
|
|
852
|
+
const tagName = this.getElementName(element.id);
|
|
853
|
+
this.raise(
|
|
854
|
+
this.start,
|
|
855
|
+
`Unclosed tag '<${tagName}>'. Expected '</${tagName}>' before end of component.`,
|
|
856
|
+
);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
// Ensure we escape JSX <tag></tag> context
|
|
860
|
+
const tokContexts = this.acornTypeScript.tokContexts;
|
|
861
|
+
const curContext = this.curContext();
|
|
862
|
+
|
|
863
|
+
if (curContext === tokContexts.tc_expr) {
|
|
864
|
+
this.context.pop();
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
this.finishNode(element, 'Element');
|
|
869
|
+
return element;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
parseTemplateBody(body) {
|
|
873
|
+
var inside_func =
|
|
874
|
+
this.context.some((n) => n.token === 'function') || this.scopeStack.length > 1;
|
|
875
|
+
|
|
876
|
+
if (!inside_func) {
|
|
877
|
+
if (this.type.label === 'return') {
|
|
878
|
+
throw new Error('`return` statements are not allowed in components');
|
|
879
|
+
}
|
|
880
|
+
if (this.type.label === 'continue') {
|
|
881
|
+
throw new Error('`continue` statements are not allowed in components');
|
|
882
|
+
}
|
|
883
|
+
if (this.type.label === 'break') {
|
|
884
|
+
throw new Error('`break` statements are not allowed in components');
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
if (this.type.label === '{') {
|
|
889
|
+
const node = this.jsx_parseExpressionContainer();
|
|
890
|
+
node.type = 'Text';
|
|
891
|
+
body.push(node);
|
|
892
|
+
} else if (this.type.label === '}') {
|
|
893
|
+
return;
|
|
894
|
+
} else if (this.type.label === 'jsxTagStart') {
|
|
895
|
+
this.next();
|
|
896
|
+
if (this.value === '/') {
|
|
897
|
+
this.next();
|
|
898
|
+
const closingTag = this.jsx_parseElementName();
|
|
899
|
+
this.exprAllowed = true;
|
|
900
|
+
|
|
901
|
+
// Validate that the closing tag matches the opening tag
|
|
902
|
+
const currentElement = this.#path[this.#path.length - 1];
|
|
903
|
+
if (!currentElement || currentElement.type !== 'Element') {
|
|
904
|
+
this.raise(this.start, 'Unexpected closing tag');
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
const openingTagName = this.getElementName(currentElement.id);
|
|
908
|
+
const closingTagName = this.getElementName(closingTag);
|
|
909
|
+
|
|
910
|
+
if (openingTagName !== closingTagName) {
|
|
911
|
+
this.raise(
|
|
912
|
+
this.start,
|
|
913
|
+
`Expected closing tag to match opening tag. Expected '</${openingTagName}>' but found '</${closingTagName}>'`,
|
|
914
|
+
);
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
this.#path.pop();
|
|
918
|
+
this.next();
|
|
919
|
+
return;
|
|
920
|
+
}
|
|
921
|
+
const node = this.parseElement();
|
|
922
|
+
if (node !== null) {
|
|
923
|
+
body.push(node);
|
|
924
|
+
}
|
|
925
|
+
} else {
|
|
926
|
+
const node = this.parseStatement(null);
|
|
927
|
+
body.push(node);
|
|
928
|
+
}
|
|
929
|
+
this.parseTemplateBody(body);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
parseStatement(context, topLevel, exports) {
|
|
933
|
+
const tok = this.acornTypeScript.tokContexts;
|
|
934
|
+
|
|
935
|
+
if (
|
|
936
|
+
context !== 'for' &&
|
|
937
|
+
context !== 'if' &&
|
|
938
|
+
this.context.at(-1) === tc.b_stat &&
|
|
939
|
+
this.type === tt.braceL &&
|
|
940
|
+
this.context.some((c) => c === tok.tc_expr)
|
|
941
|
+
) {
|
|
942
|
+
this.next();
|
|
943
|
+
const node = this.jsx_parseExpressionContainer();
|
|
944
|
+
node.type = 'Text';
|
|
945
|
+
this.next();
|
|
946
|
+
this.context.pop();
|
|
947
|
+
this.context.pop();
|
|
948
|
+
return node;
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
if (this.value === 'component') {
|
|
952
|
+
const node = this.startNode();
|
|
953
|
+
node.type = 'Component';
|
|
954
|
+
node.css = null;
|
|
955
|
+
this.next();
|
|
956
|
+
this.enterScope(0);
|
|
957
|
+
node.id = this.parseIdent();
|
|
958
|
+
this.parseFunctionParams(node);
|
|
959
|
+
this.eat(tt.braceL);
|
|
960
|
+
node.body = [];
|
|
961
|
+
this.#path.push(node);
|
|
962
|
+
|
|
963
|
+
this.parseTemplateBody(node.body);
|
|
964
|
+
|
|
965
|
+
this.#path.pop();
|
|
966
|
+
this.exitScope();
|
|
967
|
+
|
|
968
|
+
this.next();
|
|
969
|
+
this.finishNode(node, 'Component');
|
|
970
|
+
this.awaitPos = 0;
|
|
971
|
+
|
|
972
|
+
return node;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
if (this.type.label === '@') {
|
|
976
|
+
// Try to parse as an expression statement first using tryParse
|
|
977
|
+
// This allows us to handle Ripple @ syntax like @count++ without
|
|
978
|
+
// interfering with legitimate decorator syntax
|
|
979
|
+
this.skip_decorator = true;
|
|
980
|
+
const expressionResult = this.tryParse(() => {
|
|
981
|
+
const node = this.startNode();
|
|
982
|
+
this.next();
|
|
983
|
+
// Force expression context to ensure @ is tokenized correctly
|
|
984
|
+
const old_expr_allowed = this.exprAllowed;
|
|
985
|
+
this.exprAllowed = true;
|
|
986
|
+
node.expression = this.parseExpression();
|
|
987
|
+
|
|
988
|
+
if (node.expression.type === 'UpdateExpression') {
|
|
989
|
+
let object = node.expression.argument;
|
|
990
|
+
while (object.type === 'MemberExpression') {
|
|
991
|
+
object = object.object;
|
|
992
|
+
}
|
|
993
|
+
if (object.type === 'Identifier') {
|
|
994
|
+
object.tracked = true;
|
|
995
|
+
}
|
|
996
|
+
} else if (node.expression.type === 'AssignmentExpression') {
|
|
997
|
+
let object = node.expression.left;
|
|
998
|
+
while (object.type === 'MemberExpression') {
|
|
999
|
+
object = object.object;
|
|
1000
|
+
}
|
|
1001
|
+
if (object.type === 'Identifier') {
|
|
1002
|
+
object.tracked = true;
|
|
1003
|
+
}
|
|
1004
|
+
} else if (node.expression.type === 'Identifier') {
|
|
1005
|
+
node.expression.tracked = true;
|
|
1006
|
+
} else {
|
|
1007
|
+
// TODO?
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
this.exprAllowed = old_expr_allowed;
|
|
1011
|
+
return this.finishNode(node, 'ExpressionStatement');
|
|
1012
|
+
});
|
|
1013
|
+
this.skip_decorator = false;
|
|
1014
|
+
|
|
1015
|
+
// If parsing as expression statement succeeded, use that result
|
|
1016
|
+
if (expressionResult.node) {
|
|
1017
|
+
return expressionResult.node;
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
return super.parseStatement(context, topLevel, exports);
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
parseBlock(createNewLexicalScope, node, exitStrict) {
|
|
1025
|
+
const parent = this.#path.at(-1);
|
|
1026
|
+
|
|
1027
|
+
if (parent?.type === 'Component' || parent?.type === 'Element') {
|
|
1028
|
+
if (createNewLexicalScope === void 0) createNewLexicalScope = true;
|
|
1029
|
+
if (node === void 0) node = this.startNode();
|
|
1030
|
+
|
|
1031
|
+
node.body = [];
|
|
1032
|
+
this.expect(tt.braceL);
|
|
1033
|
+
if (createNewLexicalScope) {
|
|
1034
|
+
this.enterScope(0);
|
|
1035
|
+
}
|
|
1036
|
+
this.parseTemplateBody(node.body);
|
|
1037
|
+
|
|
1038
|
+
if (exitStrict) {
|
|
1039
|
+
this.strict = false;
|
|
1040
|
+
}
|
|
1041
|
+
this.exprAllowed = true;
|
|
1042
|
+
|
|
1043
|
+
this.next();
|
|
1044
|
+
if (createNewLexicalScope) {
|
|
1045
|
+
this.exitScope();
|
|
1046
|
+
}
|
|
1047
|
+
return this.finishNode(node, 'BlockStatement');
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
return super.parseBlock(createNewLexicalScope, node, exitStrict);
|
|
1051
|
+
}
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
return RippleParser;
|
|
1055
|
+
};
|
|
967
1056
|
}
|
|
968
1057
|
|
|
969
1058
|
/**
|
|
@@ -975,115 +1064,115 @@ function RipplePlugin(config) {
|
|
|
975
1064
|
* @param {number} index
|
|
976
1065
|
*/
|
|
977
1066
|
function get_comment_handlers(source, comments, index = 0) {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1067
|
+
return {
|
|
1068
|
+
onComment: (block, value, start, end, start_loc, end_loc) => {
|
|
1069
|
+
if (block && /\n/.test(value)) {
|
|
1070
|
+
let a = start;
|
|
1071
|
+
while (a > 0 && source[a - 1] !== '\n') a -= 1;
|
|
1072
|
+
|
|
1073
|
+
let b = a;
|
|
1074
|
+
while (/[ \t]/.test(source[b])) b += 1;
|
|
1075
|
+
|
|
1076
|
+
const indentation = source.slice(a, b);
|
|
1077
|
+
value = value.replace(new RegExp(`^${indentation}`, 'gm'), '');
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
comments.push({
|
|
1081
|
+
type: block ? 'Block' : 'Line',
|
|
1082
|
+
value,
|
|
1083
|
+
start,
|
|
1084
|
+
end,
|
|
1085
|
+
loc: {
|
|
1086
|
+
start: /** @type {import('acorn').Position} */ (start_loc),
|
|
1087
|
+
end: /** @type {import('acorn').Position} */ (end_loc),
|
|
1088
|
+
},
|
|
1089
|
+
});
|
|
1090
|
+
},
|
|
1091
|
+
add_comments: (ast) => {
|
|
1092
|
+
if (comments.length === 0) return;
|
|
1093
|
+
|
|
1094
|
+
comments = comments
|
|
1095
|
+
.filter((comment) => comment.start >= index)
|
|
1096
|
+
.map(({ type, value, start, end }) => ({ type, value, start, end }));
|
|
1097
|
+
|
|
1098
|
+
walk(ast, null, {
|
|
1099
|
+
_(node, { next, path }) {
|
|
1100
|
+
let comment;
|
|
1101
|
+
|
|
1102
|
+
while (comments[0] && comments[0].start < node.start) {
|
|
1103
|
+
comment = /** @type {CommentWithLocation} */ (comments.shift());
|
|
1104
|
+
(node.leadingComments ||= []).push(comment);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
next();
|
|
1108
|
+
|
|
1109
|
+
if (comments[0]) {
|
|
1110
|
+
if (node.type === 'BlockStatement' && node.body.length === 0) {
|
|
1111
|
+
if (comments[0].start < node.end && comments[0].end < node.end) {
|
|
1112
|
+
comment = /** @type {CommentWithLocation} */ (comments.shift());
|
|
1113
|
+
(node.innerComments ||= []).push(comment);
|
|
1114
|
+
return;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
const parent = /** @type {any} */ (path.at(-1));
|
|
1118
|
+
|
|
1119
|
+
if (parent === undefined || node.end !== parent.end) {
|
|
1120
|
+
const slice = source.slice(node.end, comments[0].start);
|
|
1121
|
+
const is_last_in_body =
|
|
1122
|
+
((parent?.type === 'BlockStatement' || parent?.type === 'Program') &&
|
|
1123
|
+
parent.body.indexOf(node) === parent.body.length - 1) ||
|
|
1124
|
+
(parent?.type === 'ArrayExpression' &&
|
|
1125
|
+
parent.elements.indexOf(node) === parent.elements.length - 1) ||
|
|
1126
|
+
(parent?.type === 'ObjectExpression' &&
|
|
1127
|
+
parent.properties.indexOf(node) === parent.properties.length - 1);
|
|
1128
|
+
|
|
1129
|
+
if (is_last_in_body) {
|
|
1130
|
+
// Special case: There can be multiple trailing comments after the last node in a block,
|
|
1131
|
+
// and they can be separated by newlines
|
|
1132
|
+
let end = node.end;
|
|
1133
|
+
|
|
1134
|
+
while (comments.length) {
|
|
1135
|
+
const comment = comments[0];
|
|
1136
|
+
if (parent && comment.start >= parent.end) break;
|
|
1137
|
+
|
|
1138
|
+
(node.trailingComments ||= []).push(comment);
|
|
1139
|
+
comments.shift();
|
|
1140
|
+
end = comment.end;
|
|
1141
|
+
}
|
|
1142
|
+
} else if (node.end <= comments[0].start && /^[,) \t]*$/.test(slice)) {
|
|
1143
|
+
node.trailingComments = [/** @type {CommentWithLocation} */ (comments.shift())];
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
},
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
// Special case: Trailing comments after the root node (which can only happen for expression tags or for Program nodes).
|
|
1151
|
+
// Adding them ensures that we can later detect the end of the expression tag correctly.
|
|
1152
|
+
if (comments.length > 0 && (comments[0].start >= ast.end || ast.type === 'Program')) {
|
|
1153
|
+
(ast.trailingComments ||= []).push(...comments.splice(0));
|
|
1154
|
+
}
|
|
1155
|
+
},
|
|
1156
|
+
};
|
|
1068
1157
|
}
|
|
1069
1158
|
|
|
1070
1159
|
export function parse(source) {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1160
|
+
const comments = [];
|
|
1161
|
+
const { onComment, add_comments } = get_comment_handlers(source, comments);
|
|
1162
|
+
let ast;
|
|
1163
|
+
|
|
1164
|
+
try {
|
|
1165
|
+
ast = parser.parse(source, {
|
|
1166
|
+
sourceType: 'module',
|
|
1167
|
+
ecmaVersion: 13,
|
|
1168
|
+
locations: true,
|
|
1169
|
+
onComment,
|
|
1170
|
+
});
|
|
1171
|
+
} catch (e) {
|
|
1172
|
+
throw e;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
add_comments(ast);
|
|
1176
|
+
|
|
1177
|
+
return ast;
|
|
1089
1178
|
}
|