@@ -48,6 +48,7 @@ module.exports = function defineGrammar(dialect) {
48
48
[ $ . nested_type_identifier , $ . generic_type , $ . _primary_type , $ . lookup_type , $ . index_type_query , $ . _type ] ,
49
49
[ $ . as_expression , $ . satisfies_expression , $ . _primary_type ] ,
50
50
[ $ . _type_query_member_expression , $ . member_expression ] ,
51
+ [ $ . member_expression , $ . _type_query_member_expression_in_type_annotation ] ,
51
52
[ $ . _type_query_member_expression , $ . primary_expression ] ,
52
53
[ $ . _type_query_subscript_expression , $ . subscript_expression ] ,
53
54
[ $ . _type_query_subscript_expression , $ . primary_expression ] ,
@@ -58,10 +59,11 @@ module.exports = function defineGrammar(dialect) {
58
59
[ $ . decorator_call_expression , $ . decorator ] ,
59
60
[ $ . literal_type , $ . pattern ] ,
60
61
[ $ . predefined_type , $ . pattern ] ,
61
- [ $ . _primary_type , $ . _type_query_subscript_expression ] ,
62
- [ $ . nested_type_identifier , $ . _type_query_member_expression ] ,
63
- [ $ . nested_identifier , $ . _type_query_member_expression ] ,
64
- [ $ . generic_type , $ . _type_query_instantiation_expression ] ,
62
+ [ $ . call_expression , $ . _type_query_call_expression ] ,
63
+ [ $ . call_expression , $ . _type_query_call_expression_in_type_annotation ] ,
64
+ [ $ . new_expression , $ . primary_expression ] ,
65
+ [ $ . meta_property , $ . primary_expression ] ,
66
+ [ $ . construct_signature , $ . _property_name ] ,
65
67
] ) ,
66
68
67
69
conflicts : ( $ , previous ) => previous . concat ( [
@@ -635,13 +637,37 @@ module.exports = function defineGrammar(dialect) {
635
637
':' ,
636
638
choice (
637
639
$ . _type ,
638
- alias ( $ . _type_query_subscript_expression , $ . subscript_expression ) ,
639
- alias ( $ . _type_query_member_expression , $ . member_expression ) ,
640
- alias ( $ . _type_query_call_expression , $ . call_expression ) ,
641
- alias ( $ . _type_query_instantiation_expression , $ . instantiation_expression ) ,
640
+ alias ( $ . _type_query_member_expression_in_type_annotation , $ . member_expression ) ,
641
+ alias ( $ . _type_query_call_expression_in_type_annotation , $ . call_expression ) ,
642
642
)
643
643
) ,
644
644
645
+ // Oh boy
646
+ // The issue is these special type queries need a lower relative precedence than the normal ones,
647
+ // since these are used in type annotations whereas the other ones are used where `typeof` is
648
+ // required beforehand. This allows for parsing of annotations such as
649
+ // foo: import('x').y.z;
650
+ // but was a nightmare to get working.
651
+ _type_query_member_expression_in_type_annotation : $ => seq (
652
+ field ( 'object' , choice (
653
+ $ . import ,
654
+ alias ( $ . _type_query_member_expression_in_type_annotation , $ . member_expression ) ,
655
+ alias ( $ . _type_query_call_expression_in_type_annotation , $ . call_expression )
656
+ ) ) ,
657
+ '.' ,
658
+ field ( 'property' , choice (
659
+ $ . private_property_identifier ,
660
+ alias ( $ . identifier , $ . property_identifier )
661
+ ) )
662
+ ) ,
663
+ _type_query_call_expression_in_type_annotation : $ => seq (
664
+ field ( 'function' , choice (
665
+ $ . import ,
666
+ alias ( $ . _type_query_member_expression_in_type_annotation , $ . member_expression ) ,
667
+ ) ) ,
668
+ field ( 'arguments' , $ . arguments )
669
+ ) ,
670
+
645
671
asserts : $ => seq (
646
672
'asserts' ,
647
673
choice ( $ . type_predicate , $ . identifier , $ . this )
@@ -880,7 +906,14 @@ module.exports = function defineGrammar(dialect) {
880
906
) ,
881
907
882
908
type_arguments : $ => seq (
883
- '<' , commaSep1 ( $ . _type ) , optional ( ',' ) , '>'
909
+ '<' ,
910
+ commaSep1 ( choice (
911
+ $ . _type ,
912
+ alias ( $ . _type_query_member_expression_in_type_annotation , $ . member_expression ) ,
913
+ alias ( $ . _type_query_call_expression_in_type_annotation , $ . call_expression )
914
+ ) ) ,
915
+ optional ( ',' ) ,
916
+ '>'
884
917
) ,
885
918
886
919
object_type : $ => seq (
0 commit comments