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
13 changes: 12 additions & 1 deletion tsc/internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -8539,7 +8539,18 @@ func (c *Checker) checkDeprecatedSignature(sig *Signature, node *ast.Node) {
}
if sig.declaration != nil && c.IsDeprecatedDeclaration(sig.declaration) {
suggestionNode := c.getDeprecatedSuggestionNode(node)
name := tryGetPropertyAccessOrIdentifierToString(ast.GetInvokedExpression(node))
invokedExpression := ast.SkipParentheses(ast.GetInvokedExpression(node))
name := tryGetPropertyAccessOrIdentifierToString(invokedExpression)
if name == "" {
switch {
case ast.IsPropertyAccessExpression(invokedExpression):
name = invokedExpression.Name().Text()
case ast.IsElementAccessExpression(invokedExpression):
if memberName := ast.GetElementOrPropertyAccessName(invokedExpression); memberName != nil {
name = memberName.Text()
}
}
}
c.addDeprecatedSuggestionWithSignature(suggestionNode, sig.declaration, name, c.signatureToString(sig))
}
}
Expand Down
74 changes: 74 additions & 0 deletions tsc/internal/fourslash/tests/deprecatedSignatureMemberName_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package fourslash_test

import (
"testing"

"github.com/microsoft/TypeScript/tsc/internal/fourslash"
"github.com/microsoft/TypeScript/tsc/internal/lsp/lsproto"
"github.com/microsoft/TypeScript/tsc/internal/testutil"
)

func TestDeprecatedSignatureMemberName(t *testing.T) {
t.Parallel()
defer testutil.RecoverAndFail(t, "Panic on fourslash test")
const content = `// @filename: /a.ts
interface Schema {
/** @deprecated */
passthrough(): Schema;
}
declare function object(): Schema;
object().[|passthrough|]();
object()[[|"passthrough"|]]();
(object().[|passthrough|])();
class C {
/** @deprecated */
m() {}
/** @deprecated */
#p() {}
n() {
this.[|m|]();
this.[|#p|]();
}
}`
f, done := fourslash.NewFourslash(t, nil /*capabilities*/, content)
defer done()
f.VerifySuggestionDiagnostics(t, []*lsproto.Diagnostic{
{
Code: &lsproto.IntegerOrString{Integer: new(int32(6387))},
Message: lsproto.StringOrMarkupContent{String: new("The signature '(): Schema' of 'passthrough' is deprecated.")},
Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated},
Range: f.Ranges()[0].LSRange,
},
{
Code: &lsproto.IntegerOrString{Integer: new(int32(6387))},
Message: lsproto.StringOrMarkupContent{String: new("The signature '(): Schema' of 'passthrough' is deprecated.")},
Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated},
Range: f.Ranges()[1].LSRange,
},
// A parenthesized callee also reports the deprecated property itself; that suggestion is unchanged.
{
Code: &lsproto.IntegerOrString{Integer: new(int32(6385))},
Message: lsproto.StringOrMarkupContent{String: new("'passthrough' is deprecated.")},
Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated},
Range: f.Ranges()[2].LSRange,
},
{
Code: &lsproto.IntegerOrString{Integer: new(int32(6387))},
Message: lsproto.StringOrMarkupContent{String: new("The signature '(): Schema' of 'passthrough' is deprecated.")},
Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated},
Range: f.Ranges()[2].LSRange,
},
{
Code: &lsproto.IntegerOrString{Integer: new(int32(6387))},
Message: lsproto.StringOrMarkupContent{String: new("The signature '(): void' of 'm' is deprecated.")},
Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated},
Range: f.Ranges()[3].LSRange,
},
{
Code: &lsproto.IntegerOrString{Integer: new(int32(6387))},
Message: lsproto.StringOrMarkupContent{String: new("The signature '(): void' of '#p' is deprecated.")},
Tags: &[]lsproto.DiagnosticTag{lsproto.DiagnosticTagDeprecated},
Range: f.Ranges()[4].LSRange,
},
})
}