Repository navigation
Fix language service crash on super type arguments before a template literal - #65699
Open
Jake Bailey (jakebailey) wants to merge 2 commits into
Open
Jake Bailey (jakebailey) wants to merge 2 commits into
Jake Bailey (jakebailey) wants to merge 2 commits into
Conversation
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 this commit has no baselines and the test fails with that panic until the parser is fixed.
When `super<T>` is followed by a template literal, the parser dropped the type arguments but still reported the template's missing `super.` name after them. The resulting property access covered the text `<T>` without having a node for it. Anything that visits identifiers by text position, such as find-all-references and document highlights on a type parameter named in that list, then asked astnav.getTokenAtPosition for a token that only the scanner could produce, and it panicked with "did not expect KindPropertyAccessExpression to have KindIdentifier in its trivia". Now the property access ends right after `super`, and the type arguments travel to the tagged template through the existing ExpressionWithTypeArguments absorption in parseMemberExpressionRest. Every node range covers only its children, and the type arguments are real nodes that the checker and the language service can see. The diagnostics and the emit for the test case are unchanged. The type parameter now gets a symbol entry in the baseline because the checker visits the type arguments.
Contributor
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
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 diagnostics and emit of the existing test are unchanged.