@@ -15,8 +15,12 @@ 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
+ '[' ,
20
24
// 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
25
// it should NOT parse html comments.
22
26
$ . escape_sequence ,
@@ -58,7 +62,6 @@ module.exports = grammar({
58
62
precedences : $ => [
59
63
[
60
64
'member' ,
61
- 'template_call' ,
62
65
'call' ,
63
66
$ . update_expression ,
64
67
'unary_void' ,
@@ -78,8 +81,9 @@ module.exports = grammar({
78
81
$ . sequence_expression ,
79
82
$ . arrow_function ,
80
83
] ,
84
+ [ 'new' , $ . primary_expression ] ,
81
85
[ 'assign' , $ . primary_expression ] ,
82
- [ 'member' , 'template_call ' , 'new ' , 'call ' , $ . expression ] ,
86
+ [ 'member' , 'new_args ' , 'call ' , 'new_no_args ' , $ . expression ] ,
83
87
[ 'declaration' , 'literal' ] ,
84
88
[ $ . primary_expression , $ . statement_block , 'object' ] ,
85
89
[ $ . meta_property , $ . import ] ,
@@ -488,12 +492,14 @@ module.exports = grammar({
488
492
$ . binary_expression ,
489
493
$ . ternary_expression ,
490
494
$ . update_expression ,
491
- $ . new_expression ,
492
495
$ . yield_expression ,
496
+ $ . arrow_function ,
493
497
) ,
494
498
499
+ // Note: this is similar to MemberExpression from the ecmascript spec
495
500
primary_expression : $ => choice (
496
501
$ . subscript_expression ,
502
+ $ . new_expression ,
497
503
$ . member_expression ,
498
504
$ . parenthesized_expression ,
499
505
$ . _identifier ,
@@ -510,7 +516,6 @@ module.exports = grammar({
510
516
$ . object ,
511
517
$ . array ,
512
518
$ . function_expression ,
513
- $ . arrow_function ,
514
519
$ . generator_function ,
515
520
$ . class ,
516
521
$ . meta_property ,
@@ -768,11 +773,10 @@ module.exports = grammar({
768
773
) ) ,
769
774
$ . _call_signature ,
770
775
) ,
771
- '=>' ,
772
- field ( 'body' , choice (
773
- $ . expression ,
774
- $ . statement_block ,
775
- ) ) ,
776
+ choice (
777
+ seq ( $ . _shorthand_arrow , field ( 'body' , $ . expression ) ) ,
778
+ seq ( choice ( '=>' , $ . _shorthand_arrow ) , field ( 'body' , $ . statement_block ) ) ,
779
+ ) ,
776
780
) ,
777
781
778
782
// Override
@@ -783,12 +787,8 @@ module.exports = grammar({
783
787
784
788
call_expression : $ => choice (
785
789
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 ) ,
790
+ field ( 'function' , choice ( $ . primary_expression , $ . import ) ) ,
791
+ field ( 'arguments' , choice ( $ . arguments , $ . template_string ) ) ,
792
792
) ) ,
793
793
prec ( 'member' , seq (
794
794
field ( 'function' , $ . primary_expression ) ,
@@ -797,11 +797,17 @@ module.exports = grammar({
797
797
) ) ,
798
798
) ,
799
799
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
- ) ) ,
800
+ new_expression : $ => choice (
801
+ prec ( 'new_args' , seq (
802
+ 'new' ,
803
+ field ( 'constructor' , $ . primary_expression ) ,
804
+ field ( 'arguments' , $ . arguments ) ,
805
+ ) ) ,
806
+ prec ( 'new_no_args' , seq (
807
+ 'new' ,
808
+ field ( 'constructor' , $ . primary_expression ) ,
809
+ ) ) ,
810
+ ) ,
805
811
806
812
await_expression : $ => prec ( 'unary_void' , seq (
807
813
'await' ,
0 commit comments