In `function (): object {...}` object is a predefined type, but
in `function (object: any): object is foo{}` object is now
a regular identifier. The previous grammar was not able
to parse the second example, probably because when the parsers
sees the second ':' for the return type, the contextual lexual
does not know yet if it's a type predicate or predefined type, so
it accepts 'object' as a predefined type and only fail later when
it sees 'is'.
test plan:
I tried in astexplorer.net and the second example is valid typescript
code (sadly).
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.
This is a small performance reduction (0.2% increase in instruction
count for the file in #293) but simplifies the code and ensures we're
splitting with the same logic everywhere.
This saves 16% time, 18% memory and 1% instruction counts from the
sample files in #293. These are large files, treated as textual diffs,
so reducing the storage per-line is significant. Files with structural
diffing, such as sample_files/slow_before.rs, are unchanged.
Fixes#293Closes#297
It's reasonable to assume that a single column won't exceed four
billion, and this is a small speedup (1% instruction count reduction
on the sample file in #293).