@@ -20,7 +20,7 @@ const PREC = {
2020 NEG : 10 ,
2121 INC : 11 ,
2222 CALL : 12 ,
23- NEW : 12 ,
23+ NEW : 13 ,
2424 MEMBER : 14
2525} ;
2626
@@ -46,13 +46,12 @@ module.exports = grammar({
4646
4747 inline : $ => [
4848 $ . _call_signature ,
49- $ . _constructable_expression ,
49+ $ . _primary_expression ,
5050 $ . _statement ,
5151 $ . _expressions ,
5252 $ . _semicolon ,
5353 $ . _formal_parameter ,
5454 $ . _destructuring_pattern ,
55- $ . _identifier_reference ,
5655 $ . _reserved_identifier ,
5756 $ . _jsx_attribute ,
5857 $ . _jsx_element_name ,
@@ -75,7 +74,6 @@ module.exports = grammar({
7574 [ $ . assignment_pattern , $ . assignment_expression ] ,
7675 [ $ . computed_property_name , $ . array ] ,
7776 [ $ . _for_header , $ . _expression ] ,
78- [ $ . call_expression , $ . new_expression ] ,
7977 ] ,
8078
8179 word : $ => $ . identifier ,
@@ -404,21 +402,47 @@ module.exports = grammar({
404402 ) ,
405403
406404 _expression : $ => choice (
407- $ . _constructable_expression ,
405+ $ . _primary_expression ,
408406 $ . _jsx_element ,
409407 $ . jsx_fragment ,
410-
411408 $ . assignment_expression ,
412409 $ . augmented_assignment_expression ,
413410 $ . await_expression ,
414411 $ . unary_expression ,
415412 $ . binary_expression ,
416413 $ . ternary_expression ,
417414 $ . update_expression ,
418- $ . call_expression ,
415+ $ . new_expression ,
419416 $ . yield_expression ,
420417 ) ,
421418
419+ _primary_expression : $ => choice (
420+ $ . this ,
421+ $ . super ,
422+ $ . identifier ,
423+ alias ( $ . _reserved_identifier , $ . identifier ) ,
424+ $ . number ,
425+ $ . string ,
426+ $ . template_string ,
427+ $ . regex ,
428+ $ . true ,
429+ $ . false ,
430+ $ . null ,
431+ $ . undefined ,
432+ $ . import ,
433+ $ . object ,
434+ $ . array ,
435+ $ . function ,
436+ $ . arrow_function ,
437+ $ . generator_function ,
438+ $ . class ,
439+ $ . parenthesized_expression ,
440+ $ . subscript_expression ,
441+ $ . member_expression ,
442+ $ . meta_property ,
443+ $ . call_expression ,
444+ ) ,
445+
422446 yield_expression : $ => prec . right ( seq (
423447 'yield' ,
424448 choice (
@@ -625,62 +649,39 @@ module.exports = grammar({
625649 field ( 'parameters' , $ . formal_parameters )
626650 ) ,
627651
628- call_expression : $ => prec ( PREC . CALL , seq (
629- field ( 'function' , $ . _expression ) ,
630- optional ( '?.' ) ,
631- field ( 'arguments' , choice ( $ . arguments , $ . template_string ) )
632- ) ) ,
652+ call_expression : $ => choice (
653+ prec ( PREC . CALL , seq (
654+ field ( 'function' , $ . _expression ) ,
655+ field ( 'arguments' , choice ( $ . arguments , $ . template_string ) )
656+ ) ) ,
657+ prec ( PREC . MEMBER , seq (
658+ field ( 'function' , $ . _primary_expression ) ,
659+ '?.' ,
660+ field ( 'arguments' , $ . arguments )
661+ ) )
662+ ) ,
633663
634- new_expression : $ => prec ( PREC . NEW , seq (
664+ new_expression : $ => prec . right ( PREC . NEW , seq (
635665 'new' ,
636- field ( 'constructor' , $ . _expression ) ,
666+ field ( 'constructor' , $ . _primary_expression ) ,
637667 field ( 'arguments' , optional ( prec . dynamic ( 1 , $ . arguments ) ) )
638668 ) ) ,
639669
640- _constructable_expression : $ => choice (
641- $ . super ,
642- $ . this ,
643- $ . identifier ,
644- alias ( $ . _reserved_identifier , $ . identifier ) ,
645- $ . number ,
646- $ . string ,
647- $ . template_string ,
648- $ . regex ,
649- $ . true ,
650- $ . false ,
651- $ . null ,
652- $ . undefined ,
653- $ . import ,
654- $ . object ,
655- $ . array ,
656- $ . function ,
657- $ . arrow_function ,
658- $ . generator_function ,
659- $ . class ,
660- $ . parenthesized_expression ,
661- $ . subscript_expression ,
662- $ . member_expression ,
663- $ . meta_property ,
664- $ . new_expression ,
665- ) ,
666-
667670 await_expression : $ => seq (
668671 'await' ,
669672 $ . _expression
670673 ) ,
671674
672675 member_expression : $ => prec ( PREC . MEMBER , seq (
673- field ( 'object' , $ . _expression ) ,
676+ field ( 'object' , choice ( $ . _expression , $ . _primary_expression ) ) ,
674677 choice ( '.' , '?.' ) ,
675678 field ( 'property' , alias ( $ . identifier , $ . property_identifier ) )
676679 ) ) ,
677680
678681 subscript_expression : $ => prec . right ( PREC . MEMBER , seq (
679- field ( 'object' , $ . _expression ) ,
682+ field ( 'object' , choice ( $ . _expression , $ . _primary_expression ) ) ,
680683 optional ( '?.' ) ,
681- '[' ,
682- field ( 'index' , $ . _expressions ) ,
683- ']'
684+ '[' , field ( 'index' , $ . _expressions ) , ']'
684685 ) ) ,
685686
686687 _lhs_expression : $ => choice (
@@ -947,20 +948,15 @@ module.exports = grammar({
947948 decorator : $ => seq (
948949 '@' ,
949950 choice (
950- $ . _identifier_reference ,
951+ $ . identifier ,
951952 alias ( $ . decorator_member_expression , $ . member_expression ) ,
952953 alias ( $ . decorator_call_expression , $ . call_expression )
953954 )
954955 ) ,
955956
956- _identifier_reference : $ => choice (
957- $ . identifier ,
958- alias ( $ . _reserved_identifier , $ . identifier )
959- ) ,
960-
961957 decorator_member_expression : $ => prec ( PREC . MEMBER , seq (
962958 field ( 'object' , choice (
963- $ . _identifier_reference ,
959+ $ . identifier ,
964960 alias ( $ . decorator_member_expression , $ . member_expression )
965961 ) ) ,
966962 '.' ,
@@ -969,7 +965,7 @@ module.exports = grammar({
969965
970966 decorator_call_expression : $ => prec ( PREC . CALL , seq (
971967 field ( 'function' , choice (
972- $ . _identifier_reference ,
968+ $ . identifier ,
973969 alias ( $ . decorator_member_expression , $ . member_expression )
974970 ) ) ,
975971 field ( 'arguments' , $ . arguments )
0 commit comments