@intlify/message-compiler 12.0.0-alpha.2 → 12.0.0-alpha.4
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/dist/message-compiler.d.ts +189 -230
- package/dist/message-compiler.esm-browser.js +1216 -1481
- package/dist/message-compiler.esm-browser.prod.js +788 -6
- package/dist/message-compiler.esm-bundler.js +1 -1
- package/dist/message-compiler.global.js +1295 -1561
- package/dist/message-compiler.global.prod.js +803 -6
- package/dist/message-compiler.js +1200 -1464
- package/dist/message-compiler.node.js +1242 -1517
- package/package.json +38 -38
|
@@ -1,1562 +1,1296 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var IntlifyMessageCompiler = (function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
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
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
switch (token.type) {
|
|
1297
|
-
case 10 /* TokenTypes.LinkedKey */:
|
|
1298
|
-
if (token.value == null) {
|
|
1299
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1300
|
-
}
|
|
1301
|
-
linkedNode.key = parseLinkedKey(tokenizer, token.value || '');
|
|
1302
|
-
break;
|
|
1303
|
-
case 4 /* TokenTypes.Named */:
|
|
1304
|
-
if (token.value == null) {
|
|
1305
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1306
|
-
}
|
|
1307
|
-
linkedNode.key = parseNamed(tokenizer, token.value || '');
|
|
1308
|
-
break;
|
|
1309
|
-
case 5 /* TokenTypes.List */:
|
|
1310
|
-
if (token.value == null) {
|
|
1311
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1312
|
-
}
|
|
1313
|
-
linkedNode.key = parseList(tokenizer, token.value || '');
|
|
1314
|
-
break;
|
|
1315
|
-
case 6 /* TokenTypes.Literal */:
|
|
1316
|
-
if (token.value == null) {
|
|
1317
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1318
|
-
}
|
|
1319
|
-
linkedNode.key = parseLiteral(tokenizer, token.value || '');
|
|
1320
|
-
break;
|
|
1321
|
-
default: {
|
|
1322
|
-
// empty key
|
|
1323
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY, context.lastStartLoc, 0);
|
|
1324
|
-
const nextContext = tokenizer.context();
|
|
1325
|
-
const emptyLinkedKeyNode = startNode(7 /* NodeTypes.LinkedKey */, nextContext.offset, nextContext.startLoc);
|
|
1326
|
-
emptyLinkedKeyNode.value = '';
|
|
1327
|
-
endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc);
|
|
1328
|
-
linkedNode.key = emptyLinkedKeyNode;
|
|
1329
|
-
endNode(linkedNode, nextContext.offset, nextContext.startLoc);
|
|
1330
|
-
return {
|
|
1331
|
-
nextConsumeToken: token,
|
|
1332
|
-
node: linkedNode
|
|
1333
|
-
};
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1337
|
-
return {
|
|
1338
|
-
node: linkedNode
|
|
1339
|
-
};
|
|
1340
|
-
}
|
|
1341
|
-
function parseMessage(tokenizer) {
|
|
1342
|
-
const context = tokenizer.context();
|
|
1343
|
-
const startOffset = context.currentType === 1 /* TokenTypes.Pipe */
|
|
1344
|
-
? tokenizer.currentOffset()
|
|
1345
|
-
: context.offset;
|
|
1346
|
-
const startLoc = context.currentType === 1 /* TokenTypes.Pipe */
|
|
1347
|
-
? context.endLoc
|
|
1348
|
-
: context.startLoc;
|
|
1349
|
-
const node = startNode(2 /* NodeTypes.Message */, startOffset, startLoc);
|
|
1350
|
-
node.items = [];
|
|
1351
|
-
let nextToken = null;
|
|
1352
|
-
do {
|
|
1353
|
-
const token = nextToken || tokenizer.nextToken();
|
|
1354
|
-
nextToken = null;
|
|
1355
|
-
switch (token.type) {
|
|
1356
|
-
case 0 /* TokenTypes.Text */:
|
|
1357
|
-
if (token.value == null) {
|
|
1358
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1359
|
-
}
|
|
1360
|
-
node.items.push(parseText(tokenizer, token.value || ''));
|
|
1361
|
-
break;
|
|
1362
|
-
case 5 /* TokenTypes.List */:
|
|
1363
|
-
if (token.value == null) {
|
|
1364
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1365
|
-
}
|
|
1366
|
-
node.items.push(parseList(tokenizer, token.value || ''));
|
|
1367
|
-
break;
|
|
1368
|
-
case 4 /* TokenTypes.Named */:
|
|
1369
|
-
if (token.value == null) {
|
|
1370
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1371
|
-
}
|
|
1372
|
-
node.items.push(parseNamed(tokenizer, token.value || ''));
|
|
1373
|
-
break;
|
|
1374
|
-
case 6 /* TokenTypes.Literal */:
|
|
1375
|
-
if (token.value == null) {
|
|
1376
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1377
|
-
}
|
|
1378
|
-
node.items.push(parseLiteral(tokenizer, token.value || ''));
|
|
1379
|
-
break;
|
|
1380
|
-
case 7 /* TokenTypes.LinkedAlias */: {
|
|
1381
|
-
const parsed = parseLinked(tokenizer);
|
|
1382
|
-
node.items.push(parsed.node);
|
|
1383
|
-
nextToken = parsed.nextConsumeToken || null;
|
|
1384
|
-
break;
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
} while (context.currentType !== 13 /* TokenTypes.EOF */ &&
|
|
1388
|
-
context.currentType !== 1 /* TokenTypes.Pipe */);
|
|
1389
|
-
// adjust message node loc
|
|
1390
|
-
const endOffset = context.currentType === 1 /* TokenTypes.Pipe */
|
|
1391
|
-
? context.lastOffset
|
|
1392
|
-
: tokenizer.currentOffset();
|
|
1393
|
-
const endLoc = context.currentType === 1 /* TokenTypes.Pipe */
|
|
1394
|
-
? context.lastEndLoc
|
|
1395
|
-
: tokenizer.currentPosition();
|
|
1396
|
-
endNode(node, endOffset, endLoc);
|
|
1397
|
-
return node;
|
|
1398
|
-
}
|
|
1399
|
-
function parsePlural(tokenizer, offset, loc, msgNode) {
|
|
1400
|
-
const context = tokenizer.context();
|
|
1401
|
-
let hasEmptyMessage = msgNode.items.length === 0;
|
|
1402
|
-
const node = startNode(1 /* NodeTypes.Plural */, offset, loc);
|
|
1403
|
-
node.cases = [];
|
|
1404
|
-
node.cases.push(msgNode);
|
|
1405
|
-
do {
|
|
1406
|
-
const msg = parseMessage(tokenizer);
|
|
1407
|
-
if (!hasEmptyMessage) {
|
|
1408
|
-
hasEmptyMessage = msg.items.length === 0;
|
|
1409
|
-
}
|
|
1410
|
-
node.cases.push(msg);
|
|
1411
|
-
} while (context.currentType !== 13 /* TokenTypes.EOF */);
|
|
1412
|
-
if (hasEmptyMessage) {
|
|
1413
|
-
emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);
|
|
1414
|
-
}
|
|
1415
|
-
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1416
|
-
return node;
|
|
1417
|
-
}
|
|
1418
|
-
function parseResource(tokenizer) {
|
|
1419
|
-
const context = tokenizer.context();
|
|
1420
|
-
const { offset, startLoc } = context;
|
|
1421
|
-
const msgNode = parseMessage(tokenizer);
|
|
1422
|
-
if (context.currentType === 13 /* TokenTypes.EOF */) {
|
|
1423
|
-
return msgNode;
|
|
1424
|
-
}
|
|
1425
|
-
else {
|
|
1426
|
-
return parsePlural(tokenizer, offset, startLoc, msgNode);
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
function parse(source) {
|
|
1430
|
-
const tokenizer = createTokenizer(source, assign({}, options));
|
|
1431
|
-
const context = tokenizer.context();
|
|
1432
|
-
const node = startNode(0 /* NodeTypes.Resource */, context.offset, context.startLoc);
|
|
1433
|
-
if (location && node.loc) {
|
|
1434
|
-
node.loc.source = source;
|
|
1435
|
-
}
|
|
1436
|
-
node.body = parseResource(tokenizer);
|
|
1437
|
-
if (options.onCacheKey) {
|
|
1438
|
-
node.cacheKey = options.onCacheKey(source);
|
|
1439
|
-
}
|
|
1440
|
-
// assert whether achieved to EOF
|
|
1441
|
-
if (context.currentType !== 13 /* TokenTypes.EOF */) {
|
|
1442
|
-
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || '');
|
|
1443
|
-
}
|
|
1444
|
-
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1445
|
-
return node;
|
|
1446
|
-
}
|
|
1447
|
-
return { parse };
|
|
1448
|
-
}
|
|
1449
|
-
function getTokenCaption(token) {
|
|
1450
|
-
if (token.type === 13 /* TokenTypes.EOF */) {
|
|
1451
|
-
return 'EOF';
|
|
1452
|
-
}
|
|
1453
|
-
const name = (token.value || '').replace(/\r?\n/gu, '\\n');
|
|
1454
|
-
return name.length > 10 ? name.slice(0, 9) + '…' : name;
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
function createTransformer(ast, options = {} // eslint-disable-line
|
|
1458
|
-
) {
|
|
1459
|
-
const _context = {
|
|
1460
|
-
ast,
|
|
1461
|
-
helpers: new Set()
|
|
1462
|
-
};
|
|
1463
|
-
const context = () => _context;
|
|
1464
|
-
const helper = (name) => {
|
|
1465
|
-
_context.helpers.add(name);
|
|
1466
|
-
return name;
|
|
1467
|
-
};
|
|
1468
|
-
return { context, helper };
|
|
1469
|
-
}
|
|
1470
|
-
function traverseNodes(nodes, transformer) {
|
|
1471
|
-
for (let i = 0; i < nodes.length; i++) {
|
|
1472
|
-
traverseNode(nodes[i], transformer);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1475
|
-
function traverseNode(node, transformer) {
|
|
1476
|
-
// TODO: if we need pre-hook of transform, should be implemented to here
|
|
1477
|
-
switch (node.type) {
|
|
1478
|
-
case 1 /* NodeTypes.Plural */:
|
|
1479
|
-
traverseNodes(node.cases, transformer);
|
|
1480
|
-
transformer.helper("plural" /* HelperNameMap.PLURAL */);
|
|
1481
|
-
break;
|
|
1482
|
-
case 2 /* NodeTypes.Message */:
|
|
1483
|
-
traverseNodes(node.items, transformer);
|
|
1484
|
-
break;
|
|
1485
|
-
case 6 /* NodeTypes.Linked */: {
|
|
1486
|
-
const linked = node;
|
|
1487
|
-
traverseNode(linked.key, transformer);
|
|
1488
|
-
transformer.helper("linked" /* HelperNameMap.LINKED */);
|
|
1489
|
-
transformer.helper("type" /* HelperNameMap.TYPE */);
|
|
1490
|
-
break;
|
|
1491
|
-
}
|
|
1492
|
-
case 5 /* NodeTypes.List */:
|
|
1493
|
-
transformer.helper("interpolate" /* HelperNameMap.INTERPOLATE */);
|
|
1494
|
-
transformer.helper("list" /* HelperNameMap.LIST */);
|
|
1495
|
-
break;
|
|
1496
|
-
case 4 /* NodeTypes.Named */:
|
|
1497
|
-
transformer.helper("interpolate" /* HelperNameMap.INTERPOLATE */);
|
|
1498
|
-
transformer.helper("named" /* HelperNameMap.NAMED */);
|
|
1499
|
-
break;
|
|
1500
|
-
}
|
|
1501
|
-
// TODO: if we need post-hook of transform, should be implemented to here
|
|
1502
|
-
}
|
|
1503
|
-
// transform AST
|
|
1504
|
-
function transform(ast, options = {} // eslint-disable-line
|
|
1505
|
-
) {
|
|
1506
|
-
const transformer = createTransformer(ast);
|
|
1507
|
-
transformer.helper("normalize" /* HelperNameMap.NORMALIZE */);
|
|
1508
|
-
// traverse
|
|
1509
|
-
ast.body && traverseNode(ast.body, transformer);
|
|
1510
|
-
// set meta information
|
|
1511
|
-
const context = transformer.context();
|
|
1512
|
-
ast.helpers = Array.from(context.helpers);
|
|
1513
|
-
}
|
|
1514
|
-
|
|
1515
|
-
function baseCompile(source, options = {}) {
|
|
1516
|
-
const assignedOptions = assign({}, options);
|
|
1517
|
-
const jit = !!assignedOptions.jit;
|
|
1518
|
-
const enableMangle = !!assignedOptions.mangle;
|
|
1519
|
-
const enableOptimize = assignedOptions.optimize == null ? true : assignedOptions.optimize;
|
|
1520
|
-
// parse source codes
|
|
1521
|
-
const parser = createParser(assignedOptions);
|
|
1522
|
-
const ast = parser.parse(source);
|
|
1523
|
-
// TODO:
|
|
1524
|
-
// With the introduction of Jit compilation, code generation is no longer necessary. This function may no longer be needed since tree-shaking is not possible.
|
|
1525
|
-
if (!jit) {
|
|
1526
|
-
// transform ASTs
|
|
1527
|
-
transform(ast, assignedOptions);
|
|
1528
|
-
// generate javascript codes
|
|
1529
|
-
return generate(ast, assignedOptions);
|
|
1530
|
-
}
|
|
1531
|
-
else {
|
|
1532
|
-
// optimize ASTs
|
|
1533
|
-
enableOptimize && optimize(ast);
|
|
1534
|
-
// minimize ASTs
|
|
1535
|
-
enableMangle && mangle(ast);
|
|
1536
|
-
// In JIT mode, no ast transform, no code generation.
|
|
1537
|
-
return { ast, code: '' };
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
|
|
1541
|
-
// eslint-disable-next-line no-useless-escape
|
|
1542
|
-
const RE_HTML_TAG = /<\/?[\w\s="/.':;#-\/]+>/;
|
|
1543
|
-
const detectHtmlTag = (source) => RE_HTML_TAG.test(source);
|
|
1544
|
-
|
|
1545
|
-
exports.COMPILE_ERROR_CODES_EXTEND_POINT = COMPILE_ERROR_CODES_EXTEND_POINT;
|
|
1546
|
-
exports.CompileErrorCodes = CompileErrorCodes;
|
|
1547
|
-
exports.ERROR_DOMAIN = ERROR_DOMAIN;
|
|
1548
|
-
exports.LOCATION_STUB = LOCATION_STUB;
|
|
1549
|
-
exports.baseCompile = baseCompile;
|
|
1550
|
-
exports.createCompileError = createCompileError;
|
|
1551
|
-
exports.createLocation = createLocation;
|
|
1552
|
-
exports.createParser = createParser;
|
|
1553
|
-
exports.createPosition = createPosition;
|
|
1554
|
-
exports.defaultOnError = defaultOnError;
|
|
1555
|
-
exports.detectHtmlTag = detectHtmlTag;
|
|
1556
|
-
exports.errorMessages = errorMessages;
|
|
1557
|
-
exports.mangle = mangle;
|
|
1558
|
-
exports.optimize = optimize;
|
|
1559
|
-
|
|
1560
|
-
return exports;
|
|
1561
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @intlify/message-compiler v12.0.0-alpha.4
|
|
3
|
+
* (c) 2016-present kazuya kawaguchi and contributors
|
|
4
|
+
* @license MIT
|
|
5
|
+
**/
|
|
6
|
+
var IntlifyMessageCompiler = (function(exports) {
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
//#region packages/shared/src/utils.ts
|
|
9
|
+
const inBrowser = typeof window !== "undefined";
|
|
10
|
+
{
|
|
11
|
+
const perf = inBrowser && window.performance;
|
|
12
|
+
if (perf && perf.mark && perf.measure && perf.clearMarks && perf.clearMeasures) {}
|
|
13
|
+
}
|
|
14
|
+
const RE_ARGS = /\{([0-9a-z]+)\}/gi;
|
|
15
|
+
function format(message, ...args) {
|
|
16
|
+
if (args.length === 1 && isObject(args[0])) args = args[0];
|
|
17
|
+
if (!args || !args.hasOwnProperty) args = {};
|
|
18
|
+
return message.replace(RE_ARGS, (_match, identifier) => {
|
|
19
|
+
return args.hasOwnProperty(identifier) ? args[identifier] : "";
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const assign = Object.assign;
|
|
23
|
+
Array.isArray;
|
|
24
|
+
const isString = (val) => typeof val === "string";
|
|
25
|
+
const isObject = (val) => val !== null && typeof val === "object";
|
|
26
|
+
function join(items, separator = "") {
|
|
27
|
+
return items.reduce((str, item, index) => index === 0 ? str + item : str + separator + item, "");
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region packages/message-compiler/src/nodes.ts
|
|
31
|
+
let NodeTypes = /* @__PURE__ */ function(NodeTypes) {
|
|
32
|
+
NodeTypes[NodeTypes["Resource"] = 0] = "Resource";
|
|
33
|
+
NodeTypes[NodeTypes["Plural"] = 1] = "Plural";
|
|
34
|
+
NodeTypes[NodeTypes["Message"] = 2] = "Message";
|
|
35
|
+
NodeTypes[NodeTypes["Text"] = 3] = "Text";
|
|
36
|
+
NodeTypes[NodeTypes["Named"] = 4] = "Named";
|
|
37
|
+
NodeTypes[NodeTypes["List"] = 5] = "List";
|
|
38
|
+
NodeTypes[NodeTypes["Linked"] = 6] = "Linked";
|
|
39
|
+
NodeTypes[NodeTypes["LinkedKey"] = 7] = "LinkedKey";
|
|
40
|
+
NodeTypes[NodeTypes["LinkedModifier"] = 8] = "LinkedModifier";
|
|
41
|
+
NodeTypes[NodeTypes["Literal"] = 9] = "Literal";
|
|
42
|
+
return NodeTypes;
|
|
43
|
+
}({});
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region packages/message-compiler/src/location.ts
|
|
46
|
+
const LOCATION_STUB = {
|
|
47
|
+
start: {
|
|
48
|
+
line: 1,
|
|
49
|
+
column: 1,
|
|
50
|
+
offset: 0
|
|
51
|
+
},
|
|
52
|
+
end: {
|
|
53
|
+
line: 1,
|
|
54
|
+
column: 1,
|
|
55
|
+
offset: 0
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
function createPosition(line, column, offset) {
|
|
59
|
+
return {
|
|
60
|
+
line,
|
|
61
|
+
column,
|
|
62
|
+
offset
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function createLocation(start, end, source) {
|
|
66
|
+
const loc = {
|
|
67
|
+
start,
|
|
68
|
+
end
|
|
69
|
+
};
|
|
70
|
+
if (source != null) loc.source = source;
|
|
71
|
+
return loc;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region packages/message-compiler/src/helpers.ts
|
|
75
|
+
let HelperNameMap = /* @__PURE__ */ function(HelperNameMap) {
|
|
76
|
+
HelperNameMap["LIST"] = "list";
|
|
77
|
+
HelperNameMap["NAMED"] = "named";
|
|
78
|
+
HelperNameMap["PLURAL"] = "plural";
|
|
79
|
+
HelperNameMap["LINKED"] = "linked";
|
|
80
|
+
HelperNameMap["MESSAGE"] = "message";
|
|
81
|
+
HelperNameMap["TYPE"] = "type";
|
|
82
|
+
HelperNameMap["INTERPOLATE"] = "interpolate";
|
|
83
|
+
HelperNameMap["NORMALIZE"] = "normalize";
|
|
84
|
+
HelperNameMap["VALUES"] = "values";
|
|
85
|
+
return HelperNameMap;
|
|
86
|
+
}({});
|
|
87
|
+
const RE_HTML_TAG = /<[\w\s=":;#-/]+>/;
|
|
88
|
+
const detectHtmlTag = (source) => RE_HTML_TAG.test(source);
|
|
89
|
+
//#endregion
|
|
90
|
+
//#region packages/message-compiler/src/errors.ts
|
|
91
|
+
const CompileErrorCodes = {
|
|
92
|
+
EXPECTED_TOKEN: 1,
|
|
93
|
+
INVALID_TOKEN_IN_PLACEHOLDER: 2,
|
|
94
|
+
UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER: 3,
|
|
95
|
+
UNKNOWN_ESCAPE_SEQUENCE: 4,
|
|
96
|
+
INVALID_UNICODE_ESCAPE_SEQUENCE: 5,
|
|
97
|
+
UNBALANCED_CLOSING_BRACE: 6,
|
|
98
|
+
UNTERMINATED_CLOSING_BRACE: 7,
|
|
99
|
+
EMPTY_PLACEHOLDER: 8,
|
|
100
|
+
NOT_ALLOW_NEST_PLACEHOLDER: 9,
|
|
101
|
+
INVALID_LINKED_FORMAT: 10,
|
|
102
|
+
MUST_HAVE_MESSAGES_IN_PLURAL: 11,
|
|
103
|
+
UNEXPECTED_EMPTY_LINKED_MODIFIER: 12,
|
|
104
|
+
UNEXPECTED_EMPTY_LINKED_KEY: 13,
|
|
105
|
+
UNEXPECTED_LEXICAL_ANALYSIS: 14,
|
|
106
|
+
UNHANDLED_CODEGEN_NODE_TYPE: 15,
|
|
107
|
+
UNHANDLED_MINIFIER_NODE_TYPE: 16
|
|
108
|
+
};
|
|
109
|
+
const COMPILE_ERROR_CODES_EXTEND_POINT = 17;
|
|
110
|
+
/** @internal */
|
|
111
|
+
const errorMessages = {
|
|
112
|
+
[CompileErrorCodes.EXPECTED_TOKEN]: `Expected token: '{0}'`,
|
|
113
|
+
[CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER]: `Invalid token in placeholder: '{0}'`,
|
|
114
|
+
[CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER]: `Unterminated single quote in placeholder`,
|
|
115
|
+
[CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE]: `Unknown escape sequence: \\{0}`,
|
|
116
|
+
[CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE]: `Invalid unicode escape sequence: {0}`,
|
|
117
|
+
[CompileErrorCodes.UNBALANCED_CLOSING_BRACE]: `Unbalanced closing brace`,
|
|
118
|
+
[CompileErrorCodes.UNTERMINATED_CLOSING_BRACE]: `Unterminated closing brace`,
|
|
119
|
+
[CompileErrorCodes.EMPTY_PLACEHOLDER]: `Empty placeholder`,
|
|
120
|
+
[CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER]: `Not allowed nest placeholder`,
|
|
121
|
+
[CompileErrorCodes.INVALID_LINKED_FORMAT]: `Invalid linked format`,
|
|
122
|
+
[CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL]: `Plural must have messages`,
|
|
123
|
+
[CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER]: `Unexpected empty linked modifier`,
|
|
124
|
+
[CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY]: `Unexpected empty linked key`,
|
|
125
|
+
[CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS]: `Unexpected lexical analysis in token: '{0}'`,
|
|
126
|
+
[CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE]: `unhandled codegen node type: '{0}'`,
|
|
127
|
+
[CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE]: `unhandled mimifier node type: '{0}'`
|
|
128
|
+
};
|
|
129
|
+
function createCompileError(code, loc, options = {}) {
|
|
130
|
+
const { domain, messages, args } = options;
|
|
131
|
+
const msg = format((messages || errorMessages)[code] || "", ...args || []);
|
|
132
|
+
const error = new SyntaxError(String(msg));
|
|
133
|
+
error.code = code;
|
|
134
|
+
if (loc) error.location = loc;
|
|
135
|
+
error.domain = domain;
|
|
136
|
+
return error;
|
|
137
|
+
}
|
|
138
|
+
/** @internal */
|
|
139
|
+
function defaultOnError(error) {
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region packages/message-compiler/src/generator.ts
|
|
144
|
+
const ERROR_DOMAIN$3 = "parser";
|
|
145
|
+
function createCodeGenerator(ast, options) {
|
|
146
|
+
const { sourceMap, filename, breakLineCode, needIndent: _needIndent } = options;
|
|
147
|
+
const location = options.location !== false;
|
|
148
|
+
const _context = {
|
|
149
|
+
filename,
|
|
150
|
+
code: "",
|
|
151
|
+
column: 1,
|
|
152
|
+
line: 1,
|
|
153
|
+
offset: 0,
|
|
154
|
+
map: void 0,
|
|
155
|
+
breakLineCode,
|
|
156
|
+
needIndent: _needIndent,
|
|
157
|
+
indentLevel: 0
|
|
158
|
+
};
|
|
159
|
+
if (location && ast.loc) _context.source = ast.loc.source;
|
|
160
|
+
const context = () => _context;
|
|
161
|
+
function push(code, node) {
|
|
162
|
+
_context.code += code;
|
|
163
|
+
}
|
|
164
|
+
function _newline(n, withBreakLine = true) {
|
|
165
|
+
const _breakLineCode = withBreakLine ? breakLineCode : "";
|
|
166
|
+
push(_needIndent ? _breakLineCode + ` `.repeat(n) : _breakLineCode);
|
|
167
|
+
}
|
|
168
|
+
function indent(withNewLine = true) {
|
|
169
|
+
const level = ++_context.indentLevel;
|
|
170
|
+
withNewLine && _newline(level);
|
|
171
|
+
}
|
|
172
|
+
function deindent(withNewLine = true) {
|
|
173
|
+
const level = --_context.indentLevel;
|
|
174
|
+
withNewLine && _newline(level);
|
|
175
|
+
}
|
|
176
|
+
function newline() {
|
|
177
|
+
_newline(_context.indentLevel);
|
|
178
|
+
}
|
|
179
|
+
const helper = (key) => `_${key}`;
|
|
180
|
+
const needIndent = () => _context.needIndent;
|
|
181
|
+
return {
|
|
182
|
+
context,
|
|
183
|
+
push,
|
|
184
|
+
indent,
|
|
185
|
+
deindent,
|
|
186
|
+
newline,
|
|
187
|
+
helper,
|
|
188
|
+
needIndent
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function generateLinkedNode(generator, node) {
|
|
192
|
+
const { helper } = generator;
|
|
193
|
+
generator.push(`${helper("linked")}(`);
|
|
194
|
+
generateNode(generator, node.key);
|
|
195
|
+
if (node.modifier) {
|
|
196
|
+
generator.push(`, `);
|
|
197
|
+
generateNode(generator, node.modifier);
|
|
198
|
+
generator.push(`, _type`);
|
|
199
|
+
} else generator.push(`, undefined, _type`);
|
|
200
|
+
generator.push(`)`);
|
|
201
|
+
}
|
|
202
|
+
function generateMessageNode(generator, node) {
|
|
203
|
+
const { helper, needIndent } = generator;
|
|
204
|
+
generator.push(`${helper("normalize")}([`);
|
|
205
|
+
generator.indent(needIndent());
|
|
206
|
+
const length = node.items.length;
|
|
207
|
+
for (let i = 0; i < length; i++) {
|
|
208
|
+
generateNode(generator, node.items[i]);
|
|
209
|
+
if (i === length - 1) break;
|
|
210
|
+
generator.push(", ");
|
|
211
|
+
}
|
|
212
|
+
generator.deindent(needIndent());
|
|
213
|
+
generator.push("])");
|
|
214
|
+
}
|
|
215
|
+
function generatePluralNode(generator, node) {
|
|
216
|
+
const { helper, needIndent } = generator;
|
|
217
|
+
if (node.cases.length > 1) {
|
|
218
|
+
generator.push(`${helper("plural")}([`);
|
|
219
|
+
generator.indent(needIndent());
|
|
220
|
+
const length = node.cases.length;
|
|
221
|
+
for (let i = 0; i < length; i++) {
|
|
222
|
+
generateNode(generator, node.cases[i]);
|
|
223
|
+
if (i === length - 1) break;
|
|
224
|
+
generator.push(", ");
|
|
225
|
+
}
|
|
226
|
+
generator.deindent(needIndent());
|
|
227
|
+
generator.push(`])`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
function generateResource(generator, node) {
|
|
231
|
+
if (node.body) generateNode(generator, node.body);
|
|
232
|
+
else generator.push("null");
|
|
233
|
+
}
|
|
234
|
+
function generateNode(generator, node) {
|
|
235
|
+
const { helper } = generator;
|
|
236
|
+
switch (node.type) {
|
|
237
|
+
case 0:
|
|
238
|
+
generateResource(generator, node);
|
|
239
|
+
break;
|
|
240
|
+
case 1:
|
|
241
|
+
generatePluralNode(generator, node);
|
|
242
|
+
break;
|
|
243
|
+
case 2:
|
|
244
|
+
generateMessageNode(generator, node);
|
|
245
|
+
break;
|
|
246
|
+
case 6:
|
|
247
|
+
generateLinkedNode(generator, node);
|
|
248
|
+
break;
|
|
249
|
+
case 8:
|
|
250
|
+
generator.push(JSON.stringify(node.value), node);
|
|
251
|
+
break;
|
|
252
|
+
case 7:
|
|
253
|
+
generator.push(JSON.stringify(node.value), node);
|
|
254
|
+
break;
|
|
255
|
+
case 5:
|
|
256
|
+
generator.push(`${helper("interpolate")}(${helper("list")}(${node.index}))`, node);
|
|
257
|
+
break;
|
|
258
|
+
case 4:
|
|
259
|
+
generator.push(`${helper("interpolate")}(${helper("named")}(${JSON.stringify(node.key)}))`, node);
|
|
260
|
+
break;
|
|
261
|
+
case 9:
|
|
262
|
+
generator.push(JSON.stringify(node.value), node);
|
|
263
|
+
break;
|
|
264
|
+
case 3:
|
|
265
|
+
generator.push(JSON.stringify(node.value), node);
|
|
266
|
+
break;
|
|
267
|
+
default: throw createCompileError(CompileErrorCodes.UNHANDLED_CODEGEN_NODE_TYPE, null, {
|
|
268
|
+
domain: ERROR_DOMAIN$3,
|
|
269
|
+
args: [node.type]
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const generate = (ast, options = {}) => {
|
|
274
|
+
const mode = isString(options.mode) ? options.mode : "normal";
|
|
275
|
+
const filename = isString(options.filename) ? options.filename : "message.intl";
|
|
276
|
+
const sourceMap = !!options.sourceMap;
|
|
277
|
+
const breakLineCode = options.breakLineCode != null ? options.breakLineCode : mode === "arrow" ? ";" : "\n";
|
|
278
|
+
const needIndent = options.needIndent ? options.needIndent : mode !== "arrow";
|
|
279
|
+
const helpers = ast.helpers || [];
|
|
280
|
+
const generator = createCodeGenerator(ast, {
|
|
281
|
+
mode,
|
|
282
|
+
filename,
|
|
283
|
+
sourceMap,
|
|
284
|
+
breakLineCode,
|
|
285
|
+
needIndent
|
|
286
|
+
});
|
|
287
|
+
generator.push(mode === "normal" ? `function __msg__ (ctx) {` : `(ctx) => {`);
|
|
288
|
+
generator.indent(needIndent);
|
|
289
|
+
if (helpers.length > 0) {
|
|
290
|
+
generator.push(`const { ${join(helpers.map((s) => `${s}: _${s}`), ", ")} } = ctx`);
|
|
291
|
+
generator.newline();
|
|
292
|
+
}
|
|
293
|
+
generator.push(`return `);
|
|
294
|
+
generateNode(generator, ast);
|
|
295
|
+
generator.deindent(needIndent);
|
|
296
|
+
generator.push(`}`);
|
|
297
|
+
delete ast.helpers;
|
|
298
|
+
const { code, map } = generator.context();
|
|
299
|
+
return {
|
|
300
|
+
ast,
|
|
301
|
+
code,
|
|
302
|
+
map: map ? map.toJSON() : void 0
|
|
303
|
+
};
|
|
304
|
+
};
|
|
305
|
+
//#endregion
|
|
306
|
+
//#region packages/message-compiler/src/mangler.ts
|
|
307
|
+
const ERROR_DOMAIN$2 = "minifier";
|
|
308
|
+
function mangle(node) {
|
|
309
|
+
node.t = node.type;
|
|
310
|
+
switch (node.type) {
|
|
311
|
+
case 0: {
|
|
312
|
+
const resource = node;
|
|
313
|
+
mangle(resource.body);
|
|
314
|
+
resource.b = resource.body;
|
|
315
|
+
delete resource.body;
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
case 1: {
|
|
319
|
+
const plural = node;
|
|
320
|
+
const cases = plural.cases;
|
|
321
|
+
for (let i = 0; i < cases.length; i++) mangle(cases[i]);
|
|
322
|
+
plural.c = cases;
|
|
323
|
+
delete plural.cases;
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
case 2: {
|
|
327
|
+
const message = node;
|
|
328
|
+
const items = message.items;
|
|
329
|
+
for (let i = 0; i < items.length; i++) mangle(items[i]);
|
|
330
|
+
message.i = items;
|
|
331
|
+
delete message.items;
|
|
332
|
+
if (message.static) {
|
|
333
|
+
message.s = message.static;
|
|
334
|
+
delete message.static;
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
case 3:
|
|
339
|
+
case 9:
|
|
340
|
+
case 8:
|
|
341
|
+
case 7: {
|
|
342
|
+
const valueNode = node;
|
|
343
|
+
if (valueNode.value) {
|
|
344
|
+
valueNode.v = valueNode.value;
|
|
345
|
+
delete valueNode.value;
|
|
346
|
+
}
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
case 6: {
|
|
350
|
+
const linked = node;
|
|
351
|
+
mangle(linked.key);
|
|
352
|
+
linked.k = linked.key;
|
|
353
|
+
delete linked.key;
|
|
354
|
+
if (linked.modifier) {
|
|
355
|
+
mangle(linked.modifier);
|
|
356
|
+
linked.m = linked.modifier;
|
|
357
|
+
delete linked.modifier;
|
|
358
|
+
}
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
case 5: {
|
|
362
|
+
const list = node;
|
|
363
|
+
list.i = list.index;
|
|
364
|
+
delete list.index;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
case 4: {
|
|
368
|
+
const named = node;
|
|
369
|
+
named.k = named.key;
|
|
370
|
+
delete named.key;
|
|
371
|
+
break;
|
|
372
|
+
}
|
|
373
|
+
default: throw createCompileError(CompileErrorCodes.UNHANDLED_MINIFIER_NODE_TYPE, null, {
|
|
374
|
+
domain: ERROR_DOMAIN$2,
|
|
375
|
+
args: [node.type]
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
delete node.type;
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region packages/message-compiler/src/optimizer.ts
|
|
382
|
+
function optimize(ast) {
|
|
383
|
+
const body = ast.body;
|
|
384
|
+
if (body.type === 2) optimizeMessageNode(body);
|
|
385
|
+
else body.cases.forEach((c) => optimizeMessageNode(c));
|
|
386
|
+
return ast;
|
|
387
|
+
}
|
|
388
|
+
function optimizeMessageNode(message) {
|
|
389
|
+
if (message.items.length === 1) {
|
|
390
|
+
const item = message.items[0];
|
|
391
|
+
if (item.type === 3 || item.type === 9) {
|
|
392
|
+
message.static = item.value;
|
|
393
|
+
delete item.value;
|
|
394
|
+
}
|
|
395
|
+
} else {
|
|
396
|
+
const values = [];
|
|
397
|
+
for (let i = 0; i < message.items.length; i++) {
|
|
398
|
+
const item = message.items[i];
|
|
399
|
+
if (!(item.type === 3 || item.type === 9)) break;
|
|
400
|
+
if (item.value == null) break;
|
|
401
|
+
values.push(item.value);
|
|
402
|
+
}
|
|
403
|
+
if (values.length === message.items.length) {
|
|
404
|
+
message.static = join(values);
|
|
405
|
+
for (let i = 0; i < message.items.length; i++) {
|
|
406
|
+
const item = message.items[i];
|
|
407
|
+
if (item.type === 3 || item.type === 9) delete item.value;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
function createScanner(str) {
|
|
413
|
+
const _buf = str;
|
|
414
|
+
let _index = 0;
|
|
415
|
+
let _line = 1;
|
|
416
|
+
let _column = 1;
|
|
417
|
+
let _peekOffset = 0;
|
|
418
|
+
const isCRLF = (index) => _buf[index] === "\r" && _buf[index + 1] === "\n";
|
|
419
|
+
const isLF = (index) => _buf[index] === "\n";
|
|
420
|
+
const isPS = (index) => _buf[index] === "\u2029";
|
|
421
|
+
const isLS = (index) => _buf[index] === "\u2028";
|
|
422
|
+
const isLineEnd = (index) => isCRLF(index) || isLF(index) || isPS(index) || isLS(index);
|
|
423
|
+
const index = () => _index;
|
|
424
|
+
const line = () => _line;
|
|
425
|
+
const column = () => _column;
|
|
426
|
+
const peekOffset = () => _peekOffset;
|
|
427
|
+
const charAt = (offset) => isCRLF(offset) || isPS(offset) || isLS(offset) ? "\n" : _buf[offset];
|
|
428
|
+
const currentChar = () => charAt(_index);
|
|
429
|
+
const currentPeek = () => charAt(_index + _peekOffset);
|
|
430
|
+
function next() {
|
|
431
|
+
_peekOffset = 0;
|
|
432
|
+
if (isLineEnd(_index)) {
|
|
433
|
+
_line++;
|
|
434
|
+
_column = 0;
|
|
435
|
+
}
|
|
436
|
+
if (isCRLF(_index)) _index++;
|
|
437
|
+
_index++;
|
|
438
|
+
_column++;
|
|
439
|
+
return _buf[_index];
|
|
440
|
+
}
|
|
441
|
+
function peek() {
|
|
442
|
+
if (isCRLF(_index + _peekOffset)) _peekOffset++;
|
|
443
|
+
_peekOffset++;
|
|
444
|
+
return _buf[_index + _peekOffset];
|
|
445
|
+
}
|
|
446
|
+
function reset() {
|
|
447
|
+
_index = 0;
|
|
448
|
+
_line = 1;
|
|
449
|
+
_column = 1;
|
|
450
|
+
_peekOffset = 0;
|
|
451
|
+
}
|
|
452
|
+
function resetPeek(offset = 0) {
|
|
453
|
+
_peekOffset = offset;
|
|
454
|
+
}
|
|
455
|
+
function skipToPeek() {
|
|
456
|
+
const target = _index + _peekOffset;
|
|
457
|
+
while (target !== _index) next();
|
|
458
|
+
_peekOffset = 0;
|
|
459
|
+
}
|
|
460
|
+
return {
|
|
461
|
+
index,
|
|
462
|
+
line,
|
|
463
|
+
column,
|
|
464
|
+
peekOffset,
|
|
465
|
+
charAt,
|
|
466
|
+
currentChar,
|
|
467
|
+
currentPeek,
|
|
468
|
+
next,
|
|
469
|
+
peek,
|
|
470
|
+
reset,
|
|
471
|
+
resetPeek,
|
|
472
|
+
skipToPeek
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region packages/message-compiler/src/tokenizer.ts
|
|
477
|
+
const EOF = void 0;
|
|
478
|
+
const DOT = ".";
|
|
479
|
+
const LITERAL_DELIMITER = "'";
|
|
480
|
+
const ERROR_DOMAIN$1 = "tokenizer";
|
|
481
|
+
function createTokenizer(source, options = {}) {
|
|
482
|
+
const location = options.location !== false;
|
|
483
|
+
const _scnr = createScanner(source);
|
|
484
|
+
const currentOffset = () => _scnr.index();
|
|
485
|
+
const currentPosition = () => createPosition(_scnr.line(), _scnr.column(), _scnr.index());
|
|
486
|
+
const _initLoc = currentPosition();
|
|
487
|
+
const _initOffset = currentOffset();
|
|
488
|
+
const _context = {
|
|
489
|
+
currentType: 13,
|
|
490
|
+
offset: _initOffset,
|
|
491
|
+
startLoc: _initLoc,
|
|
492
|
+
endLoc: _initLoc,
|
|
493
|
+
lastType: 13,
|
|
494
|
+
lastOffset: _initOffset,
|
|
495
|
+
lastStartLoc: _initLoc,
|
|
496
|
+
lastEndLoc: _initLoc,
|
|
497
|
+
braceNest: 0,
|
|
498
|
+
inLinked: false,
|
|
499
|
+
text: ""
|
|
500
|
+
};
|
|
501
|
+
const context = () => _context;
|
|
502
|
+
const { onError } = options;
|
|
503
|
+
function emitError(code, pos, offset, ...args) {
|
|
504
|
+
const ctx = context();
|
|
505
|
+
pos.column += offset;
|
|
506
|
+
pos.offset += offset;
|
|
507
|
+
if (onError) onError(createCompileError(code, location ? createLocation(ctx.startLoc, pos) : null, {
|
|
508
|
+
domain: ERROR_DOMAIN$1,
|
|
509
|
+
args
|
|
510
|
+
}));
|
|
511
|
+
}
|
|
512
|
+
function getToken(context, type, value) {
|
|
513
|
+
context.endLoc = currentPosition();
|
|
514
|
+
context.currentType = type;
|
|
515
|
+
const token = { type };
|
|
516
|
+
if (location) token.loc = createLocation(context.startLoc, context.endLoc);
|
|
517
|
+
if (value != null) token.value = value;
|
|
518
|
+
return token;
|
|
519
|
+
}
|
|
520
|
+
const getEndToken = (context) => getToken(context, 13);
|
|
521
|
+
function eat(scnr, ch) {
|
|
522
|
+
if (scnr.currentChar() === ch) {
|
|
523
|
+
scnr.next();
|
|
524
|
+
return ch;
|
|
525
|
+
} else {
|
|
526
|
+
emitError(CompileErrorCodes.EXPECTED_TOKEN, currentPosition(), 0, ch);
|
|
527
|
+
return "";
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
function peekSpaces(scnr) {
|
|
531
|
+
let buf = "";
|
|
532
|
+
while (scnr.currentPeek() === " " || scnr.currentPeek() === "\n") {
|
|
533
|
+
buf += scnr.currentPeek();
|
|
534
|
+
scnr.peek();
|
|
535
|
+
}
|
|
536
|
+
return buf;
|
|
537
|
+
}
|
|
538
|
+
function skipSpaces(scnr) {
|
|
539
|
+
const buf = peekSpaces(scnr);
|
|
540
|
+
scnr.skipToPeek();
|
|
541
|
+
return buf;
|
|
542
|
+
}
|
|
543
|
+
function isIdentifierStart(ch) {
|
|
544
|
+
if (ch === EOF) return false;
|
|
545
|
+
const cc = ch.charCodeAt(0);
|
|
546
|
+
return cc >= 97 && cc <= 122 || cc >= 65 && cc <= 90 || cc === 95;
|
|
547
|
+
}
|
|
548
|
+
function isNumberStart(ch) {
|
|
549
|
+
if (ch === EOF) return false;
|
|
550
|
+
const cc = ch.charCodeAt(0);
|
|
551
|
+
return cc >= 48 && cc <= 57;
|
|
552
|
+
}
|
|
553
|
+
function isNamedIdentifierStart(scnr, context) {
|
|
554
|
+
const { currentType } = context;
|
|
555
|
+
if (currentType !== 2) return false;
|
|
556
|
+
peekSpaces(scnr);
|
|
557
|
+
const ret = isIdentifierStart(scnr.currentPeek());
|
|
558
|
+
scnr.resetPeek();
|
|
559
|
+
return ret;
|
|
560
|
+
}
|
|
561
|
+
function isListIdentifierStart(scnr, context) {
|
|
562
|
+
const { currentType } = context;
|
|
563
|
+
if (currentType !== 2) return false;
|
|
564
|
+
peekSpaces(scnr);
|
|
565
|
+
const ret = isNumberStart(scnr.currentPeek() === "-" ? scnr.peek() : scnr.currentPeek());
|
|
566
|
+
scnr.resetPeek();
|
|
567
|
+
return ret;
|
|
568
|
+
}
|
|
569
|
+
function isLiteralStart(scnr, context) {
|
|
570
|
+
const { currentType } = context;
|
|
571
|
+
if (currentType !== 2) return false;
|
|
572
|
+
peekSpaces(scnr);
|
|
573
|
+
const ret = scnr.currentPeek() === LITERAL_DELIMITER;
|
|
574
|
+
scnr.resetPeek();
|
|
575
|
+
return ret;
|
|
576
|
+
}
|
|
577
|
+
function isLinkedDotStart(scnr, context) {
|
|
578
|
+
const { currentType } = context;
|
|
579
|
+
if (currentType !== 7) return false;
|
|
580
|
+
peekSpaces(scnr);
|
|
581
|
+
const ret = scnr.currentPeek() === ".";
|
|
582
|
+
scnr.resetPeek();
|
|
583
|
+
return ret;
|
|
584
|
+
}
|
|
585
|
+
function isLinkedModifierStart(scnr, context) {
|
|
586
|
+
const { currentType } = context;
|
|
587
|
+
if (currentType !== 8) return false;
|
|
588
|
+
peekSpaces(scnr);
|
|
589
|
+
const ret = isIdentifierStart(scnr.currentPeek());
|
|
590
|
+
scnr.resetPeek();
|
|
591
|
+
return ret;
|
|
592
|
+
}
|
|
593
|
+
function isLinkedDelimiterStart(scnr, context) {
|
|
594
|
+
const { currentType } = context;
|
|
595
|
+
if (!(currentType === 7 || currentType === 11)) return false;
|
|
596
|
+
peekSpaces(scnr);
|
|
597
|
+
const ret = scnr.currentPeek() === ":";
|
|
598
|
+
scnr.resetPeek();
|
|
599
|
+
return ret;
|
|
600
|
+
}
|
|
601
|
+
function isLinkedReferStart(scnr, context) {
|
|
602
|
+
const { currentType } = context;
|
|
603
|
+
if (currentType !== 9) return false;
|
|
604
|
+
const fn = () => {
|
|
605
|
+
const ch = scnr.currentPeek();
|
|
606
|
+
if (ch === "{") return isIdentifierStart(scnr.peek());
|
|
607
|
+
else if (ch === "@" || ch === "|" || ch === ":" || ch === "." || ch === " " || !ch) return false;
|
|
608
|
+
else if (ch === "\n") {
|
|
609
|
+
scnr.peek();
|
|
610
|
+
return fn();
|
|
611
|
+
} else return isTextStart(scnr, false);
|
|
612
|
+
};
|
|
613
|
+
const ret = fn();
|
|
614
|
+
scnr.resetPeek();
|
|
615
|
+
return ret;
|
|
616
|
+
}
|
|
617
|
+
function isPluralStart(scnr) {
|
|
618
|
+
peekSpaces(scnr);
|
|
619
|
+
const ret = scnr.currentPeek() === "|";
|
|
620
|
+
scnr.resetPeek();
|
|
621
|
+
return ret;
|
|
622
|
+
}
|
|
623
|
+
function isTextStart(scnr, reset = true) {
|
|
624
|
+
const fn = (hasSpace = false, prev = "") => {
|
|
625
|
+
const ch = scnr.currentPeek();
|
|
626
|
+
if (ch === "{") return hasSpace;
|
|
627
|
+
else if (ch === "@" || !ch) return hasSpace;
|
|
628
|
+
else if (ch === "|") return !(prev === " " || prev === "\n");
|
|
629
|
+
else if (ch === " ") {
|
|
630
|
+
scnr.peek();
|
|
631
|
+
return fn(true, " ");
|
|
632
|
+
} else if (ch === "\n") {
|
|
633
|
+
scnr.peek();
|
|
634
|
+
return fn(true, "\n");
|
|
635
|
+
} else return true;
|
|
636
|
+
};
|
|
637
|
+
const ret = fn();
|
|
638
|
+
reset && scnr.resetPeek();
|
|
639
|
+
return ret;
|
|
640
|
+
}
|
|
641
|
+
function takeChar(scnr, fn) {
|
|
642
|
+
const ch = scnr.currentChar();
|
|
643
|
+
if (ch === EOF) return EOF;
|
|
644
|
+
if (fn(ch)) {
|
|
645
|
+
scnr.next();
|
|
646
|
+
return ch;
|
|
647
|
+
}
|
|
648
|
+
return null;
|
|
649
|
+
}
|
|
650
|
+
function isIdentifier(ch) {
|
|
651
|
+
const cc = ch.charCodeAt(0);
|
|
652
|
+
return cc >= 97 && cc <= 122 || cc >= 65 && cc <= 90 || cc >= 48 && cc <= 57 || cc === 95 || cc === 36;
|
|
653
|
+
}
|
|
654
|
+
function takeIdentifierChar(scnr) {
|
|
655
|
+
return takeChar(scnr, isIdentifier);
|
|
656
|
+
}
|
|
657
|
+
function isNamedIdentifier(ch) {
|
|
658
|
+
const cc = ch.charCodeAt(0);
|
|
659
|
+
return cc >= 97 && cc <= 122 || cc >= 65 && cc <= 90 || cc >= 48 && cc <= 57 || cc === 95 || cc === 36 || cc === 45;
|
|
660
|
+
}
|
|
661
|
+
function takeNamedIdentifierChar(scnr) {
|
|
662
|
+
return takeChar(scnr, isNamedIdentifier);
|
|
663
|
+
}
|
|
664
|
+
function isDigit(ch) {
|
|
665
|
+
const cc = ch.charCodeAt(0);
|
|
666
|
+
return cc >= 48 && cc <= 57;
|
|
667
|
+
}
|
|
668
|
+
function takeDigit(scnr) {
|
|
669
|
+
return takeChar(scnr, isDigit);
|
|
670
|
+
}
|
|
671
|
+
function isHexDigit(ch) {
|
|
672
|
+
const cc = ch.charCodeAt(0);
|
|
673
|
+
return cc >= 48 && cc <= 57 || cc >= 65 && cc <= 70 || cc >= 97 && cc <= 102;
|
|
674
|
+
}
|
|
675
|
+
function takeHexDigit(scnr) {
|
|
676
|
+
return takeChar(scnr, isHexDigit);
|
|
677
|
+
}
|
|
678
|
+
function getDigits(scnr) {
|
|
679
|
+
let ch = "";
|
|
680
|
+
let num = "";
|
|
681
|
+
while (ch = takeDigit(scnr)) num += ch;
|
|
682
|
+
return num;
|
|
683
|
+
}
|
|
684
|
+
function readText(scnr) {
|
|
685
|
+
let buf = "";
|
|
686
|
+
while (true) {
|
|
687
|
+
const ch = scnr.currentChar();
|
|
688
|
+
if (ch === "\\") {
|
|
689
|
+
const nextCh = scnr.peek();
|
|
690
|
+
if (nextCh === "{" || nextCh === "}" || nextCh === "@" || nextCh === "|" || nextCh === "\\") {
|
|
691
|
+
buf += ch + nextCh;
|
|
692
|
+
scnr.next();
|
|
693
|
+
scnr.next();
|
|
694
|
+
} else {
|
|
695
|
+
scnr.resetPeek();
|
|
696
|
+
buf += ch;
|
|
697
|
+
scnr.next();
|
|
698
|
+
}
|
|
699
|
+
} else if (ch === "{" || ch === "}" || ch === "@" || ch === "|" || !ch) break;
|
|
700
|
+
else if (ch === " " || ch === "\n") if (isTextStart(scnr)) {
|
|
701
|
+
buf += ch;
|
|
702
|
+
scnr.next();
|
|
703
|
+
} else if (isPluralStart(scnr)) break;
|
|
704
|
+
else {
|
|
705
|
+
buf += ch;
|
|
706
|
+
scnr.next();
|
|
707
|
+
}
|
|
708
|
+
else {
|
|
709
|
+
buf += ch;
|
|
710
|
+
scnr.next();
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return buf;
|
|
714
|
+
}
|
|
715
|
+
function readNamedIdentifier(scnr) {
|
|
716
|
+
skipSpaces(scnr);
|
|
717
|
+
let ch = "";
|
|
718
|
+
let name = "";
|
|
719
|
+
while (ch = takeNamedIdentifierChar(scnr)) name += ch;
|
|
720
|
+
const currentChar = scnr.currentChar();
|
|
721
|
+
if (currentChar && currentChar !== "}" && currentChar !== EOF && currentChar !== " " && currentChar !== "\n" && currentChar !== " ") {
|
|
722
|
+
const invalidPart = readInvalidIdentifier(scnr);
|
|
723
|
+
emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, name + invalidPart);
|
|
724
|
+
return name + invalidPart;
|
|
725
|
+
}
|
|
726
|
+
if (scnr.currentChar() === EOF) emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
|
|
727
|
+
return name;
|
|
728
|
+
}
|
|
729
|
+
function readListIdentifier(scnr) {
|
|
730
|
+
skipSpaces(scnr);
|
|
731
|
+
let value = "";
|
|
732
|
+
if (scnr.currentChar() === "-") {
|
|
733
|
+
scnr.next();
|
|
734
|
+
value += `-${getDigits(scnr)}`;
|
|
735
|
+
} else value += getDigits(scnr);
|
|
736
|
+
if (scnr.currentChar() === EOF) emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
|
|
737
|
+
return value;
|
|
738
|
+
}
|
|
739
|
+
function isLiteral(ch) {
|
|
740
|
+
return ch !== LITERAL_DELIMITER && ch !== "\n";
|
|
741
|
+
}
|
|
742
|
+
function readLiteral(scnr) {
|
|
743
|
+
skipSpaces(scnr);
|
|
744
|
+
eat(scnr, `'`);
|
|
745
|
+
let ch = "";
|
|
746
|
+
let literal = "";
|
|
747
|
+
while (ch = takeChar(scnr, isLiteral)) if (ch === "\\") literal += readEscapeSequence(scnr);
|
|
748
|
+
else literal += ch;
|
|
749
|
+
const current = scnr.currentChar();
|
|
750
|
+
if (current === "\n" || current === EOF) {
|
|
751
|
+
emitError(CompileErrorCodes.UNTERMINATED_SINGLE_QUOTE_IN_PLACEHOLDER, currentPosition(), 0);
|
|
752
|
+
if (current === "\n") {
|
|
753
|
+
scnr.next();
|
|
754
|
+
eat(scnr, `'`);
|
|
755
|
+
}
|
|
756
|
+
return literal;
|
|
757
|
+
}
|
|
758
|
+
eat(scnr, `'`);
|
|
759
|
+
return literal;
|
|
760
|
+
}
|
|
761
|
+
function readEscapeSequence(scnr) {
|
|
762
|
+
const ch = scnr.currentChar();
|
|
763
|
+
switch (ch) {
|
|
764
|
+
case "\\":
|
|
765
|
+
case `'`:
|
|
766
|
+
scnr.next();
|
|
767
|
+
return `\\${ch}`;
|
|
768
|
+
case "u": return readUnicodeEscapeSequence(scnr, ch, 4);
|
|
769
|
+
case "U": return readUnicodeEscapeSequence(scnr, ch, 6);
|
|
770
|
+
default:
|
|
771
|
+
emitError(CompileErrorCodes.UNKNOWN_ESCAPE_SEQUENCE, currentPosition(), 0, ch);
|
|
772
|
+
return "";
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
function readUnicodeEscapeSequence(scnr, unicode, digits) {
|
|
776
|
+
eat(scnr, unicode);
|
|
777
|
+
let sequence = "";
|
|
778
|
+
for (let i = 0; i < digits; i++) {
|
|
779
|
+
const ch = takeHexDigit(scnr);
|
|
780
|
+
if (!ch) {
|
|
781
|
+
emitError(CompileErrorCodes.INVALID_UNICODE_ESCAPE_SEQUENCE, currentPosition(), 0, `\\${unicode}${sequence}${scnr.currentChar()}`);
|
|
782
|
+
break;
|
|
783
|
+
}
|
|
784
|
+
sequence += ch;
|
|
785
|
+
}
|
|
786
|
+
return `\\${unicode}${sequence}`;
|
|
787
|
+
}
|
|
788
|
+
function isInvalidIdentifier(ch) {
|
|
789
|
+
return ch !== "{" && ch !== "}" && ch !== " " && ch !== "\n";
|
|
790
|
+
}
|
|
791
|
+
function readInvalidIdentifier(scnr) {
|
|
792
|
+
skipSpaces(scnr);
|
|
793
|
+
let ch = "";
|
|
794
|
+
let identifiers = "";
|
|
795
|
+
while (ch = takeChar(scnr, isInvalidIdentifier)) identifiers += ch;
|
|
796
|
+
return identifiers;
|
|
797
|
+
}
|
|
798
|
+
function readLinkedModifier(scnr) {
|
|
799
|
+
let ch = "";
|
|
800
|
+
let name = "";
|
|
801
|
+
while (ch = takeIdentifierChar(scnr)) name += ch;
|
|
802
|
+
return name;
|
|
803
|
+
}
|
|
804
|
+
function readLinkedRefer(scnr) {
|
|
805
|
+
const fn = (buf) => {
|
|
806
|
+
const ch = scnr.currentChar();
|
|
807
|
+
if (ch === "{" || ch === "@" || ch === "|" || ch === "(" || ch === ")" || !ch) return buf;
|
|
808
|
+
else if (ch === " ") return buf;
|
|
809
|
+
else if (ch === "\n" || ch === DOT) {
|
|
810
|
+
buf += ch;
|
|
811
|
+
scnr.next();
|
|
812
|
+
return fn(buf);
|
|
813
|
+
} else {
|
|
814
|
+
buf += ch;
|
|
815
|
+
scnr.next();
|
|
816
|
+
return fn(buf);
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
return fn("");
|
|
820
|
+
}
|
|
821
|
+
function readPlural(scnr) {
|
|
822
|
+
skipSpaces(scnr);
|
|
823
|
+
const plural = eat(scnr, "|");
|
|
824
|
+
skipSpaces(scnr);
|
|
825
|
+
return plural;
|
|
826
|
+
}
|
|
827
|
+
function readTokenInPlaceholder(scnr, context) {
|
|
828
|
+
let token = null;
|
|
829
|
+
switch (scnr.currentChar()) {
|
|
830
|
+
case "{":
|
|
831
|
+
if (context.braceNest >= 1) emitError(CompileErrorCodes.NOT_ALLOW_NEST_PLACEHOLDER, currentPosition(), 0);
|
|
832
|
+
scnr.next();
|
|
833
|
+
token = getToken(context, 2, "{");
|
|
834
|
+
skipSpaces(scnr);
|
|
835
|
+
context.braceNest++;
|
|
836
|
+
return token;
|
|
837
|
+
case "}":
|
|
838
|
+
if (context.braceNest > 0 && context.currentType === 2) emitError(CompileErrorCodes.EMPTY_PLACEHOLDER, currentPosition(), 0);
|
|
839
|
+
scnr.next();
|
|
840
|
+
token = getToken(context, 3, "}");
|
|
841
|
+
context.braceNest--;
|
|
842
|
+
context.braceNest > 0 && skipSpaces(scnr);
|
|
843
|
+
if (context.inLinked && context.braceNest === 0) context.inLinked = false;
|
|
844
|
+
return token;
|
|
845
|
+
case "@":
|
|
846
|
+
if (context.braceNest > 0) emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
|
|
847
|
+
token = readTokenInLinked(scnr, context) || getEndToken(context);
|
|
848
|
+
context.braceNest = 0;
|
|
849
|
+
return token;
|
|
850
|
+
default: {
|
|
851
|
+
let validNamedIdentifier = true;
|
|
852
|
+
let validListIdentifier = true;
|
|
853
|
+
let validLiteral = true;
|
|
854
|
+
if (isPluralStart(scnr)) {
|
|
855
|
+
if (context.braceNest > 0) emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
|
|
856
|
+
token = getToken(context, 1, readPlural(scnr));
|
|
857
|
+
context.braceNest = 0;
|
|
858
|
+
context.inLinked = false;
|
|
859
|
+
return token;
|
|
860
|
+
}
|
|
861
|
+
if (context.braceNest > 0 && (context.currentType === 4 || context.currentType === 5 || context.currentType === 6)) {
|
|
862
|
+
emitError(CompileErrorCodes.UNTERMINATED_CLOSING_BRACE, currentPosition(), 0);
|
|
863
|
+
context.braceNest = 0;
|
|
864
|
+
return readToken(scnr, context);
|
|
865
|
+
}
|
|
866
|
+
if (validNamedIdentifier = isNamedIdentifierStart(scnr, context)) {
|
|
867
|
+
token = getToken(context, 4, readNamedIdentifier(scnr));
|
|
868
|
+
skipSpaces(scnr);
|
|
869
|
+
return token;
|
|
870
|
+
}
|
|
871
|
+
if (validListIdentifier = isListIdentifierStart(scnr, context)) {
|
|
872
|
+
token = getToken(context, 5, readListIdentifier(scnr));
|
|
873
|
+
skipSpaces(scnr);
|
|
874
|
+
return token;
|
|
875
|
+
}
|
|
876
|
+
if (validLiteral = isLiteralStart(scnr, context)) {
|
|
877
|
+
token = getToken(context, 6, readLiteral(scnr));
|
|
878
|
+
skipSpaces(scnr);
|
|
879
|
+
return token;
|
|
880
|
+
}
|
|
881
|
+
if (!validNamedIdentifier && !validListIdentifier && !validLiteral) {
|
|
882
|
+
token = getToken(context, 12, readInvalidIdentifier(scnr));
|
|
883
|
+
emitError(CompileErrorCodes.INVALID_TOKEN_IN_PLACEHOLDER, currentPosition(), 0, token.value);
|
|
884
|
+
skipSpaces(scnr);
|
|
885
|
+
return token;
|
|
886
|
+
}
|
|
887
|
+
break;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
return token;
|
|
891
|
+
}
|
|
892
|
+
function readTokenInLinked(scnr, context) {
|
|
893
|
+
const { currentType } = context;
|
|
894
|
+
let token = null;
|
|
895
|
+
const ch = scnr.currentChar();
|
|
896
|
+
if ((currentType === 7 || currentType === 8 || currentType === 11 || currentType === 9) && (ch === "\n" || ch === " ")) emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
|
|
897
|
+
switch (ch) {
|
|
898
|
+
case "@":
|
|
899
|
+
scnr.next();
|
|
900
|
+
token = getToken(context, 7, "@");
|
|
901
|
+
context.inLinked = true;
|
|
902
|
+
return token;
|
|
903
|
+
case ".":
|
|
904
|
+
skipSpaces(scnr);
|
|
905
|
+
scnr.next();
|
|
906
|
+
return getToken(context, 8, ".");
|
|
907
|
+
case ":":
|
|
908
|
+
skipSpaces(scnr);
|
|
909
|
+
scnr.next();
|
|
910
|
+
return getToken(context, 9, ":");
|
|
911
|
+
default:
|
|
912
|
+
if (isPluralStart(scnr)) {
|
|
913
|
+
token = getToken(context, 1, readPlural(scnr));
|
|
914
|
+
context.braceNest = 0;
|
|
915
|
+
context.inLinked = false;
|
|
916
|
+
return token;
|
|
917
|
+
}
|
|
918
|
+
if (isLinkedDotStart(scnr, context) || isLinkedDelimiterStart(scnr, context)) {
|
|
919
|
+
skipSpaces(scnr);
|
|
920
|
+
return readTokenInLinked(scnr, context);
|
|
921
|
+
}
|
|
922
|
+
if (isLinkedModifierStart(scnr, context)) {
|
|
923
|
+
skipSpaces(scnr);
|
|
924
|
+
return getToken(context, 11, readLinkedModifier(scnr));
|
|
925
|
+
}
|
|
926
|
+
if (isLinkedReferStart(scnr, context)) {
|
|
927
|
+
skipSpaces(scnr);
|
|
928
|
+
if (ch === "{") return readTokenInPlaceholder(scnr, context) || token;
|
|
929
|
+
else return getToken(context, 10, readLinkedRefer(scnr));
|
|
930
|
+
}
|
|
931
|
+
if (currentType === 7) emitError(CompileErrorCodes.INVALID_LINKED_FORMAT, currentPosition(), 0);
|
|
932
|
+
context.braceNest = 0;
|
|
933
|
+
context.inLinked = false;
|
|
934
|
+
return readToken(scnr, context);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
function readToken(scnr, context) {
|
|
938
|
+
let token = { type: 13 };
|
|
939
|
+
if (context.braceNest > 0) return readTokenInPlaceholder(scnr, context) || getEndToken(context);
|
|
940
|
+
if (context.inLinked) return readTokenInLinked(scnr, context) || getEndToken(context);
|
|
941
|
+
switch (scnr.currentChar()) {
|
|
942
|
+
case "{": return readTokenInPlaceholder(scnr, context) || getEndToken(context);
|
|
943
|
+
case "}":
|
|
944
|
+
emitError(CompileErrorCodes.UNBALANCED_CLOSING_BRACE, currentPosition(), 0);
|
|
945
|
+
scnr.next();
|
|
946
|
+
return getToken(context, 3, "}");
|
|
947
|
+
case "@": return readTokenInLinked(scnr, context) || getEndToken(context);
|
|
948
|
+
default:
|
|
949
|
+
if (isPluralStart(scnr)) {
|
|
950
|
+
token = getToken(context, 1, readPlural(scnr));
|
|
951
|
+
context.braceNest = 0;
|
|
952
|
+
context.inLinked = false;
|
|
953
|
+
return token;
|
|
954
|
+
}
|
|
955
|
+
if (isTextStart(scnr)) return getToken(context, 0, readText(scnr));
|
|
956
|
+
break;
|
|
957
|
+
}
|
|
958
|
+
return token;
|
|
959
|
+
}
|
|
960
|
+
function nextToken() {
|
|
961
|
+
const { currentType, offset, startLoc, endLoc } = _context;
|
|
962
|
+
_context.lastType = currentType;
|
|
963
|
+
_context.lastOffset = offset;
|
|
964
|
+
_context.lastStartLoc = startLoc;
|
|
965
|
+
_context.lastEndLoc = endLoc;
|
|
966
|
+
_context.offset = currentOffset();
|
|
967
|
+
_context.startLoc = currentPosition();
|
|
968
|
+
if (_scnr.currentChar() === EOF) return getToken(_context, 13);
|
|
969
|
+
return readToken(_scnr, _context);
|
|
970
|
+
}
|
|
971
|
+
return {
|
|
972
|
+
nextToken,
|
|
973
|
+
currentOffset,
|
|
974
|
+
currentPosition,
|
|
975
|
+
context
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
//#endregion
|
|
979
|
+
//#region packages/message-compiler/src/parser.ts
|
|
980
|
+
const ERROR_DOMAIN = "parser";
|
|
981
|
+
const KNOWN_ESCAPES = /\\\\|\\'|\\u([0-9a-fA-F]{4})|\\U([0-9a-fA-F]{6})/g;
|
|
982
|
+
const TEXT_ESCAPES = /\\([\\@{}|])/g;
|
|
983
|
+
function fromTextEscapeSequence(_match, char) {
|
|
984
|
+
return char;
|
|
985
|
+
}
|
|
986
|
+
function fromEscapeSequence(match, codePoint4, codePoint6) {
|
|
987
|
+
switch (match) {
|
|
988
|
+
case `\\\\`: return `\\`;
|
|
989
|
+
case `\\'`: return `'`;
|
|
990
|
+
default: {
|
|
991
|
+
const codePoint = parseInt(codePoint4 || codePoint6, 16);
|
|
992
|
+
if (codePoint <= 55295 || codePoint >= 57344) return String.fromCodePoint(codePoint);
|
|
993
|
+
return "�";
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
function createParser(options = {}) {
|
|
998
|
+
const location = options.location !== false;
|
|
999
|
+
const { onError } = options;
|
|
1000
|
+
function emitError(tokenzer, code, start, offset, ...args) {
|
|
1001
|
+
const end = tokenzer.currentPosition();
|
|
1002
|
+
end.offset += offset;
|
|
1003
|
+
end.column += offset;
|
|
1004
|
+
if (onError) onError(createCompileError(code, location ? createLocation(start, end) : null, {
|
|
1005
|
+
domain: ERROR_DOMAIN,
|
|
1006
|
+
args
|
|
1007
|
+
}));
|
|
1008
|
+
}
|
|
1009
|
+
function startNode(type, offset, loc) {
|
|
1010
|
+
const node = { type };
|
|
1011
|
+
if (location) {
|
|
1012
|
+
node.start = offset;
|
|
1013
|
+
node.end = offset;
|
|
1014
|
+
node.loc = {
|
|
1015
|
+
start: loc,
|
|
1016
|
+
end: loc
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
return node;
|
|
1020
|
+
}
|
|
1021
|
+
function endNode(node, offset, pos, type) {
|
|
1022
|
+
if (type) node.type = type;
|
|
1023
|
+
if (location) {
|
|
1024
|
+
node.end = offset;
|
|
1025
|
+
if (node.loc) node.loc.end = pos;
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
function parseText(tokenizer, value) {
|
|
1029
|
+
const context = tokenizer.context();
|
|
1030
|
+
const node = startNode(3, context.offset, context.startLoc);
|
|
1031
|
+
node.value = value.replace(TEXT_ESCAPES, fromTextEscapeSequence);
|
|
1032
|
+
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1033
|
+
return node;
|
|
1034
|
+
}
|
|
1035
|
+
function parseList(tokenizer, index) {
|
|
1036
|
+
const { lastOffset: offset, lastStartLoc: loc } = tokenizer.context();
|
|
1037
|
+
const node = startNode(5, offset, loc);
|
|
1038
|
+
node.index = parseInt(index, 10);
|
|
1039
|
+
tokenizer.nextToken();
|
|
1040
|
+
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1041
|
+
return node;
|
|
1042
|
+
}
|
|
1043
|
+
function parseNamed(tokenizer, key) {
|
|
1044
|
+
const { lastOffset: offset, lastStartLoc: loc } = tokenizer.context();
|
|
1045
|
+
const node = startNode(4, offset, loc);
|
|
1046
|
+
node.key = key;
|
|
1047
|
+
tokenizer.nextToken();
|
|
1048
|
+
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1049
|
+
return node;
|
|
1050
|
+
}
|
|
1051
|
+
function parseLiteral(tokenizer, value) {
|
|
1052
|
+
const { lastOffset: offset, lastStartLoc: loc } = tokenizer.context();
|
|
1053
|
+
const node = startNode(9, offset, loc);
|
|
1054
|
+
node.value = value.replace(KNOWN_ESCAPES, fromEscapeSequence);
|
|
1055
|
+
tokenizer.nextToken();
|
|
1056
|
+
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1057
|
+
return node;
|
|
1058
|
+
}
|
|
1059
|
+
function parseLinkedModifier(tokenizer) {
|
|
1060
|
+
const token = tokenizer.nextToken();
|
|
1061
|
+
const context = tokenizer.context();
|
|
1062
|
+
const { lastOffset: offset, lastStartLoc: loc } = context;
|
|
1063
|
+
const node = startNode(8, offset, loc);
|
|
1064
|
+
if (token.type !== 11) {
|
|
1065
|
+
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_MODIFIER, context.lastStartLoc, 0);
|
|
1066
|
+
node.value = "";
|
|
1067
|
+
endNode(node, offset, loc);
|
|
1068
|
+
return {
|
|
1069
|
+
nextConsumeToken: token,
|
|
1070
|
+
node
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1074
|
+
node.value = token.value || "";
|
|
1075
|
+
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1076
|
+
return { node };
|
|
1077
|
+
}
|
|
1078
|
+
function parseLinkedKey(tokenizer, value) {
|
|
1079
|
+
const context = tokenizer.context();
|
|
1080
|
+
const node = startNode(7, context.offset, context.startLoc);
|
|
1081
|
+
node.value = value;
|
|
1082
|
+
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1083
|
+
return node;
|
|
1084
|
+
}
|
|
1085
|
+
function parseLinked(tokenizer) {
|
|
1086
|
+
const context = tokenizer.context();
|
|
1087
|
+
const linkedNode = startNode(6, context.offset, context.startLoc);
|
|
1088
|
+
let token = tokenizer.nextToken();
|
|
1089
|
+
if (token.type === 8) {
|
|
1090
|
+
const parsed = parseLinkedModifier(tokenizer);
|
|
1091
|
+
linkedNode.modifier = parsed.node;
|
|
1092
|
+
token = parsed.nextConsumeToken || tokenizer.nextToken();
|
|
1093
|
+
}
|
|
1094
|
+
if (token.type !== 9) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1095
|
+
token = tokenizer.nextToken();
|
|
1096
|
+
if (token.type === 2) token = tokenizer.nextToken();
|
|
1097
|
+
switch (token.type) {
|
|
1098
|
+
case 10:
|
|
1099
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1100
|
+
linkedNode.key = parseLinkedKey(tokenizer, token.value || "");
|
|
1101
|
+
break;
|
|
1102
|
+
case 4:
|
|
1103
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1104
|
+
linkedNode.key = parseNamed(tokenizer, token.value || "");
|
|
1105
|
+
break;
|
|
1106
|
+
case 5:
|
|
1107
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1108
|
+
linkedNode.key = parseList(tokenizer, token.value || "");
|
|
1109
|
+
break;
|
|
1110
|
+
case 6:
|
|
1111
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1112
|
+
linkedNode.key = parseLiteral(tokenizer, token.value || "");
|
|
1113
|
+
break;
|
|
1114
|
+
default: {
|
|
1115
|
+
emitError(tokenizer, CompileErrorCodes.UNEXPECTED_EMPTY_LINKED_KEY, context.lastStartLoc, 0);
|
|
1116
|
+
const nextContext = tokenizer.context();
|
|
1117
|
+
const emptyLinkedKeyNode = startNode(7, nextContext.offset, nextContext.startLoc);
|
|
1118
|
+
emptyLinkedKeyNode.value = "";
|
|
1119
|
+
endNode(emptyLinkedKeyNode, nextContext.offset, nextContext.startLoc);
|
|
1120
|
+
linkedNode.key = emptyLinkedKeyNode;
|
|
1121
|
+
endNode(linkedNode, nextContext.offset, nextContext.startLoc);
|
|
1122
|
+
return {
|
|
1123
|
+
nextConsumeToken: token,
|
|
1124
|
+
node: linkedNode
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
endNode(linkedNode, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1129
|
+
return { node: linkedNode };
|
|
1130
|
+
}
|
|
1131
|
+
function parseMessage(tokenizer) {
|
|
1132
|
+
const context = tokenizer.context();
|
|
1133
|
+
const node = startNode(2, context.currentType === 1 ? tokenizer.currentOffset() : context.offset, context.currentType === 1 ? context.endLoc : context.startLoc);
|
|
1134
|
+
node.items = [];
|
|
1135
|
+
let nextToken = null;
|
|
1136
|
+
do {
|
|
1137
|
+
const token = nextToken || tokenizer.nextToken();
|
|
1138
|
+
nextToken = null;
|
|
1139
|
+
switch (token.type) {
|
|
1140
|
+
case 0:
|
|
1141
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1142
|
+
node.items.push(parseText(tokenizer, token.value || ""));
|
|
1143
|
+
break;
|
|
1144
|
+
case 5:
|
|
1145
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1146
|
+
node.items.push(parseList(tokenizer, token.value || ""));
|
|
1147
|
+
break;
|
|
1148
|
+
case 4:
|
|
1149
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1150
|
+
node.items.push(parseNamed(tokenizer, token.value || ""));
|
|
1151
|
+
break;
|
|
1152
|
+
case 6:
|
|
1153
|
+
if (token.value == null) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, getTokenCaption(token));
|
|
1154
|
+
node.items.push(parseLiteral(tokenizer, token.value || ""));
|
|
1155
|
+
break;
|
|
1156
|
+
case 7: {
|
|
1157
|
+
const parsed = parseLinked(tokenizer);
|
|
1158
|
+
node.items.push(parsed.node);
|
|
1159
|
+
nextToken = parsed.nextConsumeToken || null;
|
|
1160
|
+
break;
|
|
1161
|
+
}
|
|
1162
|
+
}
|
|
1163
|
+
} while (context.currentType !== 13 && context.currentType !== 1);
|
|
1164
|
+
endNode(node, context.currentType === 1 ? context.lastOffset : tokenizer.currentOffset(), context.currentType === 1 ? context.lastEndLoc : tokenizer.currentPosition());
|
|
1165
|
+
return node;
|
|
1166
|
+
}
|
|
1167
|
+
function parsePlural(tokenizer, offset, loc, msgNode) {
|
|
1168
|
+
const context = tokenizer.context();
|
|
1169
|
+
let hasEmptyMessage = msgNode.items.length === 0;
|
|
1170
|
+
const node = startNode(1, offset, loc);
|
|
1171
|
+
node.cases = [];
|
|
1172
|
+
node.cases.push(msgNode);
|
|
1173
|
+
do {
|
|
1174
|
+
const msg = parseMessage(tokenizer);
|
|
1175
|
+
if (!hasEmptyMessage) hasEmptyMessage = msg.items.length === 0;
|
|
1176
|
+
node.cases.push(msg);
|
|
1177
|
+
} while (context.currentType !== 13);
|
|
1178
|
+
if (hasEmptyMessage) emitError(tokenizer, CompileErrorCodes.MUST_HAVE_MESSAGES_IN_PLURAL, loc, 0);
|
|
1179
|
+
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1180
|
+
return node;
|
|
1181
|
+
}
|
|
1182
|
+
function parseResource(tokenizer) {
|
|
1183
|
+
const context = tokenizer.context();
|
|
1184
|
+
const { offset, startLoc } = context;
|
|
1185
|
+
const msgNode = parseMessage(tokenizer);
|
|
1186
|
+
if (context.currentType === 13) return msgNode;
|
|
1187
|
+
else return parsePlural(tokenizer, offset, startLoc, msgNode);
|
|
1188
|
+
}
|
|
1189
|
+
function parse(source) {
|
|
1190
|
+
const tokenizer = createTokenizer(source, assign({}, options));
|
|
1191
|
+
const context = tokenizer.context();
|
|
1192
|
+
const node = startNode(0, context.offset, context.startLoc);
|
|
1193
|
+
if (location && node.loc) node.loc.source = source;
|
|
1194
|
+
node.body = parseResource(tokenizer);
|
|
1195
|
+
if (options.onCacheKey) node.cacheKey = options.onCacheKey(source);
|
|
1196
|
+
if (context.currentType !== 13) emitError(tokenizer, CompileErrorCodes.UNEXPECTED_LEXICAL_ANALYSIS, context.lastStartLoc, 0, source[context.offset] || "");
|
|
1197
|
+
endNode(node, tokenizer.currentOffset(), tokenizer.currentPosition());
|
|
1198
|
+
return node;
|
|
1199
|
+
}
|
|
1200
|
+
return { parse };
|
|
1201
|
+
}
|
|
1202
|
+
function getTokenCaption(token) {
|
|
1203
|
+
if (token.type === 13) return "EOF";
|
|
1204
|
+
const name = (token.value || "").replace(/\r?\n/gu, "\\n");
|
|
1205
|
+
return name.length > 10 ? name.slice(0, 9) + "…" : name;
|
|
1206
|
+
}
|
|
1207
|
+
//#endregion
|
|
1208
|
+
//#region packages/message-compiler/src/transformer.ts
|
|
1209
|
+
function createTransformer(ast, _options = {}) {
|
|
1210
|
+
const _context = {
|
|
1211
|
+
ast,
|
|
1212
|
+
helpers: /* @__PURE__ */ new Set()
|
|
1213
|
+
};
|
|
1214
|
+
const context = () => _context;
|
|
1215
|
+
const helper = (name) => {
|
|
1216
|
+
_context.helpers.add(name);
|
|
1217
|
+
return name;
|
|
1218
|
+
};
|
|
1219
|
+
return {
|
|
1220
|
+
context,
|
|
1221
|
+
helper
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
function traverseNodes(nodes, transformer) {
|
|
1225
|
+
for (let i = 0; i < nodes.length; i++) traverseNode(nodes[i], transformer);
|
|
1226
|
+
}
|
|
1227
|
+
function traverseNode(node, transformer) {
|
|
1228
|
+
switch (node.type) {
|
|
1229
|
+
case 1:
|
|
1230
|
+
traverseNodes(node.cases, transformer);
|
|
1231
|
+
transformer.helper("plural");
|
|
1232
|
+
break;
|
|
1233
|
+
case 2:
|
|
1234
|
+
traverseNodes(node.items, transformer);
|
|
1235
|
+
break;
|
|
1236
|
+
case 6:
|
|
1237
|
+
traverseNode(node.key, transformer);
|
|
1238
|
+
transformer.helper("linked");
|
|
1239
|
+
transformer.helper("type");
|
|
1240
|
+
break;
|
|
1241
|
+
case 5:
|
|
1242
|
+
transformer.helper("interpolate");
|
|
1243
|
+
transformer.helper("list");
|
|
1244
|
+
break;
|
|
1245
|
+
case 4:
|
|
1246
|
+
transformer.helper("interpolate");
|
|
1247
|
+
transformer.helper("named");
|
|
1248
|
+
break;
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
function transform(ast, _options = {}) {
|
|
1252
|
+
const transformer = createTransformer(ast);
|
|
1253
|
+
transformer.helper("normalize");
|
|
1254
|
+
ast.body && traverseNode(ast.body, transformer);
|
|
1255
|
+
const context = transformer.context();
|
|
1256
|
+
ast.helpers = Array.from(context.helpers);
|
|
1257
|
+
}
|
|
1258
|
+
//#endregion
|
|
1259
|
+
//#region packages/message-compiler/src/compiler.ts
|
|
1260
|
+
function baseCompile(source, options = {}) {
|
|
1261
|
+
const assignedOptions = assign({}, options);
|
|
1262
|
+
const jit = !!assignedOptions.jit;
|
|
1263
|
+
const enableMangle = !!assignedOptions.mangle;
|
|
1264
|
+
const enableOptimize = assignedOptions.optimize == null ? true : assignedOptions.optimize;
|
|
1265
|
+
const ast = createParser(assignedOptions).parse(source);
|
|
1266
|
+
if (!jit) {
|
|
1267
|
+
transform(ast, assignedOptions);
|
|
1268
|
+
return generate(ast, assignedOptions);
|
|
1269
|
+
} else {
|
|
1270
|
+
enableOptimize && optimize(ast);
|
|
1271
|
+
enableMangle && mangle(ast);
|
|
1272
|
+
return {
|
|
1273
|
+
ast,
|
|
1274
|
+
code: ""
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
//#endregion
|
|
1279
|
+
exports.COMPILE_ERROR_CODES_EXTEND_POINT = COMPILE_ERROR_CODES_EXTEND_POINT;
|
|
1280
|
+
exports.CompileErrorCodes = CompileErrorCodes;
|
|
1281
|
+
exports.ERROR_DOMAIN = ERROR_DOMAIN;
|
|
1282
|
+
exports.HelperNameMap = HelperNameMap;
|
|
1283
|
+
exports.LOCATION_STUB = LOCATION_STUB;
|
|
1284
|
+
exports.NodeTypes = NodeTypes;
|
|
1285
|
+
exports.baseCompile = baseCompile;
|
|
1286
|
+
exports.createCompileError = createCompileError;
|
|
1287
|
+
exports.createLocation = createLocation;
|
|
1288
|
+
exports.createParser = createParser;
|
|
1289
|
+
exports.createPosition = createPosition;
|
|
1290
|
+
exports.defaultOnError = defaultOnError;
|
|
1291
|
+
exports.detectHtmlTag = detectHtmlTag;
|
|
1292
|
+
exports.errorMessages = errorMessages;
|
|
1293
|
+
exports.mangle = mangle;
|
|
1294
|
+
exports.optimize = optimize;
|
|
1295
|
+
return exports;
|
|
1562
1296
|
})({});
|