The precedence for type_query needs to be higher than that of
_type_query_subscript_expression. Otherwise, the parser will generate
incorrect parses, and even fail to parse valid code in some cases.
The code type X1 = typeof Y[keyof typeof Z]; should actually have
typeof Y grouped together. I verified this in astexplorer.net, and I
verified that TypeScript itself does parse this line. Currently, it
fails to parse using this tree-sitter grammar. Because of the incorrect
precedence, it expects an expression between the brackets instead of a
type.
I also used AST Explorer to check how TypeScript parses the other tests
that changed. In both cases, the updated parse is correct.
Checklist:
[x] All tests pass in CI.
[x] There are sufficient tests for the new fix/feature.
[x] Grammar rules have not been renamed unless absolutely necessary.
[x] The conflicts section hasn't grown too much.
[x] The parser size hasn't grown too much (check the value of STATE_COUNT in src/parser.c).
The precedence for
type_query
needs to be higher than that of_type_query_subscript_expression
. Otherwise, the parser will generate incorrect parses, and even fail to parse valid code in some cases.The code
type X1 = typeof Y[keyof typeof Z];
should actually havetypeof Y
grouped together. I verified this in astexplorer.net, and I verified that TypeScript itself does parse this line. Currently, it fails to parse using this tree-sitter grammar. Because of the incorrect precedence, it expects an expression between the brackets instead of a type.I also used AST Explorer to check how TypeScript parses the other tests that changed. In both cases, the updated parse is correct.
Checklist: