javascript - typescript_test.go
1 package javascript
2
3 import (
4 "fmt"
5 "testing"
6
7 "vimagination.zapto.org/parser"
8 )
9
10 func TestTypescriptModule(t *testing.T) {
11 doTests(t, []sourceFn{
12 {`import def from './a';import type typeDef from './b';import type {typ1, typ2} from './c';import {a} from './d';`, func(t *test, tk Tokens) { // 1
13 t.Typescript = true
14 t.Output = Module{
15 ModuleListItems: []ModuleItem{
16 {
17 ImportDeclaration: &ImportDeclaration{
18 ImportClause: &ImportClause{
19 ImportedDefaultBinding: &tk[2],
20 Tokens: tk[2:3],
21 },
22 FromClause: FromClause{
23 ModuleSpecifier: &tk[6],
24 Tokens: tk[4:7],
25 },
26 Tokens: tk[:8],
27 },
28 Tokens: tk[:8],
29 },
30 {
31 StatementListItem: &StatementListItem{
32 Statement: &Statement{
33 Tokens: tk[8:18],
34 },
35 Tokens: tk[8:18],
36 },
37 Tokens: tk[8:18],
38 },
39 {
40 StatementListItem: &StatementListItem{
41 Statement: &Statement{
42 Tokens: tk[18:33],
43 },
44 Tokens: tk[18:33],
45 },
46 Tokens: tk[18:33],
47 },
48 {
49 ImportDeclaration: &ImportDeclaration{
50 ImportClause: &ImportClause{
51 NamedImports: &NamedImports{
52 ImportList: []ImportSpecifier{
53 {
54 IdentifierName: &tk[36],
55 ImportedBinding: &tk[36],
56 Tokens: tk[36:37],
57 },
58 },
59 Tokens: tk[35:38],
60 },
61 Tokens: tk[35:38],
62 },
63 FromClause: FromClause{
64 ModuleSpecifier: &tk[41],
65 Tokens: tk[39:42],
66 },
67 Tokens: tk[33:43],
68 },
69 Tokens: tk[33:43],
70 },
71 },
72 Tokens: tk[:43],
73 }
74 }},
75 {`import def from './a';import type typeDef from './b';import type {typ1, typ2} from './c';import {a} from './d';`, func(t *test, tk Tokens) { // 2
76 t.Err = Error{
77 Err: Error{
78 Err: Error{
79 Err: ErrMissingFrom,
80 Parsing: "FromClause",
81 Token: tk[12],
82 },
83 Parsing: "ImportDeclaration",
84 Token: tk[12],
85 },
86 Parsing: "ModuleItem",
87 Token: tk[8],
88 }
89 }},
90 {`class A {
91 private;
92 public
93 protected;
94 a
95 private A
96 protected B;
97 public C
98 private static D;
99 protected static E
100 public static F
101 }`, func(t *test, tk Tokens) { // 3
102 t.Typescript = true
103 t.Output = Module{
104 ModuleListItems: []ModuleItem{
105 {
106 StatementListItem: &StatementListItem{
107 Declaration: &Declaration{
108 ClassDeclaration: &ClassDeclaration{
109 BindingIdentifier: &tk[2],
110 ClassBody: []ClassElement{
111 {
112 FieldDefinition: &FieldDefinition{
113 ClassElementName: ClassElementName{
114 PropertyName: &PropertyName{
115 LiteralPropertyName: &tk[6],
116 Tokens: tk[6:7],
117 },
118 Tokens: tk[6:7],
119 },
120 Tokens: tk[6:7],
121 },
122 Tokens: tk[6:8],
123 },
124 {
125 FieldDefinition: &FieldDefinition{
126 ClassElementName: ClassElementName{
127 PropertyName: &PropertyName{
128 LiteralPropertyName: &tk[9],
129 Tokens: tk[9:10],
130 },
131 Tokens: tk[9:10],
132 },
133 Tokens: tk[9:10],
134 },
135 Tokens: tk[9:10],
136 },
137 {
138 FieldDefinition: &FieldDefinition{
139 ClassElementName: ClassElementName{
140 PropertyName: &PropertyName{
141 LiteralPropertyName: &tk[11],
142 Tokens: tk[11:12],
143 },
144 Tokens: tk[11:12],
145 },
146 Tokens: tk[11:12],
147 },
148 Tokens: tk[11:13],
149 },
150 {
151 FieldDefinition: &FieldDefinition{
152 ClassElementName: ClassElementName{
153 PropertyName: &PropertyName{
154 LiteralPropertyName: &tk[14],
155 Tokens: tk[14:15],
156 },
157 Tokens: tk[14:15],
158 },
159 Tokens: tk[14:15],
160 },
161 Tokens: tk[14:15],
162 },
163 {
164 FieldDefinition: &FieldDefinition{
165 ClassElementName: ClassElementName{
166 PropertyName: &PropertyName{
167 LiteralPropertyName: &tk[18],
168 Tokens: tk[18:19],
169 },
170 Tokens: tk[18:19],
171 },
172 Tokens: tk[18:19],
173 },
174 Tokens: tk[16:19],
175 },
176 {
177 FieldDefinition: &FieldDefinition{
178 ClassElementName: ClassElementName{
179 PropertyName: &PropertyName{
180 LiteralPropertyName: &tk[22],
181 Tokens: tk[22:23],
182 },
183 Tokens: tk[22:23],
184 },
185 Tokens: tk[22:23],
186 },
187 Tokens: tk[20:24],
188 },
189 {
190 FieldDefinition: &FieldDefinition{
191 ClassElementName: ClassElementName{
192 PropertyName: &PropertyName{
193 LiteralPropertyName: &tk[27],
194 Tokens: tk[27:28],
195 },
196 Tokens: tk[27:28],
197 },
198 Tokens: tk[27:28],
199 },
200 Tokens: tk[25:28],
201 },
202 {
203 Static: true,
204 FieldDefinition: &FieldDefinition{
205 ClassElementName: ClassElementName{
206 PropertyName: &PropertyName{
207 LiteralPropertyName: &tk[33],
208 Tokens: tk[33:34],
209 },
210 Tokens: tk[33:34],
211 },
212 Tokens: tk[33:34],
213 },
214 Tokens: tk[29:35],
215 },
216 {
217 Static: true,
218 FieldDefinition: &FieldDefinition{
219 ClassElementName: ClassElementName{
220 PropertyName: &PropertyName{
221 LiteralPropertyName: &tk[40],
222 Tokens: tk[40:41],
223 },
224 Tokens: tk[40:41],
225 },
226 Tokens: tk[40:41],
227 },
228 Tokens: tk[36:41],
229 },
230 {
231 Static: true,
232 FieldDefinition: &FieldDefinition{
233 ClassElementName: ClassElementName{
234 PropertyName: &PropertyName{
235 LiteralPropertyName: &tk[46],
236 Tokens: tk[46:47],
237 },
238 Tokens: tk[46:47],
239 },
240 Tokens: tk[46:47],
241 },
242 Tokens: tk[42:47],
243 },
244 },
245 Tokens: tk[:49],
246 },
247 Tokens: tk[:49],
248 },
249 Tokens: tk[:49],
250 },
251 Tokens: tk[:49],
252 },
253 },
254 Tokens: tk[:49],
255 }
256 }},
257 {`class A {
258 private;
259 public
260 protected;
261 a
262 private A
263 protected B;
264 public C
265 private static D;
266 protected static E
267 public static F
268 }`, func(t *test, tk Tokens) { // 4
269 t.Err = Error{
270 Err: Error{
271 Err: Error{
272 Err: Error{
273 Err: Error{
274 Err: ErrMissingSemiColon,
275 Parsing: "ClassElement",
276 Token: tk[18],
277 },
278 Parsing: "ClassDeclaration",
279 Token: tk[16],
280 },
281 Parsing: "Declaration",
282 Token: tk[0],
283 },
284 Parsing: "StatementListItem",
285 Token: tk[0],
286 },
287 Parsing: "ModuleItem",
288 Token: tk[0],
289 }
290 }},
291 {`class A {
292 readonly;
293 a
294 readonly A
295 private readonly B
296 protected readonly C;
297 public readonly D
298 static readonly E;
299 }`, func(t *test, tk Tokens) { // 5
300 t.Typescript = true
301 t.Output = Module{
302 ModuleListItems: []ModuleItem{
303 {
304 StatementListItem: &StatementListItem{
305 Declaration: &Declaration{
306 ClassDeclaration: &ClassDeclaration{
307 BindingIdentifier: &tk[2],
308 ClassBody: []ClassElement{
309 {
310 FieldDefinition: &FieldDefinition{
311 ClassElementName: ClassElementName{
312 PropertyName: &PropertyName{
313 LiteralPropertyName: &tk[6],
314 Tokens: tk[6:7],
315 },
316 Tokens: tk[6:7],
317 },
318 Tokens: tk[6:7],
319 },
320 Tokens: tk[6:8],
321 },
322 {
323 FieldDefinition: &FieldDefinition{
324 ClassElementName: ClassElementName{
325 PropertyName: &PropertyName{
326 LiteralPropertyName: &tk[9],
327 Tokens: tk[9:10],
328 },
329 Tokens: tk[9:10],
330 },
331 Tokens: tk[9:10],
332 },
333 Tokens: tk[9:10],
334 },
335 {
336 FieldDefinition: &FieldDefinition{
337 ClassElementName: ClassElementName{
338 PropertyName: &PropertyName{
339 LiteralPropertyName: &tk[13],
340 Tokens: tk[13:14],
341 },
342 Tokens: tk[13:14],
343 },
344 Tokens: tk[13:14],
345 },
346 Tokens: tk[11:14],
347 },
348 {
349 FieldDefinition: &FieldDefinition{
350 ClassElementName: ClassElementName{
351 PropertyName: &PropertyName{
352 LiteralPropertyName: &tk[19],
353 Tokens: tk[19:20],
354 },
355 Tokens: tk[19:20],
356 },
357 Tokens: tk[19:20],
358 },
359 Tokens: tk[15:20],
360 },
361 {
362 FieldDefinition: &FieldDefinition{
363 ClassElementName: ClassElementName{
364 PropertyName: &PropertyName{
365 LiteralPropertyName: &tk[25],
366 Tokens: tk[25:26],
367 },
368 Tokens: tk[25:26],
369 },
370 Tokens: tk[25:26],
371 },
372 Tokens: tk[21:27],
373 },
374 {
375 FieldDefinition: &FieldDefinition{
376 ClassElementName: ClassElementName{
377 PropertyName: &PropertyName{
378 LiteralPropertyName: &tk[32],
379 Tokens: tk[32:33],
380 },
381 Tokens: tk[32:33],
382 },
383 Tokens: tk[32:33],
384 },
385 Tokens: tk[28:33],
386 },
387 {
388 Static: true,
389 FieldDefinition: &FieldDefinition{
390 ClassElementName: ClassElementName{
391 PropertyName: &PropertyName{
392 LiteralPropertyName: &tk[38],
393 Tokens: tk[38:39],
394 },
395 Tokens: tk[38:39],
396 },
397 Tokens: tk[38:39],
398 },
399 Tokens: tk[34:40],
400 },
401 },
402 Tokens: tk[:42],
403 },
404 Tokens: tk[:42],
405 },
406 Tokens: tk[:42],
407 },
408 Tokens: tk[:42],
409 },
410 },
411 Tokens: tk[:42],
412 }
413 }},
414 {`class A {
415 readonly;
416 a
417 readonly A
418 private readonly B
419 protected readonly C;
420 public readonly D
421 static readonly E;
422 }`, func(t *test, tk Tokens) { // 6
423 t.Err = Error{
424 Err: Error{
425 Err: Error{
426 Err: Error{
427 Err: Error{
428 Err: ErrMissingSemiColon,
429 Parsing: "ClassElement",
430 Token: tk[13],
431 },
432 Parsing: "ClassDeclaration",
433 Token: tk[11],
434 },
435 Parsing: "Declaration",
436 Token: tk[0],
437 },
438 Parsing: "StatementListItem",
439 Token: tk[0],
440 },
441 Parsing: "ModuleItem",
442 Token: tk[0],
443 }
444 }},
445 {`import {type} from 'a';`, func(t *test, tk Tokens) { // 7
446 t.Typescript = true
447 t.Output = Module{
448 ModuleListItems: []ModuleItem{
449 {
450 ImportDeclaration: &ImportDeclaration{
451 ImportClause: &ImportClause{
452 NamedImports: &NamedImports{
453 ImportList: []ImportSpecifier{
454 {
455 IdentifierName: &tk[3],
456 ImportedBinding: &tk[3],
457 Tokens: tk[3:4],
458 },
459 },
460 Tokens: tk[2:5],
461 },
462 Tokens: tk[2:5],
463 },
464 FromClause: FromClause{
465 ModuleSpecifier: &tk[8],
466 Tokens: tk[6:9],
467 },
468 Tokens: tk[:10],
469 },
470 Tokens: tk[:10],
471 },
472 },
473 Tokens: tk[:10],
474 }
475 }},
476 {`import {type A} from 'a';`, func(t *test, tk Tokens) { // 8
477 t.Typescript = true
478 t.Output = Module{
479 ModuleListItems: []ModuleItem{
480 {
481 ImportDeclaration: &ImportDeclaration{
482 ImportClause: &ImportClause{
483 NamedImports: &NamedImports{
484 Tokens: tk[2:7],
485 },
486 Tokens: tk[2:7],
487 },
488 FromClause: FromClause{
489 ModuleSpecifier: &tk[10],
490 Tokens: tk[8:11],
491 },
492 Tokens: tk[:12],
493 },
494 Tokens: tk[:12],
495 },
496 },
497 Tokens: tk[:12],
498 }
499 }},
500 {`import {type A} from 'a';`, func(t *test, tk Tokens) { // 9
501 t.Err = Error{
502 Err: Error{
503 Err: Error{
504 Err: Error{
505 Err: ErrInvalidNamedImport,
506 Parsing: "NamedImports",
507 Token: tk[5],
508 },
509 Parsing: "ImportClause",
510 Token: tk[2],
511 },
512 Parsing: "ImportDeclaration",
513 Token: tk[2],
514 },
515 Parsing: "ModuleItem",
516 Token: tk[0],
517 }
518 }},
519 {`import {type as} from 'a';`, func(t *test, tk Tokens) { // 10
520 t.Typescript = true
521 t.Output = Module{
522 ModuleListItems: []ModuleItem{
523 {
524 ImportDeclaration: &ImportDeclaration{
525 ImportClause: &ImportClause{
526 NamedImports: &NamedImports{
527 Tokens: tk[2:7],
528 },
529 Tokens: tk[2:7],
530 },
531 FromClause: FromClause{
532 ModuleSpecifier: &tk[10],
533 Tokens: tk[8:11],
534 },
535 Tokens: tk[:12],
536 },
537 Tokens: tk[:12],
538 },
539 },
540 Tokens: tk[:12],
541 }
542 }},
543 {`import {type as as} from 'a';`, func(t *test, tk Tokens) { // 11
544 t.Typescript = true
545 t.Output = Module{
546 ModuleListItems: []ModuleItem{
547 {
548 ImportDeclaration: &ImportDeclaration{
549 ImportClause: &ImportClause{
550 NamedImports: &NamedImports{
551 ImportList: []ImportSpecifier{
552 {
553 IdentifierName: &tk[3],
554 ImportedBinding: &tk[7],
555 Tokens: tk[3:8],
556 },
557 },
558 Tokens: tk[2:9],
559 },
560 Tokens: tk[2:9],
561 },
562 FromClause: FromClause{
563 ModuleSpecifier: &tk[12],
564 Tokens: tk[10:13],
565 },
566 Tokens: tk[:14],
567 },
568 Tokens: tk[:14],
569 },
570 },
571 Tokens: tk[:14],
572 }
573 }},
574 {`import {type as as as} from 'a';`, func(t *test, tk Tokens) { // 12
575 t.Typescript = true
576 t.Output = Module{
577 ModuleListItems: []ModuleItem{
578 {
579 ImportDeclaration: &ImportDeclaration{
580 ImportClause: &ImportClause{
581 NamedImports: &NamedImports{
582 Tokens: tk[2:11],
583 },
584 Tokens: tk[2:11],
585 },
586 FromClause: FromClause{
587 ModuleSpecifier: &tk[14],
588 Tokens: tk[12:15],
589 },
590 Tokens: tk[:16],
591 },
592 Tokens: tk[:16],
593 },
594 },
595 Tokens: tk[:16],
596 }
597 }},
598 {`{}
599 type B = number;
600 {}`, func(t *test, tk Tokens) { // 13
601 t.Typescript = true
602 t.Output = Module{
603 ModuleListItems: []ModuleItem{
604 {
605 StatementListItem: &StatementListItem{
606 Statement: &Statement{
607 BlockStatement: &Block{
608 Tokens: tk[:2],
609 },
610 Tokens: tk[:2],
611 },
612 Tokens: tk[:2],
613 },
614 Tokens: tk[:2],
615 },
616 {
617 StatementListItem: &StatementListItem{
618 Statement: &Statement{
619 Tokens: tk[3:11],
620 },
621 Tokens: tk[3:11],
622 },
623 Tokens: tk[3:11],
624 },
625 {
626 StatementListItem: &StatementListItem{
627 Statement: &Statement{
628 BlockStatement: &Block{
629 Tokens: tk[12:14],
630 },
631 Tokens: tk[12:14],
632 },
633 Tokens: tk[12:14],
634 },
635 Tokens: tk[12:14],
636 },
637 },
638 Tokens: tk[:14],
639 }
640 }},
641 {`{}
642 type B = number;
643 {}`, func(t *test, tk Tokens) { // 14
644 t.Err = Error{
645 Err: Error{
646 Err: Error{
647 Err: ErrMissingSemiColon,
648 Parsing: "Statement",
649 Token: tk[4],
650 },
651 Parsing: "StatementListItem",
652 Token: tk[3],
653 },
654 Parsing: "ModuleItem",
655 Token: tk[3],
656 }
657 }},
658 {`class A<B, C> extends D<E> implements F, G<H> {}`, func(t *test, tk Tokens) { // 15
659 t.Typescript = true
660 t.Output = Module{
661 ModuleListItems: []ModuleItem{
662 {
663 StatementListItem: &StatementListItem{
664 Declaration: &Declaration{
665 ClassDeclaration: &ClassDeclaration{
666 BindingIdentifier: &tk[2],
667 ClassHeritage: &LeftHandSideExpression{
668 NewExpression: &NewExpression{
669 MemberExpression: MemberExpression{
670 PrimaryExpression: &PrimaryExpression{
671 IdentifierReference: &tk[12],
672 Tokens: tk[12:13],
673 },
674 Tokens: tk[12:13],
675 },
676 Tokens: tk[12:13],
677 },
678 Tokens: tk[12:13],
679 },
680 Tokens: tk[:29],
681 },
682 Tokens: tk[:29],
683 },
684 Tokens: tk[:29],
685 },
686 Tokens: tk[:29],
687 },
688 },
689 Tokens: tk[:29],
690 }
691 }},
692 {`class A<B, C> extends D<E> implements F, G<H> {}`, func(t *test, tk Tokens) { // 16
693 t.Err = Error{
694 Err: Error{
695 Err: Error{
696 Err: Error{
697 Err: ErrMissingOpeningBrace,
698 Parsing: "ClassDeclaration",
699 Token: tk[3],
700 },
701 Parsing: "Declaration",
702 Token: tk[0],
703 },
704 Parsing: "StatementListItem",
705 Token: tk[0],
706 },
707 Parsing: "ModuleItem",
708 Token: tk[0],
709 }
710 }},
711 {`class A extends D<E> implements F, G<H> {}`, func(t *test, tk Tokens) { // 17
712 t.Err = Error{
713 Err: Error{
714 Err: Error{
715 Err: Error{
716 Err: ErrMissingOpeningBrace,
717 Parsing: "ClassDeclaration",
718 Token: tk[7],
719 },
720 Parsing: "Declaration",
721 Token: tk[0],
722 },
723 Parsing: "StatementListItem",
724 Token: tk[0],
725 },
726 Parsing: "ModuleItem",
727 Token: tk[0],
728 }
729 }},
730 {`class A extends D implements F, G<H> {}`, func(t *test, tk Tokens) { // 18
731 t.Err = Error{
732 Err: Error{
733 Err: Error{
734 Err: Error{
735 Err: ErrMissingOpeningBrace,
736 Parsing: "ClassDeclaration",
737 Token: tk[8],
738 },
739 Parsing: "Declaration",
740 Token: tk[0],
741 },
742 Parsing: "StatementListItem",
743 Token: tk[0],
744 },
745 Parsing: "ModuleItem",
746 Token: tk[0],
747 }
748 }},
749 {`class A<B, C> implements D, E<F> extends G<H> {}`, func(t *test, tk Tokens) { // 19
750 t.Typescript = true
751 t.Output = Module{
752 ModuleListItems: []ModuleItem{
753 {
754 StatementListItem: &StatementListItem{
755 Declaration: &Declaration{
756 ClassDeclaration: &ClassDeclaration{
757 BindingIdentifier: &tk[2],
758 ClassHeritage: &LeftHandSideExpression{
759 NewExpression: &NewExpression{
760 MemberExpression: MemberExpression{
761 PrimaryExpression: &PrimaryExpression{
762 IdentifierReference: &tk[22],
763 Tokens: tk[22:23],
764 },
765 Tokens: tk[22:23],
766 },
767 Tokens: tk[22:23],
768 },
769 Tokens: tk[22:23],
770 },
771 Tokens: tk[:29],
772 },
773 Tokens: tk[:29],
774 },
775 Tokens: tk[:29],
776 },
777 Tokens: tk[:29],
778 },
779 },
780 Tokens: tk[:29],
781 }
782 }},
783 {`class A implements D, E<F> extends G<H> {}`, func(t *test, tk Tokens) { // 20
784 t.Err = Error{
785 Err: Error{
786 Err: Error{
787 Err: Error{
788 Err: ErrMissingOpeningBrace,
789 Parsing: "ClassDeclaration",
790 Token: tk[4],
791 },
792 Parsing: "Declaration",
793 Token: tk[0],
794 },
795 Parsing: "StatementListItem",
796 Token: tk[0],
797 },
798 Parsing: "ModuleItem",
799 Token: tk[0],
800 }
801 }},
802 {`class A {
803 b(): C {}
804 get d(): E {}
805 set f(g): H {}
806 i <J> () {}
807 }`, func(t *test, tk Tokens) { // 21
808 t.Typescript = true
809 t.Output = Module{
810 ModuleListItems: []ModuleItem{
811 {
812 StatementListItem: &StatementListItem{
813 Declaration: &Declaration{
814 ClassDeclaration: &ClassDeclaration{
815 BindingIdentifier: &tk[2],
816 ClassBody: []ClassElement{
817 {
818 MethodDefinition: &MethodDefinition{
819 ClassElementName: ClassElementName{
820 PropertyName: &PropertyName{
821 LiteralPropertyName: &tk[6],
822 Tokens: tk[6:7],
823 },
824 Tokens: tk[6:7],
825 },
826 Params: FormalParameters{
827 Tokens: tk[7:9],
828 },
829 FunctionBody: Block{
830 Tokens: tk[13:15],
831 },
832 Tokens: tk[6:15],
833 },
834 Tokens: tk[6:15],
835 },
836 {
837 MethodDefinition: &MethodDefinition{
838 Type: MethodGetter,
839 ClassElementName: ClassElementName{
840 PropertyName: &PropertyName{
841 LiteralPropertyName: &tk[18],
842 Tokens: tk[18:19],
843 },
844 Tokens: tk[18:19],
845 },
846 Params: FormalParameters{
847 Tokens: tk[19:21],
848 },
849 FunctionBody: Block{
850 Tokens: tk[25:27],
851 },
852 Tokens: tk[16:27],
853 },
854 Tokens: tk[16:27],
855 },
856 {
857 MethodDefinition: &MethodDefinition{
858 Type: MethodSetter,
859 ClassElementName: ClassElementName{
860 PropertyName: &PropertyName{
861 LiteralPropertyName: &tk[30],
862 Tokens: tk[30:31],
863 },
864 Tokens: tk[30:31],
865 },
866 Params: FormalParameters{
867 FormalParameterList: []BindingElement{
868 {
869 SingleNameBinding: &tk[32],
870 Tokens: tk[32:33],
871 },
872 },
873 Tokens: tk[31:34],
874 },
875 FunctionBody: Block{
876 Tokens: tk[38:40],
877 },
878 Tokens: tk[28:40],
879 },
880 Tokens: tk[28:40],
881 },
882 {
883 MethodDefinition: &MethodDefinition{
884 ClassElementName: ClassElementName{
885 PropertyName: &PropertyName{
886 LiteralPropertyName: &tk[41],
887 Tokens: tk[41:42],
888 },
889 Tokens: tk[41:42],
890 },
891 Params: FormalParameters{
892 Tokens: tk[47:49],
893 },
894 FunctionBody: Block{
895 Tokens: tk[50:52],
896 },
897 Tokens: tk[41:52],
898 },
899 Tokens: tk[41:52],
900 },
901 },
902 Tokens: tk[:54],
903 },
904 Tokens: tk[:54],
905 },
906 Tokens: tk[:54],
907 },
908 Tokens: tk[:54],
909 },
910 },
911 Tokens: tk[:54],
912 }
913 }},
914 {`class A {
915 b(): C {}
916 get d(): E {}
917 set f(g): H {}
918 i <J> () {}
919 }`, func(t *test, tk Tokens) { // 22
920 t.Err = Error{
921 Err: Error{
922 Err: Error{
923 Err: Error{
924 Err: Error{
925 Err: Error{
926 Err: Error{
927 Err: ErrMissingOpeningBrace,
928 Parsing: "Block",
929 Token: tk[9],
930 },
931 Parsing: "MethodDefinition",
932 Token: tk[9],
933 },
934 Parsing: "ClassElement",
935 Token: tk[6],
936 },
937 Parsing: "ClassDeclaration",
938 Token: tk[6],
939 },
940 Parsing: "Declaration",
941 Token: tk[0],
942 },
943 Parsing: "StatementListItem",
944 Token: tk[0],
945 },
946 Parsing: "ModuleItem",
947 Token: tk[0],
948 }
949 }},
950 {`function A<B>(c: D, [e, f]?: [number, string], {g}: {g: boolean}, ...i: J): K {}`, func(t *test, tk Tokens) { // 23
951 t.Typescript = true
952 t.Output = Module{
953 ModuleListItems: []ModuleItem{
954 {
955 StatementListItem: &StatementListItem{
956 Declaration: &Declaration{
957 FunctionDeclaration: &FunctionDeclaration{
958 BindingIdentifier: &tk[2],
959 FormalParameters: FormalParameters{
960 FormalParameterList: []BindingElement{
961 {
962 SingleNameBinding: &tk[7],
963 Tokens: tk[7:11],
964 },
965 {
966 ArrayBindingPattern: &ArrayBindingPattern{
967 BindingElementList: []BindingElement{
968 {
969 SingleNameBinding: &tk[14],
970 Tokens: tk[14:15],
971 },
972 {
973 SingleNameBinding: &tk[17],
974 Tokens: tk[17:18],
975 },
976 },
977 Tokens: tk[13:19],
978 },
979 Tokens: tk[13:28],
980 },
981 {
982 ObjectBindingPattern: &ObjectBindingPattern{
983 BindingPropertyList: []BindingProperty{
984 {
985 PropertyName: PropertyName{
986 LiteralPropertyName: &tk[31],
987 Tokens: tk[31:32],
988 },
989 BindingElement: BindingElement{
990 SingleNameBinding: &tk[31],
991 Tokens: tk[31:32],
992 },
993 Tokens: tk[31:32],
994 },
995 },
996 Tokens: tk[30:33],
997 },
998 Tokens: tk[30:41],
999 },
1000 },
1001 BindingIdentifier: &tk[44],
1002 Tokens: tk[6:49],
1003 },
1004 FunctionBody: Block{
1005 Tokens: tk[53:55],
1006 },
1007 Tokens: tk[:55],
1008 },
1009 Tokens: tk[:55],
1010 },
1011 Tokens: tk[:55],
1012 },
1013 Tokens: tk[:55],
1014 },
1015 },
1016 Tokens: tk[:55],
1017 }
1018 }},
1019 {`function A<B>(c: D, [e, f]?: [number, string], {g}: {g: boolean}, ...i: J): K {}`, func(t *test, tk Tokens) { // 24
1020 t.Err = Error{
1021 Err: Error{
1022 Err: Error{
1023 Err: Error{
1024 Err: Error{
1025 Err: ErrMissingOpeningParenthesis,
1026 Parsing: "FormalParameters",
1027 Token: tk[3],
1028 },
1029 Parsing: "FunctionDeclaration",
1030 Token: tk[3],
1031 },
1032 Parsing: "Declaration",
1033 Token: tk[0],
1034 },
1035 Parsing: "StatementListItem",
1036 Token: tk[0],
1037 },
1038 Parsing: "ModuleItem",
1039 Token: tk[0],
1040 }
1041 }},
1042 {`1 as number`, func(t *test, tk Tokens) { // 25
1043 t.Typescript = true
1044 t.Output = Module{
1045 ModuleListItems: []ModuleItem{
1046 {
1047 StatementListItem: &StatementListItem{
1048 Statement: &Statement{
1049 ExpressionStatement: &Expression{
1050 Expressions: []AssignmentExpression{
1051 {
1052 ConditionalExpression: WrapConditional(&LeftHandSideExpression{
1053 NewExpression: &NewExpression{
1054 MemberExpression: MemberExpression{
1055 PrimaryExpression: &PrimaryExpression{
1056 Literal: &tk[0],
1057 Tokens: tk[0:1],
1058 },
1059 Tokens: tk[0:1],
1060 },
1061 Tokens: tk[0:1],
1062 },
1063 Tokens: tk[0:5],
1064 }),
1065 Tokens: tk[:5],
1066 },
1067 },
1068 Tokens: tk[:5],
1069 },
1070 Tokens: tk[:5],
1071 },
1072 Tokens: tk[:5],
1073 },
1074 Tokens: tk[:5],
1075 },
1076 },
1077 Tokens: tk[:5],
1078 }
1079 }},
1080 {`1 as number`, func(t *test, tk Tokens) { // 26
1081 t.Err = Error{
1082 Err: Error{
1083 Err: Error{
1084 Err: ErrMissingSemiColon,
1085 Parsing: "Statement",
1086 Token: tk[1],
1087 },
1088 Parsing: "StatementListItem",
1089 Token: tk[0],
1090 },
1091 Parsing: "ModuleItem",
1092 Token: tk[0],
1093 }
1094 }},
1095 {`function a(this){}`, func(t *test, tk Tokens) { // 27
1096 t.Typescript = true
1097 t.Output = Module{
1098 ModuleListItems: []ModuleItem{
1099 {
1100 StatementListItem: &StatementListItem{
1101 Declaration: &Declaration{
1102 FunctionDeclaration: &FunctionDeclaration{
1103 BindingIdentifier: &tk[2],
1104 FormalParameters: FormalParameters{
1105 Tokens: tk[3:6],
1106 },
1107 FunctionBody: Block{
1108 Tokens: tk[6:8],
1109 },
1110 Tokens: tk[:8],
1111 },
1112 Tokens: tk[:8],
1113 },
1114 Tokens: tk[:8],
1115 },
1116 Tokens: tk[:8],
1117 },
1118 },
1119 Tokens: tk[:8],
1120 }
1121 }},
1122 {`function a(this){}`, func(t *test, tk Tokens) { // 28
1123 t.Err = Error{
1124 Err: Error{
1125 Err: Error{
1126 Err: Error{
1127 Err: Error{
1128 Err: Error{
1129 Err: ErrNoIdentifier,
1130 Parsing: "BindingElement",
1131 Token: tk[4],
1132 },
1133 Parsing: "FormalParameters",
1134 Token: tk[4],
1135 },
1136 Parsing: "FunctionDeclaration",
1137 Token: tk[3],
1138 },
1139 Parsing: "Declaration",
1140 Token: tk[0],
1141 },
1142 Parsing: "StatementListItem",
1143 Token: tk[0],
1144 },
1145 Parsing: "ModuleItem",
1146 Token: tk[0],
1147 }
1148 }},
1149 {`function a(this: T){}`, func(t *test, tk Tokens) { // 29
1150 t.Typescript = true
1151 t.Output = Module{
1152 ModuleListItems: []ModuleItem{
1153 {
1154 StatementListItem: &StatementListItem{
1155 Declaration: &Declaration{
1156 FunctionDeclaration: &FunctionDeclaration{
1157 BindingIdentifier: &tk[2],
1158 FormalParameters: FormalParameters{
1159 Tokens: tk[3:9],
1160 },
1161 FunctionBody: Block{
1162 Tokens: tk[9:11],
1163 },
1164 Tokens: tk[:11],
1165 },
1166 Tokens: tk[:11],
1167 },
1168 Tokens: tk[:11],
1169 },
1170 Tokens: tk[:11],
1171 },
1172 },
1173 Tokens: tk[:11],
1174 }
1175 }},
1176 {`function a(this: T){}`, func(t *test, tk Tokens) { // 30
1177 t.Err = Error{
1178 Err: Error{
1179 Err: Error{
1180 Err: Error{
1181 Err: Error{
1182 Err: Error{
1183 Err: ErrNoIdentifier,
1184 Parsing: "BindingElement",
1185 Token: tk[4],
1186 },
1187 Parsing: "FormalParameters",
1188 Token: tk[4],
1189 },
1190 Parsing: "FunctionDeclaration",
1191 Token: tk[3],
1192 },
1193 Parsing: "Declaration",
1194 Token: tk[0],
1195 },
1196 Parsing: "StatementListItem",
1197 Token: tk[0],
1198 },
1199 Parsing: "ModuleItem",
1200 Token: tk[0],
1201 }
1202 }},
1203 {`function a(this, b){}`, func(t *test, tk Tokens) { // 31
1204 t.Typescript = true
1205 t.Output = Module{
1206 ModuleListItems: []ModuleItem{
1207 {
1208 StatementListItem: &StatementListItem{
1209 Declaration: &Declaration{
1210 FunctionDeclaration: &FunctionDeclaration{
1211 BindingIdentifier: &tk[2],
1212 FormalParameters: FormalParameters{
1213 FormalParameterList: []BindingElement{
1214 {
1215 SingleNameBinding: &tk[7],
1216 Tokens: tk[7:8],
1217 },
1218 },
1219 Tokens: tk[3:9],
1220 },
1221 FunctionBody: Block{
1222 Tokens: tk[9:11],
1223 },
1224 Tokens: tk[:11],
1225 },
1226 Tokens: tk[:11],
1227 },
1228 Tokens: tk[:11],
1229 },
1230 Tokens: tk[:11],
1231 },
1232 },
1233 Tokens: tk[:11],
1234 }
1235 }},
1236 {`function a(this, b){}`, func(t *test, tk Tokens) { // 32
1237 t.Err = Error{
1238 Err: Error{
1239 Err: Error{
1240 Err: Error{
1241 Err: Error{
1242 Err: Error{
1243 Err: ErrNoIdentifier,
1244 Parsing: "BindingElement",
1245 Token: tk[4],
1246 },
1247 Parsing: "FormalParameters",
1248 Token: tk[4],
1249 },
1250 Parsing: "FunctionDeclaration",
1251 Token: tk[3],
1252 },
1253 Parsing: "Declaration",
1254 Token: tk[0],
1255 },
1256 Parsing: "StatementListItem",
1257 Token: tk[0],
1258 },
1259 Parsing: "ModuleItem",
1260 Token: tk[0],
1261 }
1262 }},
1263 {`<A>() => {}`, func(t *test, tk Tokens) { // 33
1264 t.Typescript = true
1265 t.Output = Module{
1266 ModuleListItems: []ModuleItem{
1267 {
1268 StatementListItem: &StatementListItem{
1269 Statement: &Statement{
1270 ExpressionStatement: &Expression{
1271 Expressions: []AssignmentExpression{
1272 {
1273 ArrowFunction: &ArrowFunction{
1274 FormalParameters: &FormalParameters{
1275 Tokens: tk[3:5],
1276 },
1277 FunctionBody: &Block{
1278 Tokens: tk[8:10],
1279 },
1280 Tokens: tk[:10],
1281 },
1282 Tokens: tk[:10],
1283 },
1284 },
1285 Tokens: tk[:10],
1286 },
1287 Tokens: tk[:10],
1288 },
1289 Tokens: tk[:10],
1290 },
1291 Tokens: tk[:10],
1292 },
1293 },
1294 Tokens: tk[:10],
1295 }
1296 }},
1297 {`(): A => {}`, func(t *test, tk Tokens) { // 35
1298 t.Typescript = true
1299 t.Output = Module{
1300 ModuleListItems: []ModuleItem{
1301 {
1302 StatementListItem: &StatementListItem{
1303 Statement: &Statement{
1304 ExpressionStatement: &Expression{
1305 Expressions: []AssignmentExpression{
1306 {
1307 ArrowFunction: &ArrowFunction{
1308 FormalParameters: &FormalParameters{
1309 Tokens: tk[0:2],
1310 },
1311 FunctionBody: &Block{
1312 Tokens: tk[8:10],
1313 },
1314 Tokens: tk[:10],
1315 },
1316 Tokens: tk[:10],
1317 },
1318 },
1319 Tokens: tk[:10],
1320 },
1321 Tokens: tk[:10],
1322 },
1323 Tokens: tk[:10],
1324 },
1325 Tokens: tk[:10],
1326 },
1327 },
1328 Tokens: tk[:10],
1329 }
1330 }},
1331 {`(a: T) => {}`, func(t *test, tk Tokens) { // 35
1332 t.Typescript = true
1333 t.Output = Module{
1334 ModuleListItems: []ModuleItem{
1335 {
1336 StatementListItem: &StatementListItem{
1337 Statement: &Statement{
1338 ExpressionStatement: &Expression{
1339 Expressions: []AssignmentExpression{
1340 {
1341 ArrowFunction: &ArrowFunction{
1342 FormalParameters: &FormalParameters{
1343 FormalParameterList: []BindingElement{
1344 {
1345 SingleNameBinding: &tk[1],
1346 Tokens: tk[1:2],
1347 },
1348 },
1349 Tokens: tk[0:6],
1350 },
1351 FunctionBody: &Block{
1352 Tokens: tk[9:11],
1353 },
1354 Tokens: tk[:11],
1355 },
1356 Tokens: tk[:11],
1357 },
1358 },
1359 Tokens: tk[:11],
1360 },
1361 Tokens: tk[:11],
1362 },
1363 Tokens: tk[:11],
1364 },
1365 Tokens: tk[:11],
1366 },
1367 },
1368 Tokens: tk[:11],
1369 }
1370 }},
1371 {`<A>(a: A, b: C): D => {}`, func(t *test, tk Tokens) { // 36
1372 t.Typescript = true
1373 t.Output = Module{
1374 ModuleListItems: []ModuleItem{
1375 {
1376 StatementListItem: &StatementListItem{
1377 Statement: &Statement{
1378 ExpressionStatement: &Expression{
1379 Expressions: []AssignmentExpression{
1380 {
1381 ArrowFunction: &ArrowFunction{
1382 FormalParameters: &FormalParameters{
1383 FormalParameterList: []BindingElement{
1384 {
1385 SingleNameBinding: &tk[4],
1386 Tokens: tk[4:5],
1387 },
1388 {
1389 SingleNameBinding: &tk[10],
1390 Tokens: tk[10:11],
1391 },
1392 },
1393 Tokens: tk[3:15],
1394 },
1395 FunctionBody: &Block{
1396 Tokens: tk[21:23],
1397 },
1398 Tokens: tk[:23],
1399 },
1400 Tokens: tk[:23],
1401 },
1402 },
1403 Tokens: tk[:23],
1404 },
1405 Tokens: tk[:23],
1406 },
1407 Tokens: tk[:23],
1408 },
1409 Tokens: tk[:23],
1410 },
1411 },
1412 Tokens: tk[:23],
1413 }
1414 }},
1415 {`async <A>() => {}`, func(t *test, tk Tokens) { // 37
1416 t.Typescript = true
1417 t.Output = Module{
1418 ModuleListItems: []ModuleItem{
1419 {
1420 StatementListItem: &StatementListItem{
1421 Statement: &Statement{
1422 ExpressionStatement: &Expression{
1423 Expressions: []AssignmentExpression{
1424 {
1425 ArrowFunction: &ArrowFunction{
1426 Async: true,
1427 FormalParameters: &FormalParameters{
1428 Tokens: tk[5:7],
1429 },
1430 FunctionBody: &Block{
1431 Tokens: tk[10:12],
1432 },
1433 Tokens: tk[:12],
1434 },
1435 Tokens: tk[:12],
1436 },
1437 },
1438 Tokens: tk[:12],
1439 },
1440 Tokens: tk[:12],
1441 },
1442 Tokens: tk[:12],
1443 },
1444 Tokens: tk[:12],
1445 },
1446 },
1447 Tokens: tk[:12],
1448 }
1449 }},
1450 {`async (): A => {}`, func(t *test, tk Tokens) { // 38
1451 t.Typescript = true
1452 t.Output = Module{
1453 ModuleListItems: []ModuleItem{
1454 {
1455 StatementListItem: &StatementListItem{
1456 Statement: &Statement{
1457 ExpressionStatement: &Expression{
1458 Expressions: []AssignmentExpression{
1459 {
1460 ArrowFunction: &ArrowFunction{
1461 Async: true,
1462 FormalParameters: &FormalParameters{
1463 Tokens: tk[2:4],
1464 },
1465 FunctionBody: &Block{
1466 Tokens: tk[10:12],
1467 },
1468 Tokens: tk[:12],
1469 },
1470 Tokens: tk[:12],
1471 },
1472 },
1473 Tokens: tk[:12],
1474 },
1475 Tokens: tk[:12],
1476 },
1477 Tokens: tk[:12],
1478 },
1479 Tokens: tk[:12],
1480 },
1481 },
1482 Tokens: tk[:12],
1483 }
1484 }},
1485 {`async (a: T) => {}`, func(t *test, tk Tokens) { // 39
1486 t.Typescript = true
1487 t.Output = Module{
1488 ModuleListItems: []ModuleItem{
1489 {
1490 StatementListItem: &StatementListItem{
1491 Statement: &Statement{
1492 ExpressionStatement: &Expression{
1493 Expressions: []AssignmentExpression{
1494 {
1495 ArrowFunction: &ArrowFunction{
1496 Async: true,
1497 FormalParameters: &FormalParameters{
1498 FormalParameterList: []BindingElement{
1499 {
1500 SingleNameBinding: &tk[3],
1501 Tokens: tk[3:7],
1502 },
1503 },
1504 Tokens: tk[2:8],
1505 },
1506 FunctionBody: &Block{
1507 Tokens: tk[11:13],
1508 },
1509 Tokens: tk[:13],
1510 },
1511 Tokens: tk[:13],
1512 },
1513 },
1514 Tokens: tk[:13],
1515 },
1516 Tokens: tk[:13],
1517 },
1518 Tokens: tk[:13],
1519 },
1520 Tokens: tk[:13],
1521 },
1522 },
1523 Tokens: tk[:13],
1524 }
1525 }},
1526 {`async <A>(a: A, b: C): D => {}`, func(t *test, tk Tokens) { // 40
1527 t.Typescript = true
1528 t.Output = Module{
1529 ModuleListItems: []ModuleItem{
1530 {
1531 StatementListItem: &StatementListItem{
1532 Statement: &Statement{
1533 ExpressionStatement: &Expression{
1534 Expressions: []AssignmentExpression{
1535 {
1536 ArrowFunction: &ArrowFunction{
1537 Async: true,
1538 FormalParameters: &FormalParameters{
1539 FormalParameterList: []BindingElement{
1540 {
1541 SingleNameBinding: &tk[6],
1542 Tokens: tk[6:10],
1543 },
1544 {
1545 SingleNameBinding: &tk[12],
1546 Tokens: tk[12:16],
1547 },
1548 },
1549 Tokens: tk[5:17],
1550 },
1551 FunctionBody: &Block{
1552 Tokens: tk[23:25],
1553 },
1554 Tokens: tk[:25],
1555 },
1556 Tokens: tk[:25],
1557 },
1558 },
1559 Tokens: tk[:25],
1560 },
1561 Tokens: tk[:25],
1562 },
1563 Tokens: tk[:25],
1564 },
1565 Tokens: tk[:25],
1566 },
1567 },
1568 Tokens: tk[:25],
1569 }
1570 }},
1571 {"let a: B = c as D, [e] = f as const", func(t *test, tk Tokens) { // 41
1572 t.Typescript = true
1573 t.Output = Module{
1574 ModuleListItems: []ModuleItem{
1575 {
1576 StatementListItem: &StatementListItem{
1577 Declaration: &Declaration{
1578 LexicalDeclaration: &LexicalDeclaration{
1579 BindingList: []LexicalBinding{
1580 {
1581 BindingIdentifier: &tk[2],
1582 Initializer: &AssignmentExpression{
1583 ConditionalExpression: WrapConditional(&LeftHandSideExpression{
1584 NewExpression: &NewExpression{
1585 MemberExpression: MemberExpression{
1586 PrimaryExpression: &PrimaryExpression{
1587 IdentifierReference: &tk[9],
1588 Tokens: tk[9:10],
1589 },
1590 Tokens: tk[9:10],
1591 },
1592 Tokens: tk[9:10],
1593 },
1594 Tokens: tk[9:14],
1595 }),
1596 Tokens: tk[9:14],
1597 },
1598 Tokens: tk[2:14],
1599 },
1600 {
1601 ArrayBindingPattern: &ArrayBindingPattern{
1602 BindingElementList: []BindingElement{
1603 {
1604 SingleNameBinding: &tk[17],
1605 Tokens: tk[17:18],
1606 },
1607 },
1608 Tokens: tk[16:19],
1609 },
1610 Initializer: &AssignmentExpression{
1611 ConditionalExpression: WrapConditional(&LeftHandSideExpression{
1612 NewExpression: &NewExpression{
1613 MemberExpression: MemberExpression{
1614 PrimaryExpression: &PrimaryExpression{
1615 IdentifierReference: &tk[22],
1616 Tokens: tk[22:23],
1617 },
1618 Tokens: tk[22:23],
1619 },
1620 Tokens: tk[22:23],
1621 },
1622 Tokens: tk[22:27],
1623 }),
1624 Tokens: tk[22:27],
1625 },
1626 Tokens: tk[16:27],
1627 },
1628 },
1629 Tokens: tk[:27],
1630 },
1631 Tokens: tk[:27],
1632 },
1633 Tokens: tk[:27],
1634 },
1635 Tokens: tk[:27],
1636 },
1637 },
1638 Tokens: tk[:27],
1639 }
1640 }},
1641 {"let a: B = c as D, [e] = f as const", func(t *test, tk Tokens) { // 42
1642 t.Err = Error{
1643 Err: Error{
1644 Err: Error{
1645 Err: Error{
1646 Err: ErrInvalidLexicalDeclaration,
1647 Parsing: "LexicalDeclaration",
1648 Token: tk[3],
1649 },
1650 Parsing: "Declaration",
1651 Token: tk[0],
1652 },
1653 Parsing: "StatementListItem",
1654 Token: tk[0],
1655 },
1656 Parsing: "ModuleItem",
1657 Token: tk[0],
1658 }
1659 }},
1660 {`type A = {
1661 data: any;
1662 other: number;
1663 }`, func(t *test, tk Tokens) { // 43
1664 t.Typescript = true
1665 t.Output = Module{
1666 ModuleListItems: []ModuleItem{
1667 {
1668 StatementListItem: &StatementListItem{
1669 Statement: &Statement{
1670 Tokens: tk[:23],
1671 },
1672 Tokens: tk[:23],
1673 },
1674 Tokens: tk[:23],
1675 },
1676 },
1677 Tokens: tk[:23],
1678 }
1679 }},
1680 {`const a = B<C, D>()`, func(t *test, tk Tokens) { // 44
1681 t.Typescript = true
1682 t.Output = Module{
1683 ModuleListItems: []ModuleItem{
1684 {
1685 StatementListItem: &StatementListItem{
1686 Declaration: &Declaration{
1687 LexicalDeclaration: &LexicalDeclaration{
1688 LetOrConst: Const,
1689 BindingList: []LexicalBinding{
1690 {
1691 BindingIdentifier: &tk[2],
1692 Initializer: &AssignmentExpression{
1693 ConditionalExpression: WrapConditional(&CallExpression{
1694 MemberExpression: &MemberExpression{
1695 PrimaryExpression: &PrimaryExpression{
1696 IdentifierReference: &tk[6],
1697 Tokens: tk[6:7],
1698 },
1699 Tokens: tk[6:7],
1700 },
1701 Arguments: &Arguments{
1702 Tokens: tk[13:15],
1703 },
1704 Tokens: tk[6:15],
1705 }),
1706 Tokens: tk[6:15],
1707 },
1708 Tokens: tk[2:15],
1709 },
1710 },
1711 Tokens: tk[:15],
1712 },
1713 Tokens: tk[:15],
1714 },
1715 Tokens: tk[:15],
1716 },
1717 Tokens: tk[:15],
1718 },
1719 },
1720 Tokens: tk[:15],
1721 }
1722 }},
1723 {`const a = new B<C, D>()`, func(t *test, tk Tokens) { // 45
1724 t.Typescript = true
1725 t.Output = Module{
1726 ModuleListItems: []ModuleItem{
1727 {
1728 StatementListItem: &StatementListItem{
1729 Declaration: &Declaration{
1730 LexicalDeclaration: &LexicalDeclaration{
1731 LetOrConst: Const,
1732 BindingList: []LexicalBinding{
1733 {
1734 BindingIdentifier: &tk[2],
1735 Initializer: &AssignmentExpression{
1736 ConditionalExpression: WrapConditional(&NewExpression{
1737 MemberExpression: MemberExpression{
1738 MemberExpression: &MemberExpression{
1739 PrimaryExpression: &PrimaryExpression{
1740 IdentifierReference: &tk[8],
1741 Tokens: tk[8:9],
1742 },
1743 Tokens: tk[8:9],
1744 },
1745 Arguments: &Arguments{
1746 Tokens: tk[15:17],
1747 },
1748 Tokens: tk[6:17],
1749 },
1750 Tokens: tk[6:17],
1751 }),
1752 Tokens: tk[6:17],
1753 },
1754 Tokens: tk[2:17],
1755 },
1756 },
1757 Tokens: tk[:17],
1758 },
1759 Tokens: tk[:17],
1760 },
1761 Tokens: tk[:17],
1762 },
1763 Tokens: tk[:17],
1764 },
1765 },
1766 Tokens: tk[:17],
1767 }
1768 }},
1769 {`const a = new B<C<D, E>>()`, func(t *test, tk Tokens) { // 46
1770 t.Typescript = true
1771 t.Output = Module{
1772 ModuleListItems: []ModuleItem{
1773 {
1774 StatementListItem: &StatementListItem{
1775 Declaration: &Declaration{
1776 LexicalDeclaration: &LexicalDeclaration{
1777 LetOrConst: Const,
1778 BindingList: []LexicalBinding{
1779 {
1780 BindingIdentifier: &tk[2],
1781 Initializer: &AssignmentExpression{
1782 ConditionalExpression: WrapConditional(&NewExpression{
1783 MemberExpression: MemberExpression{
1784 MemberExpression: &MemberExpression{
1785 PrimaryExpression: &PrimaryExpression{
1786 IdentifierReference: &tk[8],
1787 Tokens: tk[8:9],
1788 },
1789 Tokens: tk[8:9],
1790 },
1791 Arguments: &Arguments{
1792 Tokens: tk[18:20],
1793 },
1794 Tokens: tk[6:20],
1795 },
1796 Tokens: tk[6:20],
1797 }),
1798 Tokens: tk[6:20],
1799 },
1800 Tokens: tk[2:20],
1801 },
1802 },
1803 Tokens: tk[:20],
1804 },
1805 Tokens: tk[:20],
1806 },
1807 Tokens: tk[:20],
1808 },
1809 Tokens: tk[:20],
1810 },
1811 },
1812 Tokens: tk[:20],
1813 }
1814 }},
1815 {`const a = (b): b is C => {}`, func(t *test, tk Tokens) { // 47
1816 t.Typescript = true
1817 t.Output = Module{
1818 ModuleListItems: []ModuleItem{
1819 {
1820 StatementListItem: &StatementListItem{
1821 Declaration: &Declaration{
1822 LexicalDeclaration: &LexicalDeclaration{
1823 LetOrConst: Const,
1824 BindingList: []LexicalBinding{
1825 {
1826 BindingIdentifier: &tk[2],
1827 Initializer: &AssignmentExpression{
1828 ArrowFunction: &ArrowFunction{
1829 FormalParameters: &FormalParameters{
1830 FormalParameterList: []BindingElement{
1831 {
1832 SingleNameBinding: &tk[7],
1833 Tokens: tk[7:8],
1834 },
1835 },
1836 Tokens: tk[6:9],
1837 },
1838 FunctionBody: &Block{
1839 Tokens: tk[19:21],
1840 },
1841 Tokens: tk[6:21],
1842 },
1843 Tokens: tk[6:21],
1844 },
1845 Tokens: tk[2:21],
1846 },
1847 },
1848 Tokens: tk[:21],
1849 },
1850 Tokens: tk[:21],
1851 },
1852 Tokens: tk[:21],
1853 },
1854 Tokens: tk[:21],
1855 },
1856 },
1857 Tokens: tk[:21],
1858 }
1859 }},
1860 {`a!`, func(t *test, tk Tokens) { // 48
1861 t.Typescript = true
1862 t.Output = Module{
1863 ModuleListItems: []ModuleItem{
1864 {
1865 StatementListItem: &StatementListItem{
1866 Statement: &Statement{
1867 ExpressionStatement: &Expression{
1868 Expressions: []AssignmentExpression{
1869 {
1870 ConditionalExpression: WrapConditional(&MemberExpression{
1871 PrimaryExpression: &PrimaryExpression{
1872 IdentifierReference: &tk[0],
1873 Tokens: tk[:1],
1874 },
1875 Tokens: tk[:2],
1876 }),
1877 Tokens: tk[:2],
1878 },
1879 },
1880 Tokens: tk[:2],
1881 },
1882 Tokens: tk[:2],
1883 },
1884 Tokens: tk[:2],
1885 },
1886 Tokens: tk[:2],
1887 },
1888 },
1889 Tokens: tk[:2],
1890 }
1891 }},
1892 {`a!.b`, func(t *test, tk Tokens) { // 49
1893 t.Typescript = true
1894 t.Output = Module{
1895 ModuleListItems: []ModuleItem{
1896 {
1897 StatementListItem: &StatementListItem{
1898 Statement: &Statement{
1899 ExpressionStatement: &Expression{
1900 Expressions: []AssignmentExpression{
1901 {
1902 ConditionalExpression: WrapConditional(&MemberExpression{
1903 MemberExpression: &MemberExpression{
1904 PrimaryExpression: &PrimaryExpression{
1905 IdentifierReference: &tk[0],
1906 Tokens: tk[0:1],
1907 },
1908 Tokens: tk[0:2],
1909 },
1910 IdentifierName: &tk[3],
1911 Tokens: tk[:4],
1912 }),
1913 Tokens: tk[:4],
1914 },
1915 },
1916 Tokens: tk[:4],
1917 },
1918 Tokens: tk[:4],
1919 },
1920 Tokens: tk[:4],
1921 },
1922 Tokens: tk[:4],
1923 },
1924 },
1925 Tokens: tk[:4],
1926 }
1927 }},
1928 {`a!.b!`, func(t *test, tk Tokens) { // 50
1929 t.Typescript = true
1930 t.Output = Module{
1931 ModuleListItems: []ModuleItem{
1932 {
1933 StatementListItem: &StatementListItem{
1934 Statement: &Statement{
1935 ExpressionStatement: &Expression{
1936 Expressions: []AssignmentExpression{
1937 {
1938 ConditionalExpression: WrapConditional(&MemberExpression{
1939 MemberExpression: &MemberExpression{
1940 PrimaryExpression: &PrimaryExpression{
1941 IdentifierReference: &tk[0],
1942 Tokens: tk[0:1],
1943 },
1944 Tokens: tk[0:2],
1945 },
1946 IdentifierName: &tk[3],
1947 Tokens: tk[:5],
1948 }),
1949 Tokens: tk[:5],
1950 },
1951 },
1952 Tokens: tk[:5],
1953 },
1954 Tokens: tk[:5],
1955 },
1956 Tokens: tk[:5],
1957 },
1958 Tokens: tk[:5],
1959 },
1960 },
1961 Tokens: tk[:5],
1962 }
1963 }},
1964 {`a[0]!`, func(t *test, tk Tokens) { // 51
1965 t.Typescript = true
1966 t.Output = Module{
1967 ModuleListItems: []ModuleItem{
1968 {
1969 StatementListItem: &StatementListItem{
1970 Statement: &Statement{
1971 ExpressionStatement: &Expression{
1972 Expressions: []AssignmentExpression{
1973 {
1974 ConditionalExpression: WrapConditional(&MemberExpression{
1975 MemberExpression: &MemberExpression{
1976 PrimaryExpression: &PrimaryExpression{
1977 IdentifierReference: &tk[0],
1978 Tokens: tk[:1],
1979 },
1980 Tokens: tk[:1],
1981 },
1982 Expression: &Expression{
1983 Expressions: []AssignmentExpression{
1984 {
1985 ConditionalExpression: WrapConditional(&PrimaryExpression{
1986 Literal: &tk[2],
1987 Tokens: tk[2:3],
1988 }),
1989 Tokens: tk[2:3],
1990 },
1991 },
1992 Tokens: tk[2:3],
1993 },
1994 Tokens: tk[:5],
1995 }),
1996 Tokens: tk[:5],
1997 },
1998 },
1999 Tokens: tk[:5],
2000 },
2001 Tokens: tk[:5],
2002 },
2003 Tokens: tk[:5],
2004 },
2005 Tokens: tk[:5],
2006 },
2007 },
2008 Tokens: tk[:5],
2009 }
2010 }},
2011 {`a[0]!.b`, func(t *test, tk Tokens) { // 52
2012 t.Typescript = true
2013 t.Output = Module{
2014 ModuleListItems: []ModuleItem{
2015 {
2016 StatementListItem: &StatementListItem{
2017 Statement: &Statement{
2018 ExpressionStatement: &Expression{
2019 Expressions: []AssignmentExpression{
2020 {
2021 ConditionalExpression: WrapConditional(&MemberExpression{
2022 MemberExpression: &MemberExpression{
2023 MemberExpression: &MemberExpression{
2024 PrimaryExpression: &PrimaryExpression{
2025 IdentifierReference: &tk[0],
2026 Tokens: tk[:1],
2027 },
2028 Tokens: tk[:1],
2029 },
2030 Expression: &Expression{
2031 Expressions: []AssignmentExpression{
2032 {
2033 ConditionalExpression: WrapConditional(&PrimaryExpression{
2034 Literal: &tk[2],
2035 Tokens: tk[2:3],
2036 }),
2037 Tokens: tk[2:3],
2038 },
2039 },
2040 Tokens: tk[2:3],
2041 },
2042 Tokens: tk[:5],
2043 },
2044 IdentifierName: &tk[6],
2045 Tokens: tk[:7],
2046 }),
2047 Tokens: tk[:7],
2048 },
2049 },
2050 Tokens: tk[:7],
2051 },
2052 Tokens: tk[:7],
2053 },
2054 Tokens: tk[:7],
2055 },
2056 Tokens: tk[:7],
2057 },
2058 },
2059 Tokens: tk[:7],
2060 }
2061 }},
2062 {`a!()`, func(t *test, tk Tokens) { // 53
2063 t.Typescript = true
2064 t.Output = Module{
2065 ModuleListItems: []ModuleItem{
2066 {
2067 StatementListItem: &StatementListItem{
2068 Statement: &Statement{
2069 ExpressionStatement: &Expression{
2070 Expressions: []AssignmentExpression{
2071 {
2072 ConditionalExpression: WrapConditional(&CallExpression{
2073 MemberExpression: &MemberExpression{
2074 PrimaryExpression: &PrimaryExpression{
2075 IdentifierReference: &tk[0],
2076 Tokens: tk[:1],
2077 },
2078 Tokens: tk[:2],
2079 },
2080 Arguments: &Arguments{
2081 Tokens: tk[2:4],
2082 },
2083 Tokens: tk[:4],
2084 }),
2085 Tokens: tk[:4],
2086 },
2087 },
2088 Tokens: tk[:4],
2089 },
2090 Tokens: tk[:4],
2091 },
2092 Tokens: tk[:4],
2093 },
2094 Tokens: tk[:4],
2095 },
2096 },
2097 Tokens: tk[:4],
2098 }
2099 }},
2100 {`a!().b`, func(t *test, tk Tokens) { // 54
2101 t.Typescript = true
2102 t.Output = Module{
2103 ModuleListItems: []ModuleItem{
2104 {
2105 StatementListItem: &StatementListItem{
2106 Statement: &Statement{
2107 ExpressionStatement: &Expression{
2108 Expressions: []AssignmentExpression{
2109 {
2110 ConditionalExpression: WrapConditional(&CallExpression{
2111 CallExpression: &CallExpression{
2112 MemberExpression: &MemberExpression{
2113 PrimaryExpression: &PrimaryExpression{
2114 IdentifierReference: &tk[0],
2115 Tokens: tk[:1],
2116 },
2117 Tokens: tk[:2],
2118 },
2119 Arguments: &Arguments{
2120 Tokens: tk[2:4],
2121 },
2122 Tokens: tk[:4],
2123 },
2124 IdentifierName: &tk[5],
2125 Tokens: tk[:6],
2126 }),
2127 Tokens: tk[:6],
2128 },
2129 },
2130 Tokens: tk[:6],
2131 },
2132 Tokens: tk[:6],
2133 },
2134 Tokens: tk[:6],
2135 },
2136 Tokens: tk[:6],
2137 },
2138 },
2139 Tokens: tk[:6],
2140 }
2141 }},
2142 {`a!.b()`, func(t *test, tk Tokens) { // 55
2143 t.Typescript = true
2144 t.Output = Module{
2145 ModuleListItems: []ModuleItem{
2146 {
2147 StatementListItem: &StatementListItem{
2148 Statement: &Statement{
2149 ExpressionStatement: &Expression{
2150 Expressions: []AssignmentExpression{
2151 {
2152 ConditionalExpression: WrapConditional(&CallExpression{
2153 MemberExpression: &MemberExpression{
2154 MemberExpression: &MemberExpression{
2155 PrimaryExpression: &PrimaryExpression{
2156 IdentifierReference: &tk[0],
2157 Tokens: tk[:1],
2158 },
2159 Tokens: tk[:2],
2160 },
2161 IdentifierName: &tk[3],
2162 Tokens: tk[:4],
2163 },
2164 Arguments: &Arguments{
2165 Tokens: tk[4:6],
2166 },
2167 Tokens: tk[:6],
2168 }),
2169 Tokens: tk[:6],
2170 },
2171 },
2172 Tokens: tk[:6],
2173 },
2174 Tokens: tk[:6],
2175 },
2176 Tokens: tk[:6],
2177 },
2178 Tokens: tk[:6],
2179 },
2180 },
2181 Tokens: tk[:6],
2182 }
2183 }},
2184 {`a[0]!()`, func(t *test, tk Tokens) { // 56
2185 t.Typescript = true
2186 t.Output = Module{
2187 ModuleListItems: []ModuleItem{
2188 {
2189 StatementListItem: &StatementListItem{
2190 Statement: &Statement{
2191 ExpressionStatement: &Expression{
2192 Expressions: []AssignmentExpression{
2193 {
2194 ConditionalExpression: WrapConditional(&CallExpression{
2195 MemberExpression: &MemberExpression{
2196 MemberExpression: &MemberExpression{
2197 PrimaryExpression: &PrimaryExpression{
2198 IdentifierReference: &tk[0],
2199 Tokens: tk[:1],
2200 },
2201 Tokens: tk[:1],
2202 },
2203 Expression: &Expression{
2204 Expressions: []AssignmentExpression{
2205 {
2206 ConditionalExpression: WrapConditional(&PrimaryExpression{
2207 Literal: &tk[2],
2208 Tokens: tk[2:3],
2209 }),
2210 Tokens: tk[2:3],
2211 },
2212 },
2213 Tokens: tk[2:3],
2214 },
2215 Tokens: tk[:5],
2216 },
2217 Arguments: &Arguments{
2218 Tokens: tk[5:7],
2219 },
2220 Tokens: tk[:7],
2221 }),
2222 Tokens: tk[:7],
2223 },
2224 },
2225 Tokens: tk[:7],
2226 },
2227 Tokens: tk[:7],
2228 },
2229 Tokens: tk[:7],
2230 },
2231 Tokens: tk[:7],
2232 },
2233 },
2234 Tokens: tk[:7],
2235 }
2236 }},
2237 {`a[0]!().b`, func(t *test, tk Tokens) { // 57
2238 t.Typescript = true
2239 t.Output = Module{
2240 ModuleListItems: []ModuleItem{
2241 {
2242 StatementListItem: &StatementListItem{
2243 Statement: &Statement{
2244 ExpressionStatement: &Expression{
2245 Expressions: []AssignmentExpression{
2246 {
2247 ConditionalExpression: WrapConditional(&CallExpression{
2248 CallExpression: &CallExpression{
2249 MemberExpression: &MemberExpression{
2250 MemberExpression: &MemberExpression{
2251 PrimaryExpression: &PrimaryExpression{
2252 IdentifierReference: &tk[0],
2253 Tokens: tk[:1],
2254 },
2255 Tokens: tk[:1],
2256 },
2257 Expression: &Expression{
2258 Expressions: []AssignmentExpression{
2259 {
2260 ConditionalExpression: WrapConditional(&PrimaryExpression{
2261 Literal: &tk[2],
2262 Tokens: tk[2:3],
2263 }),
2264 Tokens: tk[2:3],
2265 },
2266 },
2267 Tokens: tk[2:3],
2268 },
2269 Tokens: tk[:5],
2270 },
2271 Arguments: &Arguments{
2272 Tokens: tk[5:7],
2273 },
2274 Tokens: tk[:7],
2275 },
2276 IdentifierName: &tk[8],
2277 Tokens: tk[:9],
2278 }),
2279 Tokens: tk[:9],
2280 },
2281 },
2282 Tokens: tk[:9],
2283 },
2284 Tokens: tk[:9],
2285 },
2286 Tokens: tk[:9],
2287 },
2288 Tokens: tk[:9],
2289 },
2290 },
2291 Tokens: tk[:9],
2292 }
2293 }},
2294 {`type A = {[B]: any}`, func(t *test, tk Tokens) { // 58
2295 t.Typescript = true
2296 t.Output = Module{
2297 ModuleListItems: []ModuleItem{
2298 {
2299 StatementListItem: &StatementListItem{
2300 Statement: &Statement{
2301 Tokens: tk[:14],
2302 },
2303 Tokens: tk[:14],
2304 },
2305 Tokens: tk[:14],
2306 },
2307 },
2308 Tokens: tk[:14],
2309 }
2310 }},
2311 {`class A {#B: string}`, func(t *test, tk Tokens) { // 59
2312 t.Typescript = true
2313 t.Output = Module{
2314 ModuleListItems: []ModuleItem{
2315 {
2316 StatementListItem: &StatementListItem{
2317 Declaration: &Declaration{
2318 ClassDeclaration: &ClassDeclaration{
2319 BindingIdentifier: &tk[2],
2320 ClassBody: []ClassElement{
2321 {
2322 FieldDefinition: &FieldDefinition{
2323 ClassElementName: ClassElementName{
2324 PrivateIdentifier: &tk[5],
2325 Tokens: tk[5:6],
2326 },
2327 Tokens: tk[5:9],
2328 },
2329 Tokens: tk[5:9],
2330 },
2331 },
2332 Tokens: tk[:10],
2333 },
2334 Tokens: tk[:10],
2335 },
2336 Tokens: tk[:10],
2337 },
2338 Tokens: tk[:10],
2339 },
2340 },
2341 Tokens: tk[:10],
2342 }
2343 }},
2344 {`abstract class A {}`, func(t *test, tk Tokens) { // 60
2345 t.Typescript = true
2346 t.Output = Module{
2347 ModuleListItems: []ModuleItem{
2348 {
2349 StatementListItem: &StatementListItem{
2350 Declaration: &Declaration{
2351 ClassDeclaration: &ClassDeclaration{
2352 BindingIdentifier: &tk[4],
2353 Tokens: tk[:8],
2354 },
2355 Tokens: tk[:8],
2356 },
2357 Tokens: tk[:8],
2358 },
2359 Tokens: tk[:8],
2360 },
2361 },
2362 Tokens: tk[:8],
2363 }
2364 }},
2365 {`export default abstract class A {}`, func(t *test, tk Tokens) { // 61
2366 t.Typescript = true
2367 t.Output = Module{
2368 ModuleListItems: []ModuleItem{
2369 {
2370 ExportDeclaration: &ExportDeclaration{
2371 DefaultClass: &ClassDeclaration{
2372 BindingIdentifier: &tk[8],
2373 Tokens: tk[4:12],
2374 },
2375 Tokens: tk[:12],
2376 },
2377 Tokens: tk[:12],
2378 },
2379 },
2380 Tokens: tk[:12],
2381 }
2382 }},
2383 {`const a = abstract class {}`, func(t *test, tk Tokens) { // 62
2384 t.Typescript = true
2385 t.Output = Module{
2386 ModuleListItems: []ModuleItem{
2387 {
2388 StatementListItem: &StatementListItem{
2389 Declaration: &Declaration{
2390 LexicalDeclaration: &LexicalDeclaration{
2391 LetOrConst: Const,
2392 BindingList: []LexicalBinding{
2393 {
2394 BindingIdentifier: &tk[2],
2395 Initializer: &AssignmentExpression{
2396 ConditionalExpression: WrapConditional(&PrimaryExpression{
2397 ClassExpression: &ClassDeclaration{
2398 Tokens: tk[6:12],
2399 },
2400 Tokens: tk[6:12],
2401 }),
2402 Tokens: tk[6:12],
2403 },
2404 Tokens: tk[2:12],
2405 },
2406 },
2407 Tokens: tk[:12],
2408 },
2409 Tokens: tk[:12],
2410 },
2411 Tokens: tk[:12],
2412 },
2413 Tokens: tk[:12],
2414 },
2415 },
2416 Tokens: tk[:12],
2417 }
2418 }},
2419 {`abstract class A {
2420 abstract a(): string;
2421 abstract b;
2422 abstract c: number;
2423 public abstract d;
2424 }`, func(t *test, tk Tokens) { // 63
2425 t.Typescript = true
2426 t.Output = Module{
2427 ModuleListItems: []ModuleItem{
2428 {
2429 StatementListItem: &StatementListItem{
2430 Declaration: &Declaration{
2431 ClassDeclaration: &ClassDeclaration{
2432 BindingIdentifier: &tk[4],
2433 Tokens: tk[:39],
2434 },
2435 Tokens: tk[:39],
2436 },
2437 Tokens: tk[:39],
2438 },
2439 Tokens: tk[:39],
2440 },
2441 },
2442 Tokens: tk[:39],
2443 }
2444 }},
2445 {`export type A = B`, func(t *test, tk Tokens) { // 64
2446 t.Typescript = true
2447 t.Output = Module{
2448 ModuleListItems: []ModuleItem{
2449 {
2450 StatementListItem: &StatementListItem{
2451 Statement: &Statement{
2452 Tokens: tk[:9],
2453 },
2454 Tokens: tk[:9],
2455 },
2456 Tokens: tk[:9],
2457 },
2458 },
2459 Tokens: tk[:9],
2460 }
2461 }},
2462 {`class A {b!: string}`, func(t *test, tk Tokens) { // 65
2463 t.Typescript = true
2464 t.Output = Module{
2465 ModuleListItems: []ModuleItem{
2466 {
2467 StatementListItem: &StatementListItem{
2468 Declaration: &Declaration{
2469 ClassDeclaration: &ClassDeclaration{
2470 BindingIdentifier: &tk[2],
2471 ClassBody: []ClassElement{
2472 {
2473 FieldDefinition: &FieldDefinition{
2474 ClassElementName: ClassElementName{
2475 PropertyName: &PropertyName{
2476 LiteralPropertyName: &tk[5],
2477 Tokens: tk[5:6],
2478 },
2479 Tokens: tk[5:6],
2480 },
2481 Tokens: tk[5:10],
2482 },
2483 Tokens: tk[5:10],
2484 },
2485 },
2486 Tokens: tk[:11],
2487 },
2488 Tokens: tk[:11],
2489 },
2490 Tokens: tk[:11],
2491 },
2492 Tokens: tk[:11],
2493 },
2494 },
2495 Tokens: tk[:11],
2496 }
2497 }},
2498 {`export let a: number;`, func(t *test, tk Tokens) { // 66
2499 t.Typescript = true
2500 t.Output = Module{
2501 ModuleListItems: []ModuleItem{
2502 {
2503 ExportDeclaration: &ExportDeclaration{
2504 Declaration: &Declaration{
2505 LexicalDeclaration: &LexicalDeclaration{
2506 BindingList: []LexicalBinding{
2507 {
2508 BindingIdentifier: &tk[4],
2509 Tokens: tk[4:8],
2510 },
2511 },
2512 Tokens: tk[2:9],
2513 },
2514 Tokens: tk[2:9],
2515 },
2516 Tokens: tk[:9],
2517 },
2518 Tokens: tk[:9],
2519 },
2520 },
2521 Tokens: tk[:9],
2522 }
2523 }},
2524 {`const a: (b: any) => b is C`, func(t *test, tk Tokens) { // 67
2525 t.Typescript = true
2526 t.Output = Module{
2527 ModuleListItems: []ModuleItem{
2528 {
2529 StatementListItem: &StatementListItem{
2530 Declaration: &Declaration{
2531 LexicalDeclaration: &LexicalDeclaration{
2532 LetOrConst: Const,
2533 BindingList: []LexicalBinding{
2534 {
2535 BindingIdentifier: &tk[2],
2536 Tokens: tk[2:19],
2537 },
2538 },
2539 Tokens: tk[:19],
2540 },
2541 Tokens: tk[:19],
2542 },
2543 Tokens: tk[:19],
2544 },
2545 Tokens: tk[:19],
2546 },
2547 },
2548 Tokens: tk[:19],
2549 }
2550 }},
2551 {`const a = (b?) => true`, func(t *test, tk Tokens) { // 68
2552 t.Typescript = true
2553 t.Output = Module{
2554 ModuleListItems: []ModuleItem{
2555 {
2556 StatementListItem: &StatementListItem{
2557 Declaration: &Declaration{
2558 LexicalDeclaration: &LexicalDeclaration{
2559 LetOrConst: Const,
2560 BindingList: []LexicalBinding{
2561 {
2562 BindingIdentifier: &tk[2],
2563 Initializer: &AssignmentExpression{
2564 ArrowFunction: &ArrowFunction{
2565 FormalParameters: &FormalParameters{
2566 FormalParameterList: []BindingElement{
2567 {
2568 SingleNameBinding: &tk[7],
2569 Tokens: tk[7:8],
2570 },
2571 },
2572 Tokens: tk[6:10],
2573 },
2574 AssignmentExpression: &AssignmentExpression{
2575 ConditionalExpression: WrapConditional(&PrimaryExpression{
2576 Literal: &tk[13],
2577 Tokens: tk[13:14],
2578 }),
2579 Tokens: tk[13:14],
2580 },
2581 Tokens: tk[6:14],
2582 },
2583 Tokens: tk[6:14],
2584 },
2585 Tokens: tk[2:14],
2586 },
2587 },
2588 Tokens: tk[:14],
2589 },
2590 Tokens: tk[:14],
2591 },
2592 Tokens: tk[:14],
2593 },
2594 Tokens: tk[:14],
2595 },
2596 },
2597 Tokens: tk[:14],
2598 }
2599 }},
2600 {`const a = (b: any): b is [string, ...number[]] => false`, func(t *test, tk Tokens) { // 69
2601 t.Typescript = true
2602 t.Output = Module{
2603 ModuleListItems: []ModuleItem{
2604 {
2605 StatementListItem: &StatementListItem{
2606 Declaration: &Declaration{
2607 LexicalDeclaration: &LexicalDeclaration{
2608 LetOrConst: Const,
2609 BindingList: []LexicalBinding{
2610 {
2611 BindingIdentifier: &tk[2],
2612 Initializer: &AssignmentExpression{
2613 ArrowFunction: &ArrowFunction{
2614 FormalParameters: &FormalParameters{
2615 FormalParameterList: []BindingElement{
2616 {
2617 SingleNameBinding: &tk[7],
2618 Tokens: tk[7:8],
2619 },
2620 },
2621 Tokens: tk[6:12],
2622 },
2623 AssignmentExpression: &AssignmentExpression{
2624 ConditionalExpression: WrapConditional(&PrimaryExpression{
2625 Literal: &tk[30],
2626 Tokens: tk[30:31],
2627 }),
2628 Tokens: tk[30:31],
2629 },
2630 Tokens: tk[6:31],
2631 },
2632 Tokens: tk[6:31],
2633 },
2634 Tokens: tk[2:31],
2635 },
2636 },
2637 Tokens: tk[:31],
2638 },
2639 Tokens: tk[:31],
2640 },
2641 Tokens: tk[:31],
2642 },
2643 Tokens: tk[:31],
2644 },
2645 },
2646 Tokens: tk[:31],
2647 }
2648 }},
2649 {`const a = (b: any = 1) => false`, func(t *test, tk Tokens) { // 70
2650 t.Typescript = true
2651 t.Output = Module{
2652 ModuleListItems: []ModuleItem{
2653 {
2654 StatementListItem: &StatementListItem{
2655 Declaration: &Declaration{
2656 LexicalDeclaration: &LexicalDeclaration{
2657 LetOrConst: Const,
2658 BindingList: []LexicalBinding{
2659 {
2660 BindingIdentifier: &tk[2],
2661 Initializer: &AssignmentExpression{
2662 ArrowFunction: &ArrowFunction{
2663 FormalParameters: &FormalParameters{
2664 FormalParameterList: []BindingElement{
2665 {
2666 SingleNameBinding: &tk[7],
2667 Initializer: &AssignmentExpression{
2668 ConditionalExpression: WrapConditional(&PrimaryExpression{
2669 Literal: &tk[14],
2670 Tokens: tk[14:15],
2671 }),
2672 Tokens: tk[14:15],
2673 },
2674 Tokens: tk[7:15],
2675 },
2676 },
2677 Tokens: tk[6:16],
2678 },
2679 AssignmentExpression: &AssignmentExpression{
2680 ConditionalExpression: WrapConditional(&PrimaryExpression{
2681 Literal: &tk[19],
2682 Tokens: tk[19:20],
2683 }),
2684 Tokens: tk[19:20],
2685 },
2686 Tokens: tk[6:20],
2687 },
2688 Tokens: tk[6:20],
2689 },
2690 Tokens: tk[2:20],
2691 },
2692 },
2693 Tokens: tk[:20],
2694 },
2695 Tokens: tk[:20],
2696 },
2697 Tokens: tk[:20],
2698 },
2699 Tokens: tk[:20],
2700 },
2701 },
2702 Tokens: tk[:20],
2703 }
2704 }},
2705 {`switch (a) {
2706 case "b":
2707 c = 1;
2708 }`, func(t *test, tk Tokens) { // 71
2709 t.Typescript = true
2710 t.Output = Module{
2711 ModuleListItems: []ModuleItem{
2712 {
2713 StatementListItem: &StatementListItem{
2714 Statement: &Statement{
2715 SwitchStatement: &SwitchStatement{
2716 Expression: Expression{
2717 Expressions: []AssignmentExpression{
2718 {
2719 ConditionalExpression: WrapConditional(&PrimaryExpression{
2720 IdentifierReference: &tk[3],
2721 Tokens: tk[3:4],
2722 }),
2723 Tokens: tk[3:4],
2724 },
2725 },
2726 Tokens: tk[3:4],
2727 },
2728 CaseClauses: []CaseClause{
2729 {
2730 Expression: Expression{
2731 Expressions: []AssignmentExpression{
2732 {
2733 ConditionalExpression: WrapConditional(&PrimaryExpression{
2734 Literal: &tk[10],
2735 Tokens: tk[10:11],
2736 }),
2737 Tokens: tk[10:11],
2738 },
2739 },
2740 Tokens: tk[10:11],
2741 },
2742 StatementList: []StatementListItem{
2743 {
2744 Statement: &Statement{
2745 ExpressionStatement: &Expression{
2746 Expressions: []AssignmentExpression{
2747 {
2748 LeftHandSideExpression: &LeftHandSideExpression{
2749 NewExpression: &NewExpression{
2750 MemberExpression: MemberExpression{
2751 PrimaryExpression: &PrimaryExpression{
2752 IdentifierReference: &tk[14],
2753 Tokens: tk[14:15],
2754 },
2755 Tokens: tk[14:15],
2756 },
2757 Tokens: tk[14:15],
2758 },
2759 Tokens: tk[14:15],
2760 },
2761 AssignmentOperator: AssignmentAssign,
2762 AssignmentExpression: &AssignmentExpression{
2763 ConditionalExpression: WrapConditional(&PrimaryExpression{
2764 Literal: &tk[18],
2765 Tokens: tk[18:19],
2766 }),
2767 Tokens: tk[18:19],
2768 },
2769 Tokens: tk[14:19],
2770 },
2771 },
2772 Tokens: tk[14:19],
2773 },
2774 Tokens: tk[14:20],
2775 },
2776 Tokens: tk[14:20],
2777 },
2778 },
2779 Tokens: tk[8:20],
2780 },
2781 },
2782 Tokens: tk[:22],
2783 },
2784 Tokens: tk[:22],
2785 },
2786 Tokens: tk[:22],
2787 },
2788 Tokens: tk[:22],
2789 },
2790 },
2791 Tokens: tk[:22],
2792 }
2793 }},
2794 {`type A = {[b]?: C[];}`, func(t *test, tk Tokens) { // 72
2795 t.Typescript = true
2796 t.Output = Module{
2797 ModuleListItems: []ModuleItem{
2798 {
2799 StatementListItem: &StatementListItem{
2800 Statement: &Statement{
2801 Tokens: tk[:18],
2802 },
2803 Tokens: tk[:18],
2804 },
2805 Tokens: tk[:18],
2806 },
2807 },
2808 Tokens: tk[:18],
2809 }
2810 }},
2811 {`export type {A, B}`, func(t *test, tk Tokens) { // 73
2812 t.Typescript = true
2813 t.Output = Module{
2814 ModuleListItems: []ModuleItem{
2815 {
2816 StatementListItem: &StatementListItem{
2817 Statement: &Statement{
2818 Tokens: tk[:10],
2819 },
2820 Tokens: tk[:10],
2821 },
2822 Tokens: tk[:10],
2823 },
2824 },
2825 Tokens: tk[:10],
2826 }
2827 }},
2828 {`export interface A {}`, func(t *test, tk Tokens) { // 74
2829 t.Typescript = true
2830 t.Output = Module{
2831 ModuleListItems: []ModuleItem{
2832 {
2833 StatementListItem: &StatementListItem{
2834 Statement: &Statement{
2835 Tokens: tk[:8],
2836 },
2837 Tokens: tk[:8],
2838 },
2839 Tokens: tk[:8],
2840 },
2841 },
2842 Tokens: tk[:8],
2843 }
2844 }},
2845 {`type A = (this: B, c: D) => void;`, func(t *test, tk Tokens) { // 75
2846 t.Typescript = true
2847 t.Output = Module{
2848 ModuleListItems: []ModuleItem{
2849 {
2850 StatementListItem: &StatementListItem{
2851 Statement: &Statement{
2852 Tokens: tk[:23],
2853 },
2854 Tokens: tk[:23],
2855 },
2856 Tokens: tk[:23],
2857 },
2858 },
2859 Tokens: tk[:23],
2860 }
2861 }},
2862 {`class A {async B <C> (){}async <D> (){}}`, func(t *test, tk Tokens) { // 76
2863 t.Typescript = true
2864 t.Output = Module{
2865 ModuleListItems: []ModuleItem{
2866 {
2867 StatementListItem: &StatementListItem{
2868 Declaration: &Declaration{
2869 ClassDeclaration: &ClassDeclaration{
2870 BindingIdentifier: &tk[2],
2871 ClassBody: []ClassElement{
2872 {
2873 MethodDefinition: &MethodDefinition{
2874 Type: MethodAsync,
2875 ClassElementName: ClassElementName{
2876 PropertyName: &PropertyName{
2877 LiteralPropertyName: &tk[7],
2878 Tokens: tk[7:8],
2879 },
2880 Tokens: tk[7:8],
2881 },
2882 Params: FormalParameters{
2883 Tokens: tk[13:15],
2884 },
2885 FunctionBody: Block{
2886 Tokens: tk[15:17],
2887 },
2888 Tokens: tk[5:17],
2889 },
2890 Tokens: tk[5:17],
2891 },
2892 {
2893 MethodDefinition: &MethodDefinition{
2894 ClassElementName: ClassElementName{
2895 PropertyName: &PropertyName{
2896 LiteralPropertyName: &tk[17],
2897 Tokens: tk[17:18],
2898 },
2899 Tokens: tk[17:18],
2900 },
2901 Params: FormalParameters{
2902 Tokens: tk[23:25],
2903 },
2904 FunctionBody: Block{
2905 Tokens: tk[25:27],
2906 },
2907 Tokens: tk[17:27],
2908 },
2909 Tokens: tk[17:27],
2910 },
2911 },
2912 Tokens: tk[:28],
2913 },
2914 Tokens: tk[:28],
2915 },
2916 Tokens: tk[:28],
2917 },
2918 Tokens: tk[:28],
2919 },
2920 },
2921 Tokens: tk[:28],
2922 }
2923 }},
2924 {`<B>(1)=>{}`, func(t *test, tk Tokens) { // 77
2925 t.Typescript = true
2926 t.Err = Error{
2927 Err: Error{
2928 Err: Error{
2929 Err: Error{
2930 Err: Error{
2931 Err: Error{
2932 Err: Error{
2933 Err: Error{
2934 Err: ErrNoIdentifier,
2935 Parsing: "BindingElement",
2936 Token: tk[4],
2937 },
2938 Parsing: "FormalParameters",
2939 Token: tk[3],
2940 },
2941 Parsing: "ArrowFunction",
2942 Token: tk[3],
2943 },
2944 Parsing: "AssignmentExpression",
2945 Token: tk[0],
2946 },
2947 Parsing: "Expression",
2948 Token: tk[0],
2949 },
2950 Parsing: "Statement",
2951 Token: tk[0],
2952 },
2953 Parsing: "StatementListItem",
2954 Token: tk[0],
2955 },
2956 Parsing: "ModuleItem",
2957 Token: tk[0],
2958 }
2959 }},
2960 {`(...a: number[]) => {}`, func(t *test, tk Tokens) { // 78
2961 t.Typescript = true
2962 t.Output = Module{
2963 ModuleListItems: []ModuleItem{
2964 {
2965 StatementListItem: &StatementListItem{
2966 Statement: &Statement{
2967 ExpressionStatement: &Expression{
2968 Expressions: []AssignmentExpression{
2969 {
2970 ArrowFunction: &ArrowFunction{
2971 FormalParameters: &FormalParameters{
2972 BindingIdentifier: &tk[2],
2973 Tokens: tk[:9],
2974 },
2975 FunctionBody: &Block{
2976 Tokens: tk[12:14],
2977 },
2978 Tokens: tk[:14],
2979 },
2980 Tokens: tk[:14],
2981 },
2982 },
2983 Tokens: tk[:14],
2984 },
2985 Tokens: tk[:14],
2986 },
2987 Tokens: tk[:14],
2988 },
2989 Tokens: tk[:14],
2990 },
2991 },
2992 Tokens: tk[:14],
2993 }
2994 }},
2995 {`export default abstract`, func(t *test, tk Tokens) { // 79
2996 t.Typescript = true
2997 t.Output = Module{
2998 ModuleListItems: []ModuleItem{
2999 {
3000 ExportDeclaration: &ExportDeclaration{
3001 DefaultAssignmentExpression: &AssignmentExpression{
3002 ConditionalExpression: WrapConditional(&PrimaryExpression{
3003 IdentifierReference: &tk[4],
3004 Tokens: tk[4:5],
3005 }),
3006 Tokens: tk[4:5],
3007 },
3008 Tokens: tk[:5],
3009 },
3010 Tokens: tk[:5],
3011 },
3012 },
3013 Tokens: tk[:5],
3014 }
3015 }},
3016 {`export default abstract class!`, func(t *test, tk Tokens) { // 80
3017 t.Typescript = true
3018 t.Err = Error{
3019 Err: Error{
3020 Err: Error{
3021 Err: ErrMissingOpeningBrace,
3022 Parsing: "ClassDeclaration",
3023 Token: tk[7],
3024 },
3025 Parsing: "ExportDeclaration",
3026 Token: tk[4],
3027 },
3028 Parsing: "ModuleItem",
3029 Token: tk[0],
3030 }
3031 }},
3032 {`a()!`, func(t *test, tk Tokens) { // 81
3033 t.Typescript = true
3034 t.Output = Module{
3035 ModuleListItems: []ModuleItem{
3036 {
3037 StatementListItem: &StatementListItem{
3038 Statement: &Statement{
3039 ExpressionStatement: &Expression{
3040 Expressions: []AssignmentExpression{
3041 {
3042 ConditionalExpression: WrapConditional(&CallExpression{
3043 MemberExpression: &MemberExpression{
3044 PrimaryExpression: &PrimaryExpression{
3045 IdentifierReference: &tk[0],
3046 Tokens: tk[:1],
3047 },
3048 Tokens: tk[:1],
3049 },
3050 Arguments: &Arguments{
3051 Tokens: tk[1:3],
3052 },
3053 Tokens: tk[:4],
3054 }),
3055 Tokens: tk[:4],
3056 },
3057 },
3058 Tokens: tk[:4],
3059 },
3060 Tokens: tk[:4],
3061 },
3062 Tokens: tk[:4],
3063 },
3064 Tokens: tk[:4],
3065 },
3066 },
3067 Tokens: tk[:4],
3068 }
3069 }},
3070 {`a().b!`, func(t *test, tk Tokens) { // 82
3071 t.Typescript = true
3072 t.Output = Module{
3073 ModuleListItems: []ModuleItem{
3074 {
3075 StatementListItem: &StatementListItem{
3076 Statement: &Statement{
3077 ExpressionStatement: &Expression{
3078 Expressions: []AssignmentExpression{
3079 {
3080 ConditionalExpression: WrapConditional(&CallExpression{
3081 CallExpression: &CallExpression{
3082 MemberExpression: &MemberExpression{
3083 PrimaryExpression: &PrimaryExpression{
3084 IdentifierReference: &tk[0],
3085 Tokens: tk[:1],
3086 },
3087 Tokens: tk[:1],
3088 },
3089 Arguments: &Arguments{
3090 Tokens: tk[1:3],
3091 },
3092 Tokens: tk[:3],
3093 },
3094 IdentifierName: &tk[4],
3095 Tokens: tk[:6],
3096 }),
3097 Tokens: tk[:6],
3098 },
3099 },
3100 Tokens: tk[:6],
3101 },
3102 Tokens: tk[:6],
3103 },
3104 Tokens: tk[:6],
3105 },
3106 Tokens: tk[:6],
3107 },
3108 },
3109 Tokens: tk[:6],
3110 }
3111 }},
3112 {`([a]: number[] = [0]) => null`, func(t *test, tk Tokens) { // 83
3113 t.Typescript = true
3114 t.Output = Module{
3115 ModuleListItems: []ModuleItem{
3116 {
3117 StatementListItem: &StatementListItem{
3118 Statement: &Statement{
3119 ExpressionStatement: &Expression{
3120 Expressions: []AssignmentExpression{
3121 {
3122 ArrowFunction: &ArrowFunction{
3123 FormalParameters: &FormalParameters{
3124 FormalParameterList: []BindingElement{
3125 {
3126 ArrayBindingPattern: &ArrayBindingPattern{
3127 BindingElementList: []BindingElement{
3128 {
3129 SingleNameBinding: &tk[2],
3130 Tokens: tk[2:3],
3131 },
3132 },
3133 Tokens: tk[1:4],
3134 },
3135 Initializer: &AssignmentExpression{
3136 ConditionalExpression: WrapConditional(&PrimaryExpression{
3137 ArrayLiteral: &ArrayLiteral{
3138 ElementList: []ArrayElement{
3139 {
3140 AssignmentExpression: AssignmentExpression{
3141 ConditionalExpression: WrapConditional(&PrimaryExpression{
3142 Literal: &tk[13],
3143 Tokens: tk[13:14],
3144 }),
3145 Tokens: tk[13:14],
3146 },
3147 Tokens: tk[13:14],
3148 },
3149 },
3150 Tokens: tk[12:15],
3151 },
3152 Tokens: tk[12:15],
3153 }),
3154 Tokens: tk[12:15],
3155 },
3156 Tokens: tk[1:15],
3157 },
3158 },
3159 Tokens: tk[:16],
3160 },
3161 AssignmentExpression: &AssignmentExpression{
3162 ConditionalExpression: WrapConditional(&PrimaryExpression{
3163 Literal: &tk[19],
3164 Tokens: tk[19:20],
3165 }),
3166 Tokens: tk[19:20],
3167 },
3168 Tokens: tk[:20],
3169 },
3170 Tokens: tk[:20],
3171 },
3172 },
3173 Tokens: tk[:20],
3174 },
3175 Tokens: tk[:20],
3176 },
3177 Tokens: tk[:20],
3178 },
3179 Tokens: tk[:20],
3180 },
3181 },
3182 Tokens: tk[:20],
3183 }
3184 }},
3185 {`([...a, ...b]: number[] = [0]) => null`, func(t *test, tk Tokens) { // 84
3186 t.Typescript = true
3187 t.Err = Error{
3188 Err: Error{
3189 Err: Error{
3190 Err: Error{
3191 Err: Error{
3192 Err: Error{
3193 Err: Error{
3194 Err: Error{
3195 Err: Error{
3196 Err: Error{
3197 Err: Error{
3198 Err: Error{
3199 Err: Error{
3200 Err: Error{
3201 Err: Error{
3202 Err: Error{
3203 Err: Error{
3204 Err: Error{
3205 Err: Error{
3206 Err: Error{
3207 Err: Error{
3208 Err: Error{
3209 Err: Error{
3210 Err: Error{
3211 Err: Error{
3212 Err: Error{
3213 Err: ErrBadRestElement,
3214 Parsing: "ArrayAssignmentPattern",
3215 Token: tk[1],
3216 },
3217 Parsing: "AssignmentPattern",
3218 Token: tk[1],
3219 },
3220 Parsing: "ParenthesizedExpression",
3221 Token: tk[1],
3222 },
3223 Parsing: "PrimaryExpression",
3224 Token: tk[0],
3225 },
3226 Parsing: "MemberExpression",
3227 Token: tk[0],
3228 },
3229 Parsing: "NewExpression",
3230 Token: tk[0],
3231 },
3232 Parsing: "LeftHandSideExpression",
3233 Token: tk[0],
3234 },
3235 Parsing: "UpdateExpression",
3236 Token: tk[0],
3237 },
3238 Parsing: "UnaryExpression",
3239 Token: tk[0],
3240 },
3241 Parsing: "ExponentiationExpression",
3242 Token: tk[0],
3243 },
3244 Parsing: "MultiplicativeExpression",
3245 Token: tk[0],
3246 },
3247 Parsing: "AdditiveExpression",
3248 Token: tk[0],
3249 },
3250 Parsing: "ShiftExpression",
3251 Token: tk[0],
3252 },
3253 Parsing: "RelationalExpression",
3254 Token: tk[0],
3255 },
3256 Parsing: "EqualityExpression",
3257 Token: tk[0],
3258 },
3259 Parsing: "BitwiseANDExpression",
3260 Token: tk[0],
3261 },
3262 Parsing: "BitwiseXORExpression",
3263 Token: tk[0],
3264 },
3265 Parsing: "BitwiseORExpression",
3266 Token: tk[0],
3267 },
3268 Parsing: "LogicalANDExpression",
3269 Token: tk[0],
3270 },
3271 Parsing: "LogicalORExpression",
3272 Token: tk[0],
3273 },
3274 Parsing: "ConditionalExpression",
3275 Token: tk[0],
3276 },
3277 Parsing: "AssignmentExpression",
3278 Token: tk[0],
3279 },
3280 Parsing: "Expression",
3281 Token: tk[0],
3282 },
3283 Parsing: "Statement",
3284 Token: tk[0],
3285 },
3286 Parsing: "StatementListItem",
3287 Token: tk[0],
3288 },
3289 Parsing: "ModuleItem",
3290 Token: tk[0],
3291 }
3292 }},
3293 {`([a]: number = !) => null`, func(t *test, tk Tokens) { // 85
3294 t.Typescript = true
3295 t.Err = Error{
3296 Err: Error{
3297 Err: Error{
3298 Err: Error{
3299 Err: Error{
3300 Err: Error{
3301 Err: Error{
3302 Err: Error{
3303 Err: Error{
3304 Err: Error{
3305 Err: Error{
3306 Err: Error{
3307 Err: Error{
3308 Err: Error{
3309 Err: Error{
3310 Err: Error{
3311 Err: Error{
3312 Err: Error{
3313 Err: Error{
3314 Err: Error{
3315 Err: Error{
3316 Err: Error{
3317 Err: Error{
3318 Err: Error{
3319 Err: Error{
3320 Err: Error{
3321 Err: Error{
3322 Err: Error{
3323 Err: Error{
3324 Err: Error{
3325 Err: Error{
3326 Err: Error{
3327 Err: Error{
3328 Err: Error{
3329 Err: Error{
3330 Err: Error{
3331 Err: Error{
3332 Err: Error{
3333 Err: Error{
3334 Err: Error{
3335 Err: Error{
3336 Err: Error{
3337 Err: Error{
3338 Err: ErrNoIdentifier,
3339 Parsing: "PrimaryExpression",
3340 Token: tk[11],
3341 },
3342 Parsing: "MemberExpression",
3343 Token: tk[11],
3344 },
3345 Parsing: "NewExpression",
3346 Token: tk[11],
3347 },
3348 Parsing: "LeftHandSideExpression",
3349 Token: tk[11],
3350 },
3351 Parsing: "UpdateExpression",
3352 Token: tk[11],
3353 },
3354 Parsing: "UnaryExpression",
3355 Token: tk[11],
3356 },
3357 Parsing: "ExponentiationExpression",
3358 Token: tk[10],
3359 },
3360 Parsing: "MultiplicativeExpression",
3361 Token: tk[10],
3362 },
3363 Parsing: "AdditiveExpression",
3364 Token: tk[10],
3365 },
3366 Parsing: "ShiftExpression",
3367 Token: tk[10],
3368 },
3369 Parsing: "RelationalExpression",
3370 Token: tk[10],
3371 },
3372 Parsing: "EqualityExpression",
3373 Token: tk[10],
3374 },
3375 Parsing: "BitwiseANDExpression",
3376 Token: tk[10],
3377 },
3378 Parsing: "BitwiseXORExpression",
3379 Token: tk[10],
3380 },
3381 Parsing: "BitwiseORExpression",
3382 Token: tk[10],
3383 },
3384 Parsing: "LogicalANDExpression",
3385 Token: tk[10],
3386 },
3387 Parsing: "LogicalORExpression",
3388 Token: tk[10],
3389 },
3390 Parsing: "ConditionalExpression",
3391 Token: tk[10],
3392 },
3393 Parsing: "AssignmentExpression",
3394 Token: tk[10],
3395 },
3396 Parsing: "ParenthesizedExpression",
3397 Token: tk[10],
3398 },
3399 Parsing: "PrimaryExpression",
3400 Token: tk[0],
3401 },
3402 Parsing: "MemberExpression",
3403 Token: tk[0],
3404 },
3405 Parsing: "NewExpression",
3406 Token: tk[0],
3407 },
3408 Parsing: "LeftHandSideExpression",
3409 Token: tk[0],
3410 },
3411 Parsing: "UpdateExpression",
3412 Token: tk[0],
3413 },
3414 Parsing: "UnaryExpression",
3415 Token: tk[0],
3416 },
3417 Parsing: "ExponentiationExpression",
3418 Token: tk[0],
3419 },
3420 Parsing: "MultiplicativeExpression",
3421 Token: tk[0],
3422 },
3423 Parsing: "AdditiveExpression",
3424 Token: tk[0],
3425 },
3426 Parsing: "ShiftExpression",
3427 Token: tk[0],
3428 },
3429 Parsing: "RelationalExpression",
3430 Token: tk[0],
3431 },
3432 Parsing: "EqualityExpression",
3433 Token: tk[0],
3434 },
3435 Parsing: "BitwiseANDExpression",
3436 Token: tk[0],
3437 },
3438 Parsing: "BitwiseXORExpression",
3439 Token: tk[0],
3440 },
3441 Parsing: "BitwiseORExpression",
3442 Token: tk[0],
3443 },
3444 Parsing: "LogicalANDExpression",
3445 Token: tk[0],
3446 },
3447 Parsing: "LogicalORExpression",
3448 Token: tk[0],
3449 },
3450 Parsing: "ConditionalExpression",
3451 Token: tk[0],
3452 },
3453 Parsing: "AssignmentExpression",
3454 Token: tk[0],
3455 },
3456 Parsing: "Expression",
3457 Token: tk[0],
3458 },
3459 Parsing: "Statement",
3460 Token: tk[0],
3461 },
3462 Parsing: "StatementListItem",
3463 Token: tk[0],
3464 },
3465 Parsing: "ModuleItem",
3466 Token: tk[0],
3467 }
3468 }},
3469 {`abstract`, func(t *test, tk Tokens) { // 86
3470 t.Typescript = true
3471 t.Output = Module{
3472 ModuleListItems: []ModuleItem{
3473 {
3474 StatementListItem: &StatementListItem{
3475 Statement: &Statement{
3476 ExpressionStatement: &Expression{
3477 Expressions: []AssignmentExpression{
3478 {
3479 ConditionalExpression: WrapConditional(&PrimaryExpression{
3480 IdentifierReference: &tk[0],
3481 Tokens: tk[:1],
3482 }),
3483 Tokens: tk[:1],
3484 },
3485 },
3486 Tokens: tk[:1],
3487 },
3488 Tokens: tk[:1],
3489 },
3490 Tokens: tk[:1],
3491 },
3492 Tokens: tk[:1],
3493 },
3494 },
3495 Tokens: tk[:1],
3496 }
3497 }},
3498 {`type A<B> = {}`, func(t *test, tk Tokens) { // 87
3499 t.Typescript = true
3500 t.Output = Module{
3501 ModuleListItems: []ModuleItem{
3502 {
3503 StatementListItem: &StatementListItem{
3504 Statement: &Statement{
3505 Tokens: tk[:11],
3506 },
3507 Tokens: tk[:11],
3508 },
3509 Tokens: tk[:11],
3510 },
3511 },
3512 Tokens: tk[:11],
3513 }
3514 }},
3515 {`interface A {}`, func(t *test, tk Tokens) { // 88
3516 t.Typescript = true
3517 t.Output = Module{
3518 ModuleListItems: []ModuleItem{
3519 {
3520 StatementListItem: &StatementListItem{
3521 Statement: &Statement{
3522 Tokens: tk[:6],
3523 },
3524 Tokens: tk[:6],
3525 },
3526 Tokens: tk[:6],
3527 },
3528 },
3529 Tokens: tk[:6],
3530 }
3531 }},
3532 {`interface A<B> extends C {}`, func(t *test, tk Tokens) { // 89
3533 t.Typescript = true
3534 t.Output = Module{
3535 ModuleListItems: []ModuleItem{
3536 {
3537 StatementListItem: &StatementListItem{
3538 Statement: &Statement{
3539 Tokens: tk[:13],
3540 },
3541 Tokens: tk[:13],
3542 },
3543 Tokens: tk[:13],
3544 },
3545 },
3546 Tokens: tk[:13],
3547 }
3548 }},
3549 {`export type {A} from './b';`, func(t *test, tk Tokens) { // 90
3550 t.Typescript = true
3551 t.Output = Module{
3552 ModuleListItems: []ModuleItem{
3553 {
3554 StatementListItem: &StatementListItem{
3555 Statement: &Statement{
3556 Tokens: tk[:12],
3557 },
3558 Tokens: tk[:12],
3559 },
3560 Tokens: tk[:12],
3561 },
3562 },
3563 Tokens: tk[:12],
3564 }
3565 }},
3566 {`import {type A as B} from './c';`, func(t *test, tk Tokens) { // 91
3567 t.Typescript = true
3568 t.Output = Module{
3569 ModuleListItems: []ModuleItem{
3570 {
3571 ImportDeclaration: &ImportDeclaration{
3572 ImportClause: &ImportClause{
3573 NamedImports: &NamedImports{
3574 Tokens: tk[2:11],
3575 },
3576 Tokens: tk[2:11],
3577 },
3578 FromClause: FromClause{
3579 ModuleSpecifier: &tk[14],
3580 Tokens: tk[12:15],
3581 },
3582 Tokens: tk[:16],
3583 },
3584 Tokens: tk[:16],
3585 },
3586 },
3587 Tokens: tk[:16],
3588 }
3589 }},
3590 {`declare var a: number;`, func(t *test, tk Tokens) { // 92
3591 t.Typescript = true
3592 t.Output = Module{
3593 ModuleListItems: []ModuleItem{
3594 {
3595 StatementListItem: &StatementListItem{
3596 Statement: &Statement{
3597 Tokens: tk[:9],
3598 },
3599 Tokens: tk[:9],
3600 },
3601 Tokens: tk[:9],
3602 },
3603 },
3604 Tokens: tk[:9],
3605 }
3606 }},
3607 {`declare let a: number;`, func(t *test, tk Tokens) { // 93
3608 t.Typescript = true
3609 t.Output = Module{
3610 ModuleListItems: []ModuleItem{
3611 {
3612 StatementListItem: &StatementListItem{
3613 Statement: &Statement{
3614 Tokens: tk[:9],
3615 },
3616 Tokens: tk[:9],
3617 },
3618 Tokens: tk[:9],
3619 },
3620 },
3621 Tokens: tk[:9],
3622 }
3623 }},
3624 {`declare const a: number;`, func(t *test, tk Tokens) { // 94
3625 t.Typescript = true
3626 t.Output = Module{
3627 ModuleListItems: []ModuleItem{
3628 {
3629 StatementListItem: &StatementListItem{
3630 Statement: &Statement{
3631 Tokens: tk[:9],
3632 },
3633 Tokens: tk[:9],
3634 },
3635 Tokens: tk[:9],
3636 },
3637 },
3638 Tokens: tk[:9],
3639 }
3640 }},
3641 {`declare async function A<B>(): string`, func(t *test, tk Tokens) { // 95
3642 t.Typescript = true
3643 t.Output = Module{
3644 ModuleListItems: []ModuleItem{
3645 {
3646 StatementListItem: &StatementListItem{
3647 Statement: &Statement{
3648 Tokens: tk[:15],
3649 },
3650 Tokens: tk[:15],
3651 },
3652 Tokens: tk[:15],
3653 },
3654 },
3655 Tokens: tk[:15],
3656 }
3657 }},
3658 {`declare function* A(): number`, func(t *test, tk Tokens) { // 96
3659 t.Typescript = true
3660 t.Output = Module{
3661 ModuleListItems: []ModuleItem{
3662 {
3663 StatementListItem: &StatementListItem{
3664 Statement: &Statement{
3665 Tokens: tk[:11],
3666 },
3667 Tokens: tk[:11],
3668 },
3669 Tokens: tk[:11],
3670 },
3671 },
3672 Tokens: tk[:11],
3673 }
3674 }},
3675 {`declare class A {}`, func(t *test, tk Tokens) { // 97
3676 t.Typescript = true
3677 t.Output = Module{
3678 ModuleListItems: []ModuleItem{
3679 {
3680 StatementListItem: &StatementListItem{
3681 Statement: &Statement{
3682 Tokens: tk[:8],
3683 },
3684 Tokens: tk[:8],
3685 },
3686 Tokens: tk[:8],
3687 },
3688 },
3689 Tokens: tk[:8],
3690 }
3691 }},
3692 {`declare class A extends B {C(): void}`, func(t *test, tk Tokens) { // 98
3693 t.Typescript = true
3694 t.Output = Module{
3695 ModuleListItems: []ModuleItem{
3696 {
3697 StatementListItem: &StatementListItem{
3698 Statement: &Statement{
3699 Tokens: tk[:18],
3700 },
3701 Tokens: tk[:18],
3702 },
3703 Tokens: tk[:18],
3704 },
3705 },
3706 Tokens: tk[:18],
3707 }
3708 }},
3709 {`interface A {readonly B: C;}`, func(t *test, tk Tokens) { // 99
3710 t.Typescript = true
3711 t.Output = Module{
3712 ModuleListItems: []ModuleItem{
3713 {
3714 StatementListItem: &StatementListItem{
3715 Statement: &Statement{
3716 Tokens: tk[:13],
3717 },
3718 Tokens: tk[:13],
3719 },
3720 Tokens: tk[:13],
3721 },
3722 },
3723 Tokens: tk[:13],
3724 }
3725 }},
3726 {`interface A {(b?: B, c?: C): D}`, func(t *test, tk Tokens) { // 100
3727 t.Typescript = true
3728 t.Output = Module{
3729 ModuleListItems: []ModuleItem{
3730 {
3731 StatementListItem: &StatementListItem{
3732 Statement: &Statement{
3733 Tokens: tk[:23],
3734 },
3735 Tokens: tk[:23],
3736 },
3737 Tokens: tk[:23],
3738 },
3739 },
3740 Tokens: tk[:23],
3741 }
3742 }},
3743 {`type A = B & {}`, func(t *test, tk Tokens) { // 101
3744 t.Typescript = true
3745 t.Output = Module{
3746 ModuleListItems: []ModuleItem{
3747 {
3748 StatementListItem: &StatementListItem{
3749 Statement: &Statement{
3750 Tokens: tk[:12],
3751 },
3752 Tokens: tk[:12],
3753 },
3754 Tokens: tk[:12],
3755 },
3756 },
3757 Tokens: tk[:12],
3758 }
3759 }},
3760 {`class A {
3761 b(c: string): this;
3762 b(d: number): this
3763 b(): this {}
3764 }`, func(t *test, tk Tokens) { // 102
3765 t.Typescript = true
3766 t.Output = Module{
3767 ModuleListItems: []ModuleItem{
3768 {
3769 StatementListItem: &StatementListItem{
3770 Declaration: &Declaration{
3771 ClassDeclaration: &ClassDeclaration{
3772 BindingIdentifier: &tk[2],
3773 ClassBody: []ClassElement{
3774 {
3775 MethodDefinition: &MethodDefinition{
3776 ClassElementName: ClassElementName{
3777 PropertyName: &PropertyName{
3778 LiteralPropertyName: &tk[7],
3779 Tokens: tk[7:8],
3780 },
3781 Tokens: tk[7:8],
3782 },
3783 Params: FormalParameters{
3784 Tokens: tk[33:35],
3785 },
3786 FunctionBody: Block{
3787 Tokens: tk[39:41],
3788 },
3789 Tokens: tk[7:41],
3790 },
3791 Tokens: tk[7:41],
3792 },
3793 },
3794 Tokens: tk[:43],
3795 },
3796 Tokens: tk[:43],
3797 },
3798 Tokens: tk[:43],
3799 },
3800 Tokens: tk[:43],
3801 },
3802 },
3803 Tokens: tk[:43],
3804 }
3805 }},
3806 {`function a(): b;
3807 function a(): c;
3808 function a() {}`, func(t *test, tk Tokens) { // 103
3809 t.Typescript = true
3810 t.Output = Module{
3811 ModuleListItems: []ModuleItem{
3812 {
3813 StatementListItem: &StatementListItem{
3814 Declaration: &Declaration{
3815 FunctionDeclaration: &FunctionDeclaration{
3816 BindingIdentifier: &tk[2],
3817 FormalParameters: FormalParameters{
3818 Tokens: tk[23:25],
3819 },
3820 FunctionBody: Block{
3821 Tokens: tk[26:28],
3822 },
3823 Tokens: tk[:28],
3824 },
3825 Tokens: tk[:28],
3826 },
3827 Tokens: tk[:28],
3828 },
3829 Tokens: tk[:28],
3830 },
3831 },
3832 Tokens: tk[:28],
3833 }
3834 }},
3835 {`class A {
3836 static b(c: string): this
3837 static b(d: number): this;
3838 static b(): this {}
3839 }`, func(t *test, tk Tokens) { // 104
3840 t.Typescript = true
3841 t.Output = Module{
3842 ModuleListItems: []ModuleItem{
3843 {
3844 StatementListItem: &StatementListItem{
3845 Declaration: &Declaration{
3846 ClassDeclaration: &ClassDeclaration{
3847 BindingIdentifier: &tk[2],
3848 ClassBody: []ClassElement{
3849 {
3850 Static: true,
3851 MethodDefinition: &MethodDefinition{
3852 ClassElementName: ClassElementName{
3853 PropertyName: &PropertyName{
3854 LiteralPropertyName: &tk[9],
3855 Tokens: tk[9:10],
3856 },
3857 Tokens: tk[9:10],
3858 },
3859 Params: FormalParameters{
3860 Tokens: tk[39:41],
3861 },
3862 FunctionBody: Block{
3863 Tokens: tk[45:47],
3864 },
3865 Tokens: tk[9:47],
3866 },
3867 Tokens: tk[7:47],
3868 },
3869 },
3870 Tokens: tk[:49],
3871 },
3872 Tokens: tk[:49],
3873 },
3874 Tokens: tk[:49],
3875 },
3876 Tokens: tk[:49],
3877 },
3878 },
3879 Tokens: tk[:49],
3880 }
3881 }},
3882 {`class A {
3883 [b: number]: string;
3884 [c] = d;
3885 [e]!
3886 }`, func(t *test, tk Tokens) { // 105
3887 t.Typescript = true
3888 t.Output = Module{
3889 ModuleListItems: []ModuleItem{
3890 {
3891 StatementListItem: &StatementListItem{
3892 Declaration: &Declaration{
3893 ClassDeclaration: &ClassDeclaration{
3894 BindingIdentifier: &tk[2],
3895 ClassBody: []ClassElement{
3896 {
3897 FieldDefinition: &FieldDefinition{
3898 ClassElementName: ClassElementName{
3899 PropertyName: &PropertyName{
3900 ComputedPropertyName: &AssignmentExpression{
3901 ConditionalExpression: WrapConditional(&PrimaryExpression{
3902 IdentifierReference: &tk[20],
3903 Tokens: tk[20:21],
3904 }),
3905 Tokens: tk[20:21],
3906 },
3907 Tokens: tk[19:22],
3908 },
3909 Tokens: tk[19:22],
3910 },
3911 Initializer: &AssignmentExpression{
3912 ConditionalExpression: WrapConditional(&PrimaryExpression{
3913 IdentifierReference: &tk[25],
3914 Tokens: tk[25:26],
3915 }),
3916 Tokens: tk[25:26],
3917 },
3918 Tokens: tk[19:26],
3919 },
3920 Tokens: tk[19:27],
3921 },
3922 {
3923 FieldDefinition: &FieldDefinition{
3924 ClassElementName: ClassElementName{
3925 PropertyName: &PropertyName{
3926 ComputedPropertyName: &AssignmentExpression{
3927 ConditionalExpression: WrapConditional(&PrimaryExpression{
3928 IdentifierReference: &tk[30],
3929 Tokens: tk[30:31],
3930 }),
3931 Tokens: tk[30:31],
3932 },
3933 Tokens: tk[29:32],
3934 },
3935 Tokens: tk[29:32],
3936 },
3937 Tokens: tk[29:33],
3938 },
3939 Tokens: tk[29:33],
3940 },
3941 },
3942 Tokens: tk[:35],
3943 },
3944 Tokens: tk[:35],
3945 },
3946 Tokens: tk[:35],
3947 },
3948 Tokens: tk[:35],
3949 },
3950 },
3951 Tokens: tk[:35],
3952 }
3953 }},
3954 {`a as any as b as c`, func(t *test, tk Tokens) { // 106
3955 t.Typescript = true
3956 t.Output = Module{
3957 ModuleListItems: []ModuleItem{
3958 {
3959 StatementListItem: &StatementListItem{
3960 Statement: &Statement{
3961 ExpressionStatement: &Expression{
3962 Expressions: []AssignmentExpression{
3963 {
3964 ConditionalExpression: &ConditionalExpression{
3965 LogicalORExpression: WrapConditional(&LeftHandSideExpression{
3966 NewExpression: &NewExpression{
3967 MemberExpression: MemberExpression{
3968 PrimaryExpression: &PrimaryExpression{
3969 IdentifierReference: &tk[0],
3970 Tokens: tk[0:1],
3971 },
3972 Tokens: tk[0:1],
3973 },
3974 Tokens: tk[0:1],
3975 },
3976 Tokens: tk[0:13],
3977 }).LogicalORExpression,
3978
3979 Tokens: tk[0:13],
3980 },
3981 Tokens: tk[0:13],
3982 },
3983 },
3984 Tokens: tk[0:13],
3985 },
3986 Tokens: tk[0:13],
3987 },
3988 Tokens: tk[0:13],
3989 },
3990 Tokens: tk[0:13],
3991 },
3992 },
3993 Tokens: tk[0:13],
3994 }
3995 }},
3996 {`const a = (b :c) => {}`, func(t *test, tk Tokens) { // 107
3997 t.Typescript = true
3998 t.Output = Module{
3999 ModuleListItems: []ModuleItem{
4000 {
4001 StatementListItem: &StatementListItem{
4002 Declaration: &Declaration{
4003 LexicalDeclaration: &LexicalDeclaration{
4004 LetOrConst: Const,
4005 BindingList: []LexicalBinding{
4006 {
4007 BindingIdentifier: &tk[2],
4008 Initializer: &AssignmentExpression{
4009 ArrowFunction: &ArrowFunction{
4010 FormalParameters: &FormalParameters{
4011 FormalParameterList: []BindingElement{
4012 {
4013 SingleNameBinding: &tk[7],
4014 Tokens: tk[7:8],
4015 },
4016 },
4017 Tokens: tk[6:12],
4018 },
4019 FunctionBody: &Block{
4020 Tokens: tk[15:17],
4021 },
4022 Tokens: tk[6:17],
4023 },
4024 Tokens: tk[6:17],
4025 },
4026 Tokens: tk[2:17],
4027 },
4028 },
4029 Tokens: tk[:17],
4030 },
4031 Tokens: tk[:17],
4032 },
4033 Tokens: tk[:17],
4034 },
4035 Tokens: tk[:17],
4036 },
4037 },
4038 Tokens: tk[:17],
4039 }
4040 }},
4041 {`const a = b?.c()!;`, func(t *test, tk Tokens) { // 108
4042 t.Typescript = true
4043 t.Output = Module{
4044 ModuleListItems: []ModuleItem{
4045 {
4046 StatementListItem: &StatementListItem{
4047 Declaration: &Declaration{
4048 LexicalDeclaration: &LexicalDeclaration{
4049 LetOrConst: Const,
4050 BindingList: []LexicalBinding{
4051 {
4052 BindingIdentifier: &tk[2],
4053 Initializer: &AssignmentExpression{
4054 ConditionalExpression: WrapConditional(&OptionalExpression{
4055 MemberExpression: &MemberExpression{
4056 PrimaryExpression: &PrimaryExpression{
4057 IdentifierReference: &tk[6],
4058 Tokens: tk[6:7],
4059 },
4060 Tokens: tk[6:7],
4061 },
4062 OptionalChain: OptionalChain{
4063 OptionalChain: &OptionalChain{
4064 IdentifierName: &tk[8],
4065 Tokens: tk[7:9],
4066 },
4067 Arguments: &Arguments{
4068 Tokens: tk[9:11],
4069 },
4070 Tokens: tk[7:12],
4071 },
4072 Tokens: tk[6:12],
4073 }),
4074 Tokens: tk[6:12],
4075 },
4076 Tokens: tk[2:12],
4077 },
4078 },
4079 Tokens: tk[:13],
4080 },
4081 Tokens: tk[:13],
4082 },
4083 Tokens: tk[:13],
4084 },
4085 Tokens: tk[:13],
4086 },
4087 },
4088 Tokens: tk[:13],
4089 }
4090 }},
4091 {`type A = {[B in C]: D;}`, func(t *test, tk Tokens) { // 109
4092 t.Typescript = true
4093 t.Output = Module{
4094 ModuleListItems: []ModuleItem{
4095 {
4096 StatementListItem: &StatementListItem{
4097 Statement: &Statement{
4098 Tokens: tk[:19],
4099 },
4100 Tokens: tk[:19],
4101 },
4102 Tokens: tk[:19],
4103 },
4104 },
4105 Tokens: tk[:19],
4106 }
4107 }},
4108 {`function a<const B extends C[]>(d: B) {}`, func(t *test, tk Tokens) { // 110
4109 t.Typescript = true
4110 t.Output = Module{
4111 ModuleListItems: []ModuleItem{
4112 {
4113 StatementListItem: &StatementListItem{
4114 Declaration: &Declaration{
4115 FunctionDeclaration: &FunctionDeclaration{
4116 BindingIdentifier: &tk[2],
4117 FormalParameters: FormalParameters{
4118 FormalParameterList: []BindingElement{
4119 {
4120 SingleNameBinding: &tk[15],
4121 Tokens: tk[15:19],
4122 },
4123 },
4124 Tokens: tk[14:20],
4125 },
4126 FunctionBody: Block{
4127 Tokens: tk[21:23],
4128 },
4129 Tokens: tk[:23],
4130 },
4131 Tokens: tk[:23],
4132 },
4133 Tokens: tk[:23],
4134 },
4135 Tokens: tk[:23],
4136 },
4137 },
4138 Tokens: tk[:23],
4139 }
4140 }},
4141 {`type A<B> = { B(): C; finally(): B; }`, func(t *test, tk Tokens) { // 111
4142 t.Typescript = true
4143 t.Output = Module{
4144 ModuleListItems: []ModuleItem{
4145 {
4146 StatementListItem: &StatementListItem{
4147 Statement: &Statement{
4148 Tokens: tk[:28],
4149 },
4150 Tokens: tk[:28],
4151 },
4152 Tokens: tk[:28],
4153 },
4154 },
4155 Tokens: tk[:28],
4156 }
4157 }},
4158 {`((): this is b => true)`, func(t *test, tk Tokens) { // 112
4159 t.Typescript = true
4160 t.Output = Module{
4161 ModuleListItems: []ModuleItem{
4162 {
4163 StatementListItem: &StatementListItem{
4164 Statement: &Statement{
4165 ExpressionStatement: &Expression{
4166 Expressions: []AssignmentExpression{
4167 {
4168 ConditionalExpression: WrapConditional(&ParenthesizedExpression{
4169 Expressions: []AssignmentExpression{
4170 {
4171 ArrowFunction: &ArrowFunction{
4172 FormalParameters: &FormalParameters{
4173 Tokens: tk[1:3],
4174 },
4175 AssignmentExpression: &AssignmentExpression{
4176 ConditionalExpression: WrapConditional(&PrimaryExpression{
4177 Literal: &tk[13],
4178 Tokens: tk[13:14],
4179 }),
4180 Tokens: tk[13:14],
4181 },
4182 Tokens: tk[1:14],
4183 },
4184 Tokens: tk[1:14],
4185 },
4186 },
4187 Tokens: tk[:15],
4188 }),
4189 Tokens: tk[:15],
4190 },
4191 },
4192 Tokens: tk[:15],
4193 },
4194 Tokens: tk[:15],
4195 },
4196 Tokens: tk[:15],
4197 },
4198 Tokens: tk[:15],
4199 },
4200 },
4201 Tokens: tk[:15],
4202 }
4203 }},
4204 {`class A {b(): a is b {}}`, func(t *test, tk Tokens) { // 113
4205 t.Typescript = true
4206 t.Output = Module{
4207 ModuleListItems: []ModuleItem{
4208 {
4209 StatementListItem: &StatementListItem{
4210 Declaration: &Declaration{
4211 ClassDeclaration: &ClassDeclaration{
4212 BindingIdentifier: &tk[2],
4213 ClassBody: []ClassElement{
4214 {
4215 MethodDefinition: &MethodDefinition{
4216 ClassElementName: ClassElementName{
4217 PropertyName: &PropertyName{
4218 LiteralPropertyName: &tk[5],
4219 Tokens: tk[5:6],
4220 },
4221 Tokens: tk[5:6],
4222 },
4223 Params: FormalParameters{
4224 Tokens: tk[6:8],
4225 },
4226 FunctionBody: Block{
4227 Tokens: tk[16:18],
4228 },
4229 Tokens: tk[5:18],
4230 },
4231 Tokens: tk[5:18],
4232 },
4233 },
4234 Tokens: tk[:19],
4235 },
4236 Tokens: tk[:19],
4237 },
4238 Tokens: tk[:19],
4239 },
4240 Tokens: tk[:19],
4241 },
4242 },
4243 Tokens: tk[:19],
4244 }
4245 }},
4246 {`type A<B extends any[]> = B extends [b: infer C] ? C : B;`, func(t *test, tk Tokens) { // 114
4247 t.Typescript = true
4248 t.Output = Module{
4249 ModuleListItems: []ModuleItem{
4250 {
4251 StatementListItem: &StatementListItem{
4252 Statement: &Statement{
4253 Tokens: tk[:36],
4254 },
4255 Tokens: tk[:36],
4256 },
4257 Tokens: tk[:36],
4258 },
4259 },
4260 Tokens: tk[:36],
4261 }
4262 }},
4263 {`class A extends B<C<D>> {}`, func(t *test, tk Tokens) { // 115
4264 t.Typescript = true
4265 t.Output = Module{
4266 ModuleListItems: []ModuleItem{
4267 {
4268 StatementListItem: &StatementListItem{
4269 Declaration: &Declaration{
4270 ClassDeclaration: &ClassDeclaration{
4271 BindingIdentifier: &tk[2],
4272 ClassHeritage: &LeftHandSideExpression{
4273 NewExpression: &NewExpression{
4274 MemberExpression: MemberExpression{
4275 PrimaryExpression: &PrimaryExpression{
4276 IdentifierReference: &tk[6],
4277 Tokens: tk[6:7],
4278 },
4279 Tokens: tk[6:7],
4280 },
4281 Tokens: tk[6:7],
4282 },
4283 Tokens: tk[6:7],
4284 },
4285 Tokens: tk[:16],
4286 },
4287 Tokens: tk[:16],
4288 },
4289 Tokens: tk[:16],
4290 },
4291 Tokens: tk[:16],
4292 },
4293 },
4294 Tokens: tk[:16],
4295 }
4296 }},
4297 {`const a: import("mod").A = 1`, func(t *test, tk Tokens) { // 116
4298 t.Typescript = true
4299 t.Output = Module{
4300 ModuleListItems: []ModuleItem{
4301 {
4302 StatementListItem: &StatementListItem{
4303 Declaration: &Declaration{
4304 LexicalDeclaration: &LexicalDeclaration{
4305 LetOrConst: Const,
4306 BindingList: []LexicalBinding{
4307 {
4308 BindingIdentifier: &tk[2],
4309 Initializer: &AssignmentExpression{
4310 ConditionalExpression: WrapConditional(&PrimaryExpression{
4311 Literal: &tk[14],
4312 Tokens: tk[14:15],
4313 }),
4314 Tokens: tk[14:15],
4315 },
4316 Tokens: tk[2:15],
4317 },
4318 },
4319 Tokens: tk[:15],
4320 },
4321 Tokens: tk[:15],
4322 },
4323 Tokens: tk[:15],
4324 },
4325 Tokens: tk[:15],
4326 },
4327 },
4328 Tokens: tk[:15],
4329 }
4330 }},
4331 {`type A = [B?];`, func(t *test, tk Tokens) { // 117
4332 t.Typescript = true
4333 t.Output = Module{
4334 ModuleListItems: []ModuleItem{
4335 {
4336 StatementListItem: &StatementListItem{
4337 Statement: &Statement{
4338 Tokens: tk[:11],
4339 },
4340 Tokens: tk[:11],
4341 },
4342 Tokens: tk[:11],
4343 },
4344 },
4345 Tokens: tk[:11],
4346 }
4347 }},
4348 {`a.method().method2<string>()`, func(t *test, tk Tokens) { // 118
4349 t.Typescript = true
4350 t.Output = Module{
4351 ModuleListItems: []ModuleItem{
4352 {
4353 StatementListItem: &StatementListItem{
4354 Statement: &Statement{
4355 ExpressionStatement: &Expression{
4356 Expressions: []AssignmentExpression{
4357 {
4358 ConditionalExpression: WrapConditional(&CallExpression{
4359 CallExpression: &CallExpression{
4360 CallExpression: &CallExpression{
4361 MemberExpression: &MemberExpression{
4362 MemberExpression: &MemberExpression{
4363 PrimaryExpression: &PrimaryExpression{
4364 IdentifierReference: &tk[0],
4365 Tokens: tk[:1],
4366 },
4367 Tokens: tk[:1],
4368 },
4369 IdentifierName: &tk[2],
4370 Tokens: tk[:3],
4371 },
4372 Arguments: &Arguments{
4373 Tokens: tk[3:5],
4374 },
4375 Tokens: tk[:5],
4376 },
4377 IdentifierName: &tk[6],
4378 Tokens: tk[:7],
4379 },
4380 Arguments: &Arguments{
4381 Tokens: tk[7:12],
4382 },
4383 Tokens: tk[:12],
4384 }),
4385 Tokens: tk[:12],
4386 },
4387 },
4388 Tokens: tk[:12],
4389 },
4390 Tokens: tk[:12],
4391 },
4392 Tokens: tk[:12],
4393 },
4394 Tokens: tk[:12],
4395 },
4396 },
4397 Tokens: tk[:12],
4398 }
4399 }},
4400 {`a?.<string>()`, func(t *test, tk Tokens) { // 119
4401 t.Typescript = true
4402 t.Output = Module{
4403 ModuleListItems: []ModuleItem{
4404 {
4405 StatementListItem: &StatementListItem{
4406 Statement: &Statement{
4407 ExpressionStatement: &Expression{
4408 Expressions: []AssignmentExpression{
4409 {
4410 ConditionalExpression: WrapConditional(&OptionalExpression{
4411 MemberExpression: &MemberExpression{
4412 PrimaryExpression: &PrimaryExpression{
4413 IdentifierReference: &tk[0],
4414 Tokens: tk[:1],
4415 },
4416 Tokens: tk[:1],
4417 },
4418 OptionalChain: OptionalChain{
4419 Arguments: &Arguments{
4420 Tokens: tk[5:7],
4421 },
4422 Tokens: tk[1:7],
4423 },
4424 Tokens: tk[:7],
4425 }),
4426 Tokens: tk[:7],
4427 },
4428 },
4429 Tokens: tk[:7],
4430 },
4431 Tokens: tk[:7],
4432 },
4433 Tokens: tk[:7],
4434 },
4435 Tokens: tk[:7],
4436 },
4437 },
4438 Tokens: tk[:7],
4439 }
4440 }},
4441 {`a?.method<string>()`, func(t *test, tk Tokens) { // 120
4442 t.Typescript = true
4443 t.Output = Module{
4444 ModuleListItems: []ModuleItem{
4445 {
4446 StatementListItem: &StatementListItem{
4447 Statement: &Statement{
4448 ExpressionStatement: &Expression{
4449 Expressions: []AssignmentExpression{
4450 {
4451 ConditionalExpression: WrapConditional(&OptionalExpression{
4452 MemberExpression: &MemberExpression{
4453 PrimaryExpression: &PrimaryExpression{
4454 IdentifierReference: &tk[0],
4455 Tokens: tk[:1],
4456 },
4457 Tokens: tk[:1],
4458 },
4459 OptionalChain: OptionalChain{
4460 OptionalChain: &OptionalChain{
4461 IdentifierName: &tk[2],
4462 Tokens: tk[1:3],
4463 },
4464 Arguments: &Arguments{
4465 Tokens: tk[6:8],
4466 },
4467 Tokens: tk[1:8],
4468 },
4469 Tokens: tk[:8],
4470 }),
4471 Tokens: tk[:8],
4472 },
4473 },
4474 Tokens: tk[:8],
4475 },
4476 Tokens: tk[:8],
4477 },
4478 Tokens: tk[:8],
4479 },
4480 Tokens: tk[:8],
4481 },
4482 },
4483 Tokens: tk[:8],
4484 }
4485 }},
4486 {`const a = b as c ?? d`, func(t *test, tk Tokens) { // 121
4487 t.Typescript = true
4488 t.Output = Module{
4489 ModuleListItems: []ModuleItem{
4490 {
4491 StatementListItem: &StatementListItem{
4492 Declaration: &Declaration{
4493 LexicalDeclaration: &LexicalDeclaration{
4494 LetOrConst: Const,
4495 BindingList: []LexicalBinding{
4496 {
4497 BindingIdentifier: &tk[2],
4498 Initializer: &AssignmentExpression{
4499 ConditionalExpression: &ConditionalExpression{
4500 CoalesceExpression: &CoalesceExpression{
4501 CoalesceExpressionHead: &CoalesceExpression{
4502 BitwiseORExpression: WrapConditional(&LeftHandSideExpression{
4503 NewExpression: &NewExpression{
4504 MemberExpression: MemberExpression{
4505 PrimaryExpression: &PrimaryExpression{
4506 IdentifierReference: &tk[6],
4507 Tokens: tk[6:7],
4508 },
4509 Tokens: tk[6:7],
4510 },
4511 Tokens: tk[6:7],
4512 },
4513 Tokens: tk[6:11],
4514 }).LogicalORExpression.LogicalANDExpression.BitwiseORExpression,
4515 Tokens: tk[6:11],
4516 },
4517 BitwiseORExpression: WrapConditional(&PrimaryExpression{
4518 IdentifierReference: &tk[14],
4519 Tokens: tk[14:15],
4520 }).LogicalORExpression.LogicalANDExpression.BitwiseORExpression,
4521 Tokens: tk[6:15],
4522 },
4523 Tokens: tk[6:15],
4524 },
4525 Tokens: tk[6:15],
4526 },
4527 Tokens: tk[2:15],
4528 },
4529 },
4530 Tokens: tk[:15],
4531 },
4532 Tokens: tk[:15],
4533 },
4534 Tokens: tk[:15],
4535 },
4536 Tokens: tk[:15],
4537 },
4538 },
4539 Tokens: tk[:15],
4540 }
4541 }},
4542 }, func(t *test) (Type, error) {
4543 if t.Typescript {
4544 t.Tokens[:cap(t.Tokens)][cap(t.Tokens)-1].Data = marker
4545 }
4546 var m Module
4547 err := m.parse(&t.Tokens)
4548 return m, err
4549 })
4550 }
4551
4552 func TestTypescriptTypes(t *testing.T) {
4553 for n, test := range [...]struct {
4554 Fn func(*jsParser) bool
4555 Input string
4556 }{
4557 { // 1
4558 (*jsParser).ReadLiteralType,
4559 "1",
4560 },
4561 { // 2
4562 (*jsParser).ReadLiteralType,
4563 "2",
4564 },
4565 { // 3
4566 (*jsParser).ReadLiteralType,
4567 "-1",
4568 },
4569 { // 4
4570 (*jsParser).ReadLiteralType,
4571 "null",
4572 },
4573 { // 5
4574 (*jsParser).ReadLiteralType,
4575 "true",
4576 },
4577 { // 6
4578 (*jsParser).ReadLiteralType,
4579 "false",
4580 },
4581 { // 7
4582 (*jsParser).ReadLiteralType,
4583 "\"\"",
4584 },
4585 { // 8
4586 (*jsParser).ReadLiteralType,
4587 "\"string\"",
4588 },
4589 { // 9
4590 (*jsParser).ReadLiteralType,
4591 "``",
4592 },
4593 { // 10
4594 (*jsParser).ReadLiteralType,
4595 "`template`",
4596 },
4597 { // 11
4598 (*jsParser).ReadPredefinedType,
4599 "void",
4600 },
4601 { // 12
4602 (*jsParser).ReadPredefinedType,
4603 "any",
4604 },
4605 { // 13
4606 (*jsParser).ReadPredefinedType,
4607 "number",
4608 },
4609 { // 14
4610 (*jsParser).ReadPredefinedType,
4611 "boolean",
4612 },
4613 { // 15
4614 (*jsParser).ReadPredefinedType,
4615 "string",
4616 },
4617 { // 16
4618 (*jsParser).ReadPredefinedType,
4619 "symbol",
4620 },
4621 { // 17
4622 (*jsParser).ReadPredefinedType,
4623 "unknown",
4624 },
4625 { // 18
4626 (*jsParser).ReadPredefinedType,
4627 "bigint",
4628 },
4629 { // 19
4630 (*jsParser).ReadPredefinedType,
4631 "undefined",
4632 },
4633 { // 20
4634 (*jsParser).ReadPredefinedType,
4635 "never",
4636 },
4637 { // 21
4638 (*jsParser).ReadPredefinedType,
4639 "object",
4640 },
4641 { // 22
4642 (*jsParser).ReadThisType,
4643 "this",
4644 },
4645 { // 23
4646 (*jsParser).ReadTupleType,
4647 "[any]",
4648 },
4649 { // 24
4650 (*jsParser).ReadTupleType,
4651 "[ any ]",
4652 },
4653 { // 25
4654 (*jsParser).ReadTupleType,
4655 "[number,bigint]",
4656 },
4657 { // 26
4658 (*jsParser).ReadTupleType,
4659 "[ number , bigint ]",
4660 },
4661 { // 27
4662 (*jsParser).ReadTupleType,
4663 "[string,1,...symbol]",
4664 },
4665 { // 28
4666 (*jsParser).ReadTupleType,
4667 "[ string , 1 , ... symbol ]",
4668 },
4669 { // 29
4670 (*jsParser).ReadTupleType,
4671 "[...boolean]",
4672 },
4673 { // 30
4674 (*jsParser).ReadTupleType,
4675 "[ ... boolean ]",
4676 },
4677 { // 31
4678 (*jsParser).ReadTemplateType,
4679 "`A${number}B`",
4680 },
4681 { // 32
4682 (*jsParser).ReadTemplateType,
4683 "`A${ number }B`",
4684 },
4685 { // 33
4686 (*jsParser).ReadTemplateType,
4687 "`A${string}B${boolean}`",
4688 },
4689 { // 34
4690 (*jsParser).ReadTemplateType,
4691 "`A${ string }B${ boolean }`",
4692 },
4693 { // 35
4694 (*jsParser).ReadParenthesizedType,
4695 "(number)",
4696 },
4697 { // 36
4698 (*jsParser).ReadParenthesizedType,
4699 "( number )",
4700 },
4701 { // 37
4702 (*jsParser).ReadObjectType,
4703 "{}",
4704 },
4705 { // 38
4706 (*jsParser).ReadObjectType,
4707 "{ }",
4708 },
4709 { // 39
4710 (*jsParser).ReadObjectType,
4711 "{a:number}",
4712 },
4713 { // 40
4714 (*jsParser).ReadObjectType,
4715 "{ a : number }",
4716 },
4717 { // 41
4718 (*jsParser).ReadObjectType,
4719 "{a: number;}",
4720 },
4721 { // 42
4722 (*jsParser).ReadObjectType,
4723 "{a: number,}",
4724 },
4725 { // 43
4726 (*jsParser).ReadObjectType,
4727 "{a: number; }",
4728 },
4729 { // 44
4730 (*jsParser).ReadObjectType,
4731 "{a: number, }",
4732 },
4733 { // 45
4734 (*jsParser).ReadObjectType,
4735 "{a: number;b: string}",
4736 },
4737 { // 46
4738 (*jsParser).ReadObjectType,
4739 "{a: number; b: string}",
4740 },
4741 { // 47
4742 (*jsParser).ReadObjectType,
4743 "{a: number,b: string}",
4744 },
4745 { // 48
4746 (*jsParser).ReadObjectType,
4747 "{a: number, b: string}",
4748 },
4749 { // 49
4750 (*jsParser).ReadObjectType,
4751 "{(a: number)}",
4752 },
4753 { // 50
4754 (*jsParser).ReadObjectType,
4755 "{ < B > (a: B)}",
4756 },
4757 { // 51
4758 (*jsParser).ReadObjectType,
4759 "{(a: number) : string}",
4760 },
4761 { // 52
4762 (*jsParser).ReadObjectType,
4763 "{ < B > () : B}",
4764 },
4765 { // 53
4766 (*jsParser).ReadObjectType,
4767 "{new (a: number)}",
4768 },
4769 { // 54
4770 (*jsParser).ReadObjectType,
4771 "{ new < B > (a: B)}",
4772 },
4773 { // 55
4774 (*jsParser).ReadObjectType,
4775 "{new(a: number) : string}",
4776 },
4777 { // 56
4778 (*jsParser).ReadObjectType,
4779 "{ new < B > () : B}",
4780 },
4781 { // 57
4782 (*jsParser).ReadObjectType,
4783 "{get(a: number)}",
4784 },
4785 { // 58
4786 (*jsParser).ReadObjectType,
4787 "{ get < B > (a: B)}",
4788 },
4789 { // 59
4790 (*jsParser).ReadObjectType,
4791 "{get(a: number) : string}",
4792 },
4793 { // 60
4794 (*jsParser).ReadObjectType,
4795 "{ get < B > () : B}",
4796 },
4797 { // 61
4798 (*jsParser).ReadObjectType,
4799 "{set(a: number)}",
4800 },
4801 { // 62
4802 (*jsParser).ReadObjectType,
4803 "{ set < B > (a: B)}",
4804 },
4805 { // 63
4806 (*jsParser).ReadObjectType,
4807 "{set(a: number) : string}",
4808 },
4809 { // 64
4810 (*jsParser).ReadObjectType,
4811 "{ set < B > () : B}",
4812 },
4813 { // 65
4814 (*jsParser).ReadObjectType,
4815 "{ [ A ] }",
4816 },
4817 { // 66
4818 (*jsParser).ReadObjectType,
4819 "{[A: boolean]: bigint}",
4820 },
4821 { // 67
4822 (*jsParser).ReadObjectType,
4823 "{ [ A : number ] ? : string ; }",
4824 },
4825 { // 68
4826 (*jsParser).ReadObjectType,
4827 "{a()}",
4828 },
4829 { // 69
4830 (*jsParser).ReadObjectType,
4831 "{a?(): string}",
4832 },
4833 { // 70
4834 (*jsParser).ReadObjectType,
4835 "{a<B>(c: D): E}",
4836 },
4837 { // 71
4838 (*jsParser).ReadObjectType,
4839 "{ a ? < B > ( c : D ) : E ; }",
4840 },
4841 { // 72
4842 (*jsParser).ReadObjectType,
4843 "{'a'()}",
4844 },
4845 { // 73
4846 (*jsParser).ReadObjectType,
4847 "{0()}",
4848 },
4849 { // 74
4850 (*jsParser).ReadObjectType,
4851 "{0}",
4852 },
4853 { // 75
4854 (*jsParser).ReadObjectType,
4855 "{''}",
4856 },
4857 { // 76
4858 (*jsParser).ReadObjectType,
4859 "{0?: number}",
4860 },
4861 { // 77
4862 (*jsParser).ReadObjectType,
4863 "{'': string}",
4864 },
4865 { // 78
4866 (*jsParser).ReadObjectType,
4867 "{a}",
4868 },
4869 { // 79
4870 (*jsParser).ReadObjectType,
4871 "{ a : boolean ; }",
4872 },
4873 { // 80
4874 (*jsParser).ReadMappedType,
4875 "{readonly [A in B]}",
4876 },
4877 { // 81
4878 (*jsParser).ReadMappedType,
4879 "{+readonly [A in B]}",
4880 },
4881 { // 82
4882 (*jsParser).ReadMappedType,
4883 "{-readonly [A in B]}",
4884 },
4885 { // 83
4886 (*jsParser).ReadMappedType,
4887 "{[A in B]?}",
4888 },
4889 { // 84
4890 (*jsParser).ReadMappedType,
4891 "{[A in B]-?}",
4892 },
4893 { // 85
4894 (*jsParser).ReadMappedType,
4895 "{[A in B]?: string}",
4896 },
4897 { // 86
4898 (*jsParser).ReadMappedType,
4899 "{[A in B]-?: number}",
4900 },
4901 { // 87
4902 (*jsParser).ReadMappedType,
4903 "{[A in B as C]}",
4904 },
4905 { // 88
4906 (*jsParser).ReadTupleType,
4907 "[]",
4908 },
4909 { // 89
4910 (*jsParser).ReadTupleType,
4911 "[ ]",
4912 },
4913 { // 90
4914 (*jsParser).ReadTupleType,
4915 "[number]",
4916 },
4917 { // 91
4918 (*jsParser).ReadTupleType,
4919 "[ number ]",
4920 },
4921 { // 92
4922 (*jsParser).ReadTupleType,
4923 "[number, string]",
4924 },
4925 { // 93
4926 (*jsParser).ReadTupleType,
4927 "[ number, string ]",
4928 },
4929 { // 94
4930 (*jsParser).ReadTupleType,
4931 "[...number]",
4932 },
4933 { // 95
4934 (*jsParser).ReadTupleType,
4935 "[number, ...string]",
4936 },
4937 { // 96
4938 (*jsParser).ReadThisType,
4939 "this",
4940 },
4941 { // 97
4942 (*jsParser).ReadTypeQuery,
4943 "typeof A",
4944 },
4945 { // 98
4946 (*jsParser).ReadTypeQuery,
4947 "typeof A<B>",
4948 },
4949 { // 99
4950 (*jsParser).ReadTypeQuery,
4951 "typeof A.B",
4952 },
4953 { // 100
4954 (*jsParser).ReadTypeQuery,
4955 "typeof A.const",
4956 },
4957 { // 101
4958 (*jsParser).ReadTypeQuery,
4959 "typeof A.#B",
4960 },
4961 { // 102
4962 (*jsParser).ReadTypeQuery,
4963 "typeof A . #B . void",
4964 },
4965 { // 103
4966 (*jsParser).ReadTypeQuery,
4967 "typeof A.#B.void<C, D>",
4968 },
4969 { // 104
4970 (*jsParser).ReadTypeReference,
4971 "A",
4972 },
4973 { // 105
4974 (*jsParser).ReadTypeReference,
4975 "A.B",
4976 },
4977 { // 116
4978 (*jsParser).ReadTypeReference,
4979 "A<B>",
4980 },
4981 { // 107
4982 (*jsParser).ReadTypeReference,
4983 "A.B<C>",
4984 },
4985 { // 108
4986 (*jsParser).ReadTypeReference,
4987 "A . B < C >",
4988 },
4989 { // 109
4990 (*jsParser).ReadPostfixType,
4991 "number[]",
4992 },
4993 { // 110
4994 (*jsParser).ReadPostfixType,
4995 "`a${string}b` [ ] ",
4996 },
4997 { // 111
4998 (*jsParser).ReadPostfixType,
4999 "(boolean)!",
5000 },
5001 { // 112
5002 (*jsParser).ReadPostfixType,
5003 "(null)!",
5004 },
5005 { // 113
5006 (*jsParser).ReadPostfixType,
5007 "this ! []",
5008 },
5009 { // 114
5010 (*jsParser).ReadPostfixType,
5011 "typeof A [] !",
5012 },
5013 { // 115
5014 (*jsParser).ReadPostfixType,
5015 "A [ B ]",
5016 },
5017 { // 116
5018 (*jsParser).ReadTypeOperator,
5019 "infer A",
5020 },
5021 { // 117
5022 (*jsParser).ReadTypeOperator,
5023 "keyof infer A",
5024 },
5025 { // 118
5026 (*jsParser).ReadTypeOperator,
5027 "unique infer A",
5028 },
5029 { // 119
5030 (*jsParser).ReadTypeOperator,
5031 "readonly infer A",
5032 },
5033 { // 120
5034 (*jsParser).ReadTypeOperator,
5035 "keyof keyof infer A",
5036 },
5037 { // 121
5038 (*jsParser).ReadTypeOperator,
5039 "readonly unique infer A",
5040 },
5041 { // 122
5042 (*jsParser).ReadTypeOperator,
5043 "unique readonly infer A",
5044 },
5045 { // 123
5046 (*jsParser).ReadTypeOperator,
5047 "A [ B ]",
5048 },
5049 { // 124
5050 (*jsParser).ReadUnionOrIntersectionOrPrimaryType,
5051 "A",
5052 },
5053 { // 125
5054 (*jsParser).ReadUnionOrIntersectionOrPrimaryType,
5055 "A|B",
5056 },
5057 { // 126
5058 (*jsParser).ReadUnionOrIntersectionOrPrimaryType,
5059 "A & B | C",
5060 },
5061 { // 127
5062 (*jsParser).ReadUnionOrIntersectionOrPrimaryType,
5063 "A | B&C",
5064 },
5065 { // 128
5066 (*jsParser).ReadFunctionType,
5067 "()=>A",
5068 },
5069 { // 129
5070 (*jsParser).ReadFunctionType,
5071 "new()=>A",
5072 },
5073 { // 130
5074 (*jsParser).ReadFunctionType,
5075 "new<A>() => B",
5076 },
5077 { // 131
5078 (*jsParser).ReadFunctionType,
5079 "new < A, B > (B, C) => D",
5080 },
5081 { // 132
5082 (*jsParser).ReadFunctionType,
5083 "<A, B> (B, C) => D",
5084 },
5085 { // 133
5086 (*jsParser).ReadType,
5087 "A extends B?C:D",
5088 },
5089 { // 134
5090 (*jsParser).ReadType,
5091 "A extends B ? C : D",
5092 },
5093 { // 135
5094 (*jsParser).ReadType,
5095 "A",
5096 },
5097 { // 136
5098 (*jsParser).ReadType,
5099 "()=>void",
5100 },
5101 { // 137
5102 (*jsParser).ReadType,
5103 "<A extends B>()=>void",
5104 },
5105 { // 138
5106 (*jsParser).ReadType,
5107 "<A = B>()=>void",
5108 },
5109 { // 139
5110 (*jsParser).ReadType,
5111 "<A extends B = C>()=>void",
5112 },
5113 { // 140
5114 (*jsParser).ReadType,
5115 "< A, B extends C, D = E, F extends G = H >()=>void",
5116 },
5117 { // 141
5118 (*jsParser).ReadPredefinedType,
5119 "object.a",
5120 },
5121 { // 142
5122 (*jsParser).ReadPredefinedType,
5123 "any . a . b",
5124 },
5125 { // 143
5126 (*jsParser).ReadPredefinedType,
5127 "object . a . b <C, D>",
5128 },
5129 { // 144
5130 (*jsParser).ReadObjectType,
5131 "{ get [ A ]()}",
5132 },
5133 { // 145
5134 (*jsParser).ReadObjectType,
5135 `{
5136 a: boolean
5137 b: string
5138 }`,
5139 },
5140 { // 146
5141 (*jsParser).ReadFunctionType,
5142 "(...a)=>B",
5143 },
5144 { // 147
5145 (*jsParser).ReadFunctionType,
5146 "(a: string, ...b: number) => C",
5147 },
5148 { // 148
5149 (*jsParser).ReadFunctionType,
5150 "new (private a: string, public b: number, protected c: bigint) => D",
5151 },
5152 { // 149
5153 (*jsParser).ReadFunctionType,
5154 "(a: number = 1) => B",
5155 },
5156 { // 150
5157 (*jsParser).ReadObjectType,
5158 "{ get \"a\"(): string}",
5159 },
5160 { // 151
5161 (*jsParser).ReadObjectType,
5162 "{ get 0(): number}",
5163 },
5164 { // 152
5165 (*jsParser).ReadObjectType,
5166 "{ get #a(): bigint}",
5167 },
5168 { // 153
5169 (*jsParser).ReadObjectType,
5170 "{ get other(): boolean}",
5171 },
5172 } {
5173 tk := parser.NewStringTokeniser(test.Input)
5174 j, err := newJSParser(&tk)
5175 if err != nil {
5176 t.Errorf("test %d: unexpected error: %s", n+1, err)
5177 } else {
5178 j[:cap(j)][cap(j)-1].Data = marker
5179 g := j
5180 if !test.Fn(&j) {
5181 t.Errorf("test %d: failed on specific type fn ", n+1)
5182 } else if !g.ReadType() {
5183 t.Errorf("test %d: failed on generic type fn", n+1)
5184 } else if len(j) != len(g) {
5185 t.Errorf("test %d: inconsistant number of tokens read. %d != %d", n+1, len(j), len(g))
5186 }
5187 }
5188 }
5189 }
5190
5191 func TestAsTypescript(t *testing.T) {
5192 for n, test := range [...]struct {
5193 Input, Output string
5194 }{
5195 {
5196 "const a = 1;",
5197 "const a = 1;",
5198 },
5199 {
5200 "let a: number | null = null",
5201 "let a = null;",
5202 },
5203 } {
5204 tk := parser.NewStringTokeniser(test.Input)
5205 m, err := ParseModule(AsTypescript(&tk))
5206 if err != nil {
5207 t.Errorf("test %d: unexpected error: %s", n+1, err)
5208 } else if str := fmt.Sprintf("%s", m); str != test.Output {
5209 t.Errorf("test %d: expecting output %q, got %q", n+1, test.Output, str)
5210 }
5211 }
5212 }
5213