@@ -36,6 +36,21 @@ module.exports = function defineGrammar(dialect) {
3636 ] ) ,
3737
3838 conflicts : ( $ , previous ) => previous . concat ( [
39+ [ $ . _expression , $ . call_expression ] ,
40+ [ $ . _expression , $ . arrow_function , $ . call_expression ] ,
41+ [ $ . _property_name , $ . arrow_function , $ . call_expression ] ,
42+ [ $ . _property_name , $ . _expression , $ . arrow_function , $ . call_expression ] ,
43+ [ $ . _property_name , $ . call_expression ] ,
44+ [ $ . _expression , $ . _property_name , $ . call_expression ] ,
45+ [ $ . _expression , $ . call_expression , $ . new_expression , $ . member_expression , $ . subscript_expression ] ,
46+ [ $ . _expression , $ . call_expression , $ . generic_type ] ,
47+
48+ [ $ . _expression , $ . call_expression , $ . new_expression ] ,
49+ [ $ . _expression , $ . new_expression ] ,
50+ [ $ . _expression , $ . arrow_function , $ . call_expression , $ . new_expression ] ,
51+ [ $ . call_expression , $ . new_expression ] ,
52+ [ $ . arrow_function , $ . new_expression , $ . call_expression ] ,
53+
3954 [ $ . call_expression , $ . binary_expression ] ,
4055 [ $ . call_expression , $ . binary_expression , $ . unary_expression ] ,
4156
@@ -93,25 +108,14 @@ module.exports = function defineGrammar(dialect) {
93108 optional ( $ . _initializer )
94109 ) ,
95110
96- call_expression : ( $ , previous ) => choice (
97- prec ( PREC . CALL , seq (
98- field ( 'function' , $ . _expression ) ,
99- field ( 'type_arguments' , optional ( $ . type_arguments ) ) ,
100- field ( 'arguments' , choice ( $ . arguments , $ . template_string ) )
101- ) ) ,
102- prec ( PREC . MEMBER , seq (
103- field ( 'function' , $ . _primary_expression ) ,
104- '?.' ,
105- field ( 'type_arguments' , optional ( $ . type_arguments ) ) ,
106- field ( 'arguments' , $ . arguments )
107- ) )
111+ call_expression : $ => choice (
112+ callExpression ( $ ) ( PREC . CALL ) ,
113+ callExpression ( $ ) ( PREC . MEMBER , '?.' ) ,
108114 ) ,
109115
110- new_expression : $ => prec . right ( PREC . NEW , seq (
116+ new_expression : $ => prec . dynamic ( PREC . NEW , seq (
111117 'new' ,
112- field ( 'constructor' , $ . _primary_expression ) ,
113- field ( 'type_arguments' , optional ( $ . type_arguments ) ) ,
114- field ( 'arguments' , optional ( $ . arguments ) )
118+ callExpression ( $ ) ( PREC . NEW )
115119 ) ) ,
116120
117121 // If the dialect is regular typescript, we exclude JSX expressions and
@@ -726,6 +730,19 @@ module.exports = function defineGrammar(dialect) {
726730 } ) ;
727731}
728732
733+ function callExpression ( $ ) {
734+ return function ( precedence , punctuation ) {
735+ return seq (
736+ ...[
737+ field ( 'function' , $ . _primary_expression ) ,
738+ ...( punctuation ? [ punctuation ] : [ ] ) ,
739+ field ( 'type_arguments' , prec . dynamic ( precedence , optional ( $ . type_arguments ) ) ) ,
740+ field ( 'arguments' , choice ( $ . arguments , $ . template_string ) )
741+ ]
742+ )
743+ }
744+ }
745+
729746function commaSep1 ( rule ) {
730747 return sepBy1 ( ',' , rule ) ;
731748}
0 commit comments