Skip to content

Commit bb252d7

Browse files
committed
fix: allow certain type queries in type annotations
1 parent 9e0ce8e commit bb252d7

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

common/define-grammar.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ module.exports = function defineGrammar(dialect) {
5858
[$.decorator_call_expression, $.decorator],
5959
[$.literal_type, $.pattern],
6060
[$.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],
6165
]),
6266

6367
conflicts: ($, previous) => previous.concat([
@@ -618,7 +622,16 @@ module.exports = function defineGrammar(dialect) {
618622
omitting_type_annotation: $ => seq('-?:', $._type),
619623
adding_type_annotation: $ => seq('+?:', $._type),
620624
opting_type_annotation: $ => seq('?:', $._type),
621-
type_annotation: $ => seq(':', $._type),
625+
type_annotation: $ => seq(
626+
':',
627+
choice(
628+
$._type,
629+
alias($._type_query_subscript_expression, $.subscript_expression),
630+
alias($._type_query_member_expression, $.member_expression),
631+
alias($._type_query_call_expression, $.call_expression),
632+
alias($._type_query_instantiation_expression, $.instantiation_expression),
633+
)
634+
),
622635

623636
asserts: $ => seq(
624637
'asserts',

0 commit comments

Comments
 (0)