@@ -19,11 +19,16 @@ module.exports = function defineGrammar(dialect) {
19
19
precedences : ( $ , previous ) => previous . concat ( [
20
20
[
21
21
'call' ,
22
+ 'instantiation' ,
22
23
'unary' ,
23
24
'binary' ,
24
25
$ . await_expression ,
25
26
$ . arrow_function ,
26
27
] ,
28
+ [
29
+ 'extends' ,
30
+ 'instantiation' ,
31
+ ] ,
27
32
[
28
33
$ . intersection_type ,
29
34
$ . union_type ,
@@ -53,6 +58,7 @@ module.exports = function defineGrammar(dialect) {
53
58
[ $ . _type_query_subscript_expression , $ . subscript_expression ] ,
54
59
[ $ . _type_query_subscript_expression , $ . primary_expression ] ,
55
60
[ $ . _type_query_call_expression , $ . primary_expression ] ,
61
+ [ $ . _type_query_instantiation_expression , $ . primary_expression ] ,
56
62
[ $ . type_query , $ . primary_expression ] ,
57
63
[ $ . override_modifier , $ . primary_expression ] ,
58
64
[ $ . decorator_call_expression , $ . decorator ] ,
@@ -61,11 +67,11 @@ module.exports = function defineGrammar(dialect) {
61
67
] ) ,
62
68
63
69
conflicts : ( $ , previous ) => previous . concat ( [
64
- [ $ . call_expression , $ . binary_expression ] ,
65
- [ $ . call_expression , $ . binary_expression , $ . unary_expression ] ,
66
- [ $ . call_expression , $ . binary_expression , $ . update_expression ] ,
70
+ [ $ . call_expression , $ . instantiation_expression , $ . binary_expression ] ,
71
+ [ $ . call_expression , $ . instantiation_expression , $ . binary_expression , $ . unary_expression ] ,
72
+ [ $ . call_expression , $ . instantiation_expression , $ . binary_expression , $ . update_expression ] ,
67
73
[ $ . call_expression , $ . binary_expression , $ . type_assertion ] ,
68
- [ $ . call_expression , $ . binary_expression , $ . await_expression ] ,
74
+ [ $ . call_expression , $ . instantiation_expression , $ . binary_expression , $ . await_expression ] ,
69
75
70
76
// This appears to be necessary to parse a parenthesized class expression
71
77
[ $ . class ] ,
@@ -208,6 +214,7 @@ module.exports = function defineGrammar(dialect) {
208
214
const choices = [
209
215
$ . as_expression ,
210
216
$ . satisfies_expression ,
217
+ $ . instantiation_expression ,
211
218
$ . internal_module ,
212
219
] ;
213
220
@@ -447,6 +454,11 @@ module.exports = function defineGrammar(dialect) {
447
454
$ . _type
448
455
) ) ,
449
456
457
+ instantiation_expression : $ => prec ( 'instantiation' , seq (
458
+ $ . expression ,
459
+ field ( 'type_arguments' , $ . type_arguments ) ,
460
+ ) ) ,
461
+
450
462
class_heritage : $ => choice (
451
463
seq ( $ . extends_clause , optional ( $ . implements_clause ) ) ,
452
464
$ . implements_clause
@@ -463,11 +475,13 @@ module.exports = function defineGrammar(dialect) {
463
475
464
476
extends_clause : $ => seq (
465
477
'extends' ,
466
- commaSep1 ( seq (
478
+ commaSep1 ( $ . _extends_clause_single ) ,
479
+ ) ,
480
+
481
+ _extends_clause_single : $ => prec ( 'extends' , seq (
467
482
field ( 'value' , $ . expression ) ,
468
483
field ( 'type_arguments' , optional ( $ . type_arguments ) )
469
- ) ) ,
470
- ) ,
484
+ ) ) ,
471
485
472
486
implements_clause : $ => seq (
473
487
'implements' ,
@@ -786,12 +800,22 @@ module.exports = function defineGrammar(dialect) {
786
800
) ) ,
787
801
field ( 'arguments' , $ . arguments )
788
802
) ,
803
+ _type_query_instantiation_expression : $ => seq (
804
+ field ( 'function' , choice (
805
+ $ . import ,
806
+ $ . identifier ,
807
+ alias ( $ . _type_query_member_expression , $ . member_expression ) ,
808
+ alias ( $ . _type_query_subscript_expression , $ . subscript_expression )
809
+ ) ) ,
810
+ field ( 'type_arguments' , $ . type_arguments )
811
+ ) ,
789
812
type_query : $ => prec . right ( seq (
790
813
'typeof' ,
791
814
choice (
792
815
alias ( $ . _type_query_subscript_expression , $ . subscript_expression ) ,
793
816
alias ( $ . _type_query_member_expression , $ . member_expression ) ,
794
817
alias ( $ . _type_query_call_expression , $ . call_expression ) ,
818
+ alias ( $ . _type_query_instantiation_expression , $ . instantiation_expression ) ,
795
819
$ . identifier
796
820
) ,
797
821
) ) ,
0 commit comments