Skip to content

Commit 22167c2

Browse files
authored
Merge pull request #213 from nmote/typeof-prec
Fix type_query precedence
2 parents 1b3ba31 + 0a90858 commit 22167c2

File tree

6 files changed

+222794
-224132
lines changed

6 files changed

+222794
-224132
lines changed

common/corpus/types.txt

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ type T = typeof array[number];
767767
(type_alias_declaration (type_identifier)
768768
(intersection_type (index_type_query (type_identifier)) (type_identifier)))
769769
(type_alias_declaration (type_identifier)
770-
(type_query (subscript_expression (identifier) (predefined_type)))))
770+
(lookup_type (type_query (identifier)) (predefined_type))))
771771

772772
=======================================
773773
Lookup types
@@ -1318,9 +1318,10 @@ type T = Foo<Bar<typeof bar["baz"]>>
13181318
(generic_type
13191319
(type_identifier)
13201320
(type_arguments
1321-
(type_query
1322-
(subscript_expression
1323-
(identifier)
1321+
(lookup_type
1322+
(type_query
1323+
(identifier))
1324+
(literal_type
13241325
(string
13251326
(string_fragment))))))))))
13261327

@@ -1407,3 +1408,33 @@ type Foo<T> = abstract new () => T;
14071408
---
14081409

14091410
(program (type_alias_declaration (type_identifier) (type_parameters (type_parameter (type_identifier))) (constructor_type (formal_parameters) (type_identifier))))
1411+
1412+
=========================
1413+
Indexed Access Precedence
1414+
=========================
1415+
1416+
// These should generate the same AST aside from the parenthesized_type node
1417+
type X1 = typeof Y[keyof typeof Z];
1418+
type X2 = (typeof Y)[keyof typeof Z];
1419+
1420+
---
1421+
1422+
(program
1423+
(comment)
1424+
(type_alias_declaration
1425+
(type_identifier)
1426+
(lookup_type
1427+
(type_query
1428+
(identifier))
1429+
(index_type_query
1430+
(type_query
1431+
(identifier)))))
1432+
(type_alias_declaration
1433+
(type_identifier)
1434+
(lookup_type
1435+
(parenthesized_type
1436+
(type_query
1437+
(identifier)))
1438+
(index_type_query
1439+
(type_query
1440+
(identifier))))))

common/define-grammar.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports = function defineGrammar(dialect) {
4545
[$.readonly_type, $.pattern],
4646
[$.readonly_type, $.primary_expression],
4747
[$.type_query, $.subscript_expression, $.expression],
48+
[$.type_query, $._type_query_subscript_expression],
4849
[$.nested_type_identifier, $.generic_type, $._primary_type, $.lookup_type, $.index_type_query, $._type],
4950
[$.as_expression, $._primary_type],
5051
[$._type_query_member_expression, $.member_expression],

tsx/src/grammar.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10814,6 +10814,16 @@
1081410814
"name": "expression"
1081510815
}
1081610816
],
10817+
[
10818+
{
10819+
"type": "SYMBOL",
10820+
"name": "type_query"
10821+
},
10822+
{
10823+
"type": "SYMBOL",
10824+
"name": "_type_query_subscript_expression"
10825+
}
10826+
],
1081710827
[
1081810828
{
1081910829
"type": "SYMBOL",

0 commit comments

Comments
 (0)