Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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, B, C> {
a!: A; b!: B; c!: C;
}
class SomeDerived</*1*/T> extends SomeBase<number, string, T> {
constructor() {
/*2*/super<number, string, /*3*/T> ` + "`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")
}
12 changes: 10 additions & 2 deletions tsc/internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>` 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,6 @@ class SomeDerived<T> extends SomeBase<number, string, T> {
constructor() {
super<number, string, T> `hello world`;
>super : Symbol(SomeBase, Decl(taggedTemplatesWithTypeArguments2.ts, 27, 10))
>T : Symbol(T, Decl(taggedTemplatesWithTypeArguments2.ts, 33, 18))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SomeDerived<T> extends SomeBase<number, string, T> {
constructor() {
super<number, string, T> `hello world`;
>super<number, string, T> `hello world` : any
>super<number, string, T> : any
>super : any
>super : SomeBase<number, string, T>
> : any
>`hello world` : "hello world"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// === documentHighlights ===
// === /main.ts ===
// class SomeBase<A, B, C> {
// a!: A; b!: B; c!: C;
// }
// class SomeDerived</*HIGHLIGHTS*/[|T|]> extends SomeBase<number, string, [|T|]> {
// constructor() {
// super<number, string, [|T|]> `hello world`;
// }
// }



// === documentHighlights ===
// === /main.ts ===
// class SomeBase<A, B, C> {
// a!: A; b!: B; c!: C;
// }
// class SomeDerived<T> extends SomeBase<number, string, T> {
// constructor() {
// /*HIGHLIGHTS*/[|super|]<number, string, T> `hello world`;
// }
// }



// === documentHighlights ===
// === /main.ts ===
// class SomeBase<A, B, C> {
// a!: A; b!: B; c!: C;
// }
// class SomeDerived<[|T|]> extends SomeBase<number, string, [|T|]> {
// constructor() {
// super<number, string, /*HIGHLIGHTS*/[|T|]> `hello world`;
// }
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// === findAllReferences ===
// === /main.ts ===
// class SomeBase<A, B, C> {
// a!: A; b!: B; c!: C;
// }
// class SomeDerived</*FIND ALL REFS*/[|T|]> extends SomeBase<number, string, [|T|]> {
// constructor() {
// super<number, string, [|T|]> `hello world`;
// }
// }



// === findAllReferences ===
// === /main.ts ===
// class SomeBase<A, B, C> {
// a!: A; b!: B; c!: C;
// }
// class SomeDerived<T> extends SomeBase<number, string, T> {
// constructor() {
// /*FIND ALL REFS*/[|super|]<number, string, T> `hello world`;
// }
// }



// === findAllReferences ===
// === /main.ts ===
// class SomeBase<A, B, C> {
// a!: A; b!: B; c!: C;
// }
// class SomeDerived<[|T|]> extends SomeBase<number, string, [|T|]> {
// constructor() {
// super<number, string, /*FIND ALL REFS*/[|T|]> `hello world`;
// }
// }
Loading