Repository navigation
Fix language service crash on super type arguments before a template literal - #65699
Jake Bailey (jakebailey) wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the parser recovery change addressing language-service crashes with super tagged templates.
No open issues 🎉
What changed in this PR
Fixes a language-service crash found during fuzzing for #65064 when super<T> precedes a template literal. The parser preserves the type arguments as navigable nodes, allowing document highlights and reference searches to resolve them.
Changes:
- Ends the recovered property access at
superand transfers the type arguments to the tagged template. - Adds a fourslash regression test for document highlights and find-all-references.
- Updates type, symbol, and language-service baselines to reflect the corrected tree and references.
| File | Description |
|---|---|
tsc/testdata/baselines/reference/fourslash/findAllReferences/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc |
Records references from the declaration, super, and type argument. |
tsc/testdata/baselines/reference/fourslash/documentHighlights/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc |
Records highlights at the three regression-test markers. |
tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.types |
Reflects the shortened property-access span. |
tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.symbols |
Records the retained type argument’s symbol. |
tsc/internal/parser/parser.go |
Preserves type arguments during recovery of invalid super tagged templates. |
tsc/internal/fourslash/tests/superTaggedTemplateTypeArgumentsNoCrash_test.go |
Adds regression coverage for both language-service queries. |
Review effort: Balanced
Document highlights and find-all-references on a type parameter whose class calls `super<number, string, T>` followed by a template literal panic in astnav.getTokenAtPosition with "did not expect KindPropertyAccessExpression to have KindIdentifier in its trivia". The panic aborts the request, so the fourslash test has no baselines in this commit and fails with that panic until the parser is fixed. Also add chained member-access and tagged-template cases to taggedTemplatesWithTypeArguments2.ts with main's baselines.
c66f3fb to
1de26bd
Compare
There was a problem hiding this comment.
Okay just for my own understanding, if we have this example
super<T> ``what we had before (in the tree) was effectively
super.(missing identifier) ``and now we have
super.(missing identifier)<T> ``and the problem was that during token collection that type argument list was parsed but not stored in the tree - so if we tried to ask about a position (e.g. when we get to $ in the repro in the following)
class C<T> extends Object {
constructor() {
super$<T> ``
}
}we would find ourselves in prior to that missing identifier in the tree and start scanning tokens in a property access and hit <, T, and then trigger an assertion.
When `super<T>` is followed by a template literal, the parser dropped the type arguments and fell through to recover `super.` with a missing name after them. The resulting PropertyAccessExpression covered the text `<T>` without any child nodes for it. Requests that resolve identifiers by text position, such as find-all-references and document highlights on a type parameter in that list, then asked astnav.getTokenAtPosition for a token that only existed in trivia, panicking with "did not expect KindPropertyAccessExpression to have KindIdentifier in its trivia". End the recovered property access right after `super` and pass it to parseTaggedTemplateRest along with the type arguments, which become the tagged template's own type arguments. parseCallExpressionRest then attaches any trailing member accesses or chained templates to the returned TaggedTemplateExpression as usual. Every node range covers only its children, and the type arguments stay in the AST for the checker and the language service. This form reports only the missing member access, the same error that `super` followed by a template without type arguments gets. The expression is invalid either way, so a second error about the type arguments adds nothing. Emit is unchanged.
1de26bd to
dc4c38a
Compare
This was found by fuzzing language service queries over
taggedTemplatesWithTypeArguments2.tsas part of #65064.When
super<T>is followed by a template literal, the parser drops the type arguments and builds the missingsuper.name after them, so the property access spans<T>without a node for that text. Document highlights or find-all-references on a type parameter named in that list then crash with "did not expect KindPropertyAccessExpression to have KindIdentifier in its trivia". TypeScript 6.0 builds the same tree and fails the same assertion.The parser now ends the property access at
superand keeps the type arguments as nodes on the tagged template, so references inside them resolve. The existing test now reports only TS1034 for these lines, and its emit is unchanged.