From e8d08d08f1d3813e3579be6494614a2aaa6b4929 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:50:11 -0800 Subject: [PATCH 1/2] Add fourslash test for super call with type arguments and template Document highlights and find-all-references on a type parameter whose class calls `super` 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. --- ...TaggedTemplateTypeArgumentsNoCrash_test.go | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tsc/internal/fourslash/tests/superTaggedTemplateTypeArgumentsNoCrash_test.go diff --git a/tsc/internal/fourslash/tests/superTaggedTemplateTypeArgumentsNoCrash_test.go b/tsc/internal/fourslash/tests/superTaggedTemplateTypeArgumentsNoCrash_test.go new file mode 100644 index 0000000000000..91e9bf883a14e --- /dev/null +++ b/tsc/internal/fourslash/tests/superTaggedTemplateTypeArgumentsNoCrash_test.go @@ -0,0 +1,26 @@ +package fourslash_test + +import ( + "testing" + + "github.com/microsoft/TypeScript/tsc/internal/fourslash" + "github.com/microsoft/TypeScript/tsc/internal/testutil" +) + +func TestSuperTaggedTemplateTypeArgumentsNoCrash(t *testing.T) { + t.Parallel() + defer testutil.RecoverAndFail(t, "Panic on fourslash test") + const content = `// @Filename: /main.ts +class SomeBase { + a!: A; b!: B; c!: C; +} +class SomeDerived extends SomeBase { + constructor() { + /*2*/super ` + "`hello world`" + `; + } +}` + f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content) + defer done() + f.VerifyBaselineDocumentHighlights(t, nil /*preferences*/, "1", "2", "3") + f.VerifyBaselineFindAllReferences(t, "1", "2", "3") +} From c66f3fb56ae748df5c3ea734783e7d6323fcbd51 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:06:20 -0800 Subject: [PATCH 2/2] Keep super type arguments inside the tagged template that follows When `super` 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 `` 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. --- tsc/internal/parser/parser.go | 12 +++++-- .../taggedTemplatesWithTypeArguments2.symbols | 1 + .../taggedTemplatesWithTypeArguments2.types | 2 +- ...emplateTypeArgumentsNoCrash.baseline.jsonc | 36 +++++++++++++++++++ ...emplateTypeArgumentsNoCrash.baseline.jsonc | 36 +++++++++++++++++++ 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 tsc/testdata/baselines/reference/fourslash/documentHighlights/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc create mode 100644 tsc/testdata/baselines/reference/fourslash/findAllReferences/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc diff --git a/tsc/internal/parser/parser.go b/tsc/internal/parser/parser.go index c89104f31263f..cc456b05bd0b7 100644 --- a/tsc/internal/parser/parser.go +++ b/tsc/internal/parser/parser.go @@ -5408,9 +5408,17 @@ func (p *Parser) parseSuperExpression() *ast.Expression { typeArguments := p.tryParseTypeArgumentsInExpression() if typeArguments != nil { p.parseErrorAt(startPos, p.nodePos(), diagnostics.X_super_may_not_use_type_arguments) - if !p.isTemplateStartOfTaggedTemplate() { - expression = p.finishNode(p.factory.NewExpressionWithTypeArguments(expression, typeArguments), pos) + if p.isTemplateStartOfTaggedTemplate() { + // `super` followed by a template is a tagged template whose tag is `super.` with a missing name. + // The property access ends at `super`, and the type arguments are wrapped around it so that + // parseMemberExpressionRest moves them onto the tagged template, which keeps them out of the + // range of the property access. + p.parseErrorAtCurrentToken(diagnostics.X_super_must_be_followed_by_an_argument_list_or_member_access) + name := p.finishNodeWithEnd(p.newIdentifier(""), startPos, startPos) + access := p.finishNodeWithEnd(p.factory.NewPropertyAccessExpression(expression, nil /*questionDotToken*/, name, ast.NodeFlagsNone), pos, startPos) + return p.finishNode(p.factory.NewExpressionWithTypeArguments(access, typeArguments), pos) } + expression = p.finishNode(p.factory.NewExpressionWithTypeArguments(expression, typeArguments), pos) } } if p.token == ast.KindOpenParenToken || p.token == ast.KindDotToken || p.token == ast.KindOpenBracketToken { diff --git a/tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.symbols b/tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.symbols index 7a2956a3d888c..05a6197d1c41e 100644 --- a/tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.symbols +++ b/tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.symbols @@ -80,5 +80,6 @@ class SomeDerived extends SomeBase { constructor() { super `hello world`; >super : Symbol(SomeBase, Decl(taggedTemplatesWithTypeArguments2.ts, 27, 10)) +>T : Symbol(T, Decl(taggedTemplatesWithTypeArguments2.ts, 33, 18)) } } diff --git a/tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.types b/tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.types index 1da07ea7a790b..36478cc8b9a1c 100644 --- a/tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.types +++ b/tsc/testdata/baselines/reference/conformance/taggedTemplatesWithTypeArguments2.types @@ -92,7 +92,7 @@ class SomeDerived extends SomeBase { constructor() { super `hello world`; >super `hello world` : any ->super : any +>super : any >super : SomeBase > : any >`hello world` : "hello world" diff --git a/tsc/testdata/baselines/reference/fourslash/documentHighlights/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/documentHighlights/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc new file mode 100644 index 0000000000000..9a0799558b78f --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/documentHighlights/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc @@ -0,0 +1,36 @@ +// === documentHighlights === +// === /main.ts === +// class SomeBase { +// a!: A; b!: B; c!: C; +// } +// class SomeDerived extends SomeBase { +// constructor() { +// super `hello world`; +// } +// } + + + +// === documentHighlights === +// === /main.ts === +// class SomeBase { +// a!: A; b!: B; c!: C; +// } +// class SomeDerived extends SomeBase { +// constructor() { +// /*HIGHLIGHTS*/[|super|] `hello world`; +// } +// } + + + +// === documentHighlights === +// === /main.ts === +// class SomeBase { +// a!: A; b!: B; c!: C; +// } +// class SomeDerived<[|T|]> extends SomeBase { +// constructor() { +// super `hello world`; +// } +// } \ No newline at end of file diff --git a/tsc/testdata/baselines/reference/fourslash/findAllReferences/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc b/tsc/testdata/baselines/reference/fourslash/findAllReferences/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc new file mode 100644 index 0000000000000..ad5c604fdc1f7 --- /dev/null +++ b/tsc/testdata/baselines/reference/fourslash/findAllReferences/superTaggedTemplateTypeArgumentsNoCrash.baseline.jsonc @@ -0,0 +1,36 @@ +// === findAllReferences === +// === /main.ts === +// class SomeBase { +// a!: A; b!: B; c!: C; +// } +// class SomeDerived extends SomeBase { +// constructor() { +// super `hello world`; +// } +// } + + + +// === findAllReferences === +// === /main.ts === +// class SomeBase { +// a!: A; b!: B; c!: C; +// } +// class SomeDerived extends SomeBase { +// constructor() { +// /*FIND ALL REFS*/[|super|] `hello world`; +// } +// } + + + +// === findAllReferences === +// === /main.ts === +// class SomeBase { +// a!: A; b!: B; c!: C; +// } +// class SomeDerived<[|T|]> extends SomeBase { +// constructor() { +// super `hello world`; +// } +// } \ No newline at end of file