Skip to content

Fix language service crash on super type arguments before a template literal - #65699

Open
Jake Bailey (jakebailey) wants to merge 2 commits into
microsoft:mainfrom
jakebailey:fix-super-tagged-template-crash
Open

Jake Bailey (jakebailey) wants to merge 2 commits into
microsoft:mainfrom
jakebailey:fix-super-tagged-template-crash

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

This was found by fuzzing language service queries over taggedTemplatesWithTypeArguments2.ts as part of #65064.

When super<T> is followed by a template literal, the parser drops the type arguments and builds the missing super. 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 super and 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.

Copilot AI balanced review requested due to automatic review settings November 26, 2026 17:22
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 26, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 super and 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.
@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Nov 30, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Nov 30, 2026

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tsc/internal/parser/parser.go Resolved
Comment thread tsc/internal/parser/parser.go Resolved
@jakebailey
Jake Bailey (jakebailey) removed this pull request from the merge queue due to a manual request Nov 30, 2026
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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

4 participants