Skip to content

Commit 43252c5

Browse files
committed
feat: support special type_query types everywhere
1 parent b8439c2 commit 43252c5

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

common/define-grammar.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,7 @@ module.exports = function defineGrammar(dialect) {
654654
opting_type_annotation: $ => seq('?:', $.type),
655655
type_annotation: $ => seq(
656656
':',
657-
choice(
658-
$.type,
659-
alias($._type_query_member_expression_in_type_annotation, $.member_expression),
660-
alias($._type_query_call_expression_in_type_annotation, $.call_expression),
661-
),
657+
$.type,
662658
),
663659

664660
// Oh boy
@@ -702,6 +698,8 @@ module.exports = function defineGrammar(dialect) {
702698
$.readonly_type,
703699
$.constructor_type,
704700
$.infer_type,
701+
prec(-1, alias($._type_query_member_expression_in_type_annotation, $.member_expression)),
702+
prec(-1, alias($._type_query_call_expression_in_type_annotation, $.call_expression)),
705703
),
706704

707705
tuple_parameter: $ => seq(
@@ -927,11 +925,7 @@ module.exports = function defineGrammar(dialect) {
927925

928926
type_arguments: $ => seq(
929927
'<',
930-
commaSep1(choice(
931-
$.type,
932-
alias($._type_query_member_expression_in_type_annotation, $.member_expression),
933-
alias($._type_query_call_expression_in_type_annotation, $.call_expression),
934-
)),
928+
commaSep1($.type),
935929
optional(','),
936930
'>',
937931
),

test/corpus/types.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,3 +2167,29 @@ class A {
21672167
(this)
21682168
(property_identifier))
21692169
(number))))))
2170+
2171+
=========================
2172+
Import in type
2173+
=========================
2174+
2175+
type Foo = import('node:fs').ReadStream & {
2176+
bar();
2177+
};
2178+
2179+
---
2180+
2181+
(program
2182+
(type_alias_declaration
2183+
(type_identifier)
2184+
(intersection_type
2185+
(member_expression
2186+
(call_expression
2187+
(import)
2188+
(arguments
2189+
(string
2190+
(string_fragment))))
2191+
(property_identifier))
2192+
(object_type
2193+
(method_signature
2194+
(property_identifier)
2195+
(formal_parameters))))))

0 commit comments

Comments
 (0)