@@ -15,8 +15,13 @@ module.exports = grammar({
1515 $ . _automatic_semicolon ,
1616 $ . _template_chars ,
1717 $ . _ternary_qmark ,
18+ $ . _shorthand_arrow ,
1819 $ . html_comment ,
20+ // we use these just as signaling to the ASI scanner
1921 '||' ,
22+ '(' ,
23+ '[' ,
24+ '{' ,
2025 // We use escape sequence and regex pattern to tell the scanner if we're currently inside a string or template string, in which case
2126 // it should NOT parse html comments.
2227 $ . escape_sequence ,
@@ -58,7 +63,6 @@ module.exports = grammar({
5863 precedences : $ => [
5964 [
6065 'member' ,
61- 'template_call' ,
6266 'call' ,
6367 $ . update_expression ,
6468 'unary_void' ,
@@ -78,8 +82,9 @@ module.exports = grammar({
7882 $ . sequence_expression ,
7983 $ . arrow_function ,
8084 ] ,
85+ [ 'new' , $ . primary_expression ] ,
8186 [ 'assign' , $ . primary_expression ] ,
82- [ 'member' , 'template_call ' , 'new ' , 'call ' , $ . expression ] ,
87+ [ 'member' , 'new_args ' , 'call ' , 'new_no_args ' , $ . expression ] ,
8388 [ 'declaration' , 'literal' ] ,
8489 [ $ . primary_expression , $ . statement_block , 'object' ] ,
8590 [ $ . meta_property , $ . import ] ,
@@ -488,12 +493,14 @@ module.exports = grammar({
488493 $ . binary_expression ,
489494 $ . ternary_expression ,
490495 $ . update_expression ,
491- $ . new_expression ,
492496 $ . yield_expression ,
497+ $ . arrow_function ,
493498 ) ,
494499
500+ // Note: this is similar to MemberExpression from the ecmascript spec
495501 primary_expression : $ => choice (
496502 $ . subscript_expression ,
503+ $ . new_expression ,
497504 $ . member_expression ,
498505 $ . parenthesized_expression ,
499506 $ . _identifier ,
@@ -510,7 +517,6 @@ module.exports = grammar({
510517 $ . object ,
511518 $ . array ,
512519 $ . function_expression ,
513- $ . arrow_function ,
514520 $ . generator_function ,
515521 $ . class ,
516522 $ . meta_property ,
@@ -768,11 +774,16 @@ module.exports = grammar({
768774 ) ) ,
769775 $ . _call_signature ,
770776 ) ,
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+ ) ,
776787 ) ,
777788
778789 // Override
@@ -783,12 +794,8 @@ module.exports = grammar({
783794
784795 call_expression : $ => choice (
785796 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 ) ) ,
792799 ) ) ,
793800 prec ( 'member' , seq (
794801 field ( 'function' , $ . primary_expression ) ,
@@ -797,11 +804,17 @@ module.exports = grammar({
797804 ) ) ,
798805 ) ,
799806
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+ ) ,
805818
806819 await_expression : $ => prec ( 'unary_void' , seq (
807820 'await' ,
0 commit comments