@@ -15,8 +15,13 @@ module.exports = grammar({
15
15
$ . _automatic_semicolon ,
16
16
$ . _template_chars ,
17
17
$ . _ternary_qmark ,
18
+ $ . _shorthand_arrow ,
18
19
$ . html_comment ,
20
+ // we use these just as signaling to the ASI scanner
19
21
'||' ,
22
+ '(' ,
23
+ '[' ,
24
+ '{' ,
20
25
// We use escape sequence and regex pattern to tell the scanner if we're currently inside a string or template string, in which case
21
26
// it should NOT parse html comments.
22
27
$ . escape_sequence ,
@@ -58,7 +63,6 @@ module.exports = grammar({
58
63
precedences : $ => [
59
64
[
60
65
'member' ,
61
- 'template_call' ,
62
66
'call' ,
63
67
$ . update_expression ,
64
68
'unary_void' ,
@@ -78,8 +82,9 @@ module.exports = grammar({
78
82
$ . sequence_expression ,
79
83
$ . arrow_function ,
80
84
] ,
85
+ [ 'new' , $ . primary_expression ] ,
81
86
[ 'assign' , $ . primary_expression ] ,
82
- [ 'member' , 'template_call ' , 'new ' , 'call ' , $ . expression ] ,
87
+ [ 'member' , 'new_args ' , 'call ' , 'new_no_args ' , $ . expression ] ,
83
88
[ 'declaration' , 'literal' ] ,
84
89
[ $ . primary_expression , $ . statement_block , 'object' ] ,
85
90
[ $ . meta_property , $ . import ] ,
@@ -488,12 +493,14 @@ module.exports = grammar({
488
493
$ . binary_expression ,
489
494
$ . ternary_expression ,
490
495
$ . update_expression ,
491
- $ . new_expression ,
492
496
$ . yield_expression ,
497
+ $ . arrow_function ,
493
498
) ,
494
499
500
+ // Note: this is similar to MemberExpression from the ecmascript spec
495
501
primary_expression : $ => choice (
496
502
$ . subscript_expression ,
503
+ $ . new_expression ,
497
504
$ . member_expression ,
498
505
$ . parenthesized_expression ,
499
506
$ . _identifier ,
@@ -510,7 +517,6 @@ module.exports = grammar({
510
517
$ . object ,
511
518
$ . array ,
512
519
$ . function_expression ,
513
- $ . arrow_function ,
514
520
$ . generator_function ,
515
521
$ . class ,
516
522
$ . meta_property ,
@@ -768,11 +774,16 @@ module.exports = grammar({
768
774
) ) ,
769
775
$ . _call_signature ,
770
776
) ,
771
- '=>' ,
772
- field ( 'body' , choice (
773
- $ . expression ,
774
- $ . statement_block ,
775
- ) ) ,
777
+ choice (
778
+ seq (
779
+ alias ( $ . _shorthand_arrow , '=>' ) ,
780
+ field ( 'body' , $ . expression ) ,
781
+ ) ,
782
+ seq (
783
+ choice ( '=>' , alias ( $ . _shorthand_arrow , '=>' ) ) ,
784
+ field ( 'body' , $ . statement_block ) ,
785
+ ) ,
786
+ ) ,
776
787
) ,
777
788
778
789
// Override
@@ -783,12 +794,8 @@ module.exports = grammar({
783
794
784
795
call_expression : $ => choice (
785
796
prec ( 'call' , seq (
786
- field ( 'function' , choice ( $ . expression , $ . import ) ) ,
787
- field ( 'arguments' , $ . arguments ) ,
788
- ) ) ,
789
- prec ( 'template_call' , seq (
790
- field ( 'function' , choice ( $ . primary_expression , $ . new_expression ) ) ,
791
- field ( 'arguments' , $ . template_string ) ,
797
+ field ( 'function' , choice ( $ . primary_expression , $ . import ) ) ,
798
+ field ( 'arguments' , choice ( $ . arguments , $ . template_string ) ) ,
792
799
) ) ,
793
800
prec ( 'member' , seq (
794
801
field ( 'function' , $ . primary_expression ) ,
@@ -797,11 +804,17 @@ module.exports = grammar({
797
804
) ) ,
798
805
) ,
799
806
800
- new_expression : $ => prec . right ( 'new' , seq (
801
- 'new' ,
802
- field ( 'constructor' , choice ( $ . primary_expression , $ . new_expression ) ) ,
803
- field ( 'arguments' , optional ( prec . dynamic ( 1 , $ . arguments ) ) ) ,
804
- ) ) ,
807
+ new_expression : $ => choice (
808
+ prec ( 'new_args' , seq (
809
+ 'new' ,
810
+ field ( 'constructor' , $ . primary_expression ) ,
811
+ field ( 'arguments' , $ . arguments ) ,
812
+ ) ) ,
813
+ prec ( 'new_no_args' , seq (
814
+ 'new' ,
815
+ field ( 'constructor' , $ . primary_expression ) ,
816
+ ) ) ,
817
+ ) ,
805
818
806
819
await_expression : $ => prec ( 'unary_void' , seq (
807
820
'await' ,
0 commit comments