Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve deprecated suggestion node position #39702

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/compiler/checker.ts
Expand Up @@ -24652,7 +24652,7 @@ namespace ts {
if (isNodeOpeningLikeElement) {
const jsxOpeningLikeNode = node as JsxOpeningLikeElement;
const sig = getResolvedSignature(jsxOpeningLikeNode);
checkDeprecatedSignature(sig, node);
checkDeprecatedSignature(sig, <JsxOpeningLikeElement>node);
checkJsxReturnAssignableToAppropriateBound(getJsxReferenceKind(jsxOpeningLikeNode), getReturnTypeOfSignature(sig), jsxOpeningLikeNode);
}
}
Expand Down Expand Up @@ -27534,9 +27534,34 @@ namespace ts {
return returnType;
}

function checkDeprecatedSignature(signature: Signature, node: Node) {
function checkDeprecatedSignature(signature: Signature, node: CallLikeExpression) {
if (signature.declaration && signature.declaration.flags & NodeFlags.Deprecated) {
errorOrSuggestion(/*isError*/ false, node, Diagnostics._0_is_deprecated, signatureToString(signature));
const suggestionNode = getDeprecatedSuggestionNode(node);
errorOrSuggestion(/*isError*/ false, suggestionNode, Diagnostics._0_is_deprecated, signatureToString(signature));
}
}

function getDeprecatedSuggestionNode(node: Node): Node {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: getSignautreSuggestionNode -> getSignatureSuggestionNode

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. Yes... sure.

node = skipParentheses(node);
switch (node.kind) {
case SyntaxKind.CallExpression:
case SyntaxKind.Decorator:
case SyntaxKind.NewExpression:
return getDeprecatedSuggestionNode((<Decorator | CallExpression | NewExpression>node).expression);
case SyntaxKind.TaggedTemplateExpression:
return getDeprecatedSuggestionNode((<TaggedTemplateExpression>node).tag);
case SyntaxKind.JsxOpeningElement:
case SyntaxKind.JsxSelfClosingElement:
return getDeprecatedSuggestionNode((<JsxOpeningLikeElement>node).tagName);
case SyntaxKind.ElementAccessExpression:
return (<ElementAccessExpression>node).argumentExpression;
case SyntaxKind.PropertyAccessExpression:
return (<PropertyAccessExpression>node).name;
case SyntaxKind.TypeReference:
const typeReference = <TypeReferenceNode>node;
return isQualifiedName(typeReference.typeName) ? typeReference.typeName.right : typeReference;
default:
return node;
}
}

Expand Down Expand Up @@ -30927,8 +30952,7 @@ namespace ts {
const symbol = getNodeLinks(node).resolvedSymbol;
if (symbol) {
if (some(symbol.declarations, d => isTypeDeclaration(d) && !!(d.flags & NodeFlags.Deprecated))) {
const diagLocation = isTypeReferenceNode(node) && isQualifiedName(node.typeName) ? node.typeName.right : node;
errorOrSuggestion(/* isError */ false, diagLocation, Diagnostics._0_is_deprecated, symbol.escapedName as string);
errorOrSuggestion(/* isError */ false, getDeprecatedSuggestionNode(node), Diagnostics._0_is_deprecated, symbol.escapedName as string);
}
if (type.flags & TypeFlags.Enum && symbol.flags & SymbolFlags.EnumMember) {
error(node, Diagnostics.Enum_type_0_has_members_with_initializers_that_are_not_literals, typeToString(type));
Expand Down
31 changes: 15 additions & 16 deletions tests/cases/fourslash/jsdocDeprecated_suggestion1.ts
Expand Up @@ -5,18 +5,18 @@
//// export namespace foo {
//// /** @deprecated */
//// export function faff () { }
//// [|faff()|]
//// [|faff|]()
//// }
//// const [|a|] = [|foo.faff()|]
//// const [|a|] = foo.[|faff|]()
//// foo[[|"faff"|]]
//// const { [|faff|] } = foo
//// [|faff()|]
//// [|faff|]()
//// /** @deprecated */
//// export function bar () {
//// [|foo?.faff()|]
//// foo?.[|faff|]()
//// }
//// [|foo?.["faff"]?.()|]
//// [|bar()|];
//// foo?.[[|"faff"|]]?.()
//// [|bar|]();
//// /** @deprecated */
//// export interface Foo {
//// /** @deprecated */
Expand All @@ -37,8 +37,8 @@
//// constructor() {
//// }
//// }
//// var c = [|new C()|]
//// [|c.m()|]
//// var c = new [|C|]()
//// c.[|m|]()
//// c.[|m|]
//// new [|D|]()
//// C
Expand All @@ -51,26 +51,26 @@
//// return <div></div>
//// }
//// [|Compi|];
//// [|<Compi />|];
//// [|<Compi {...props}>|]<div></div></[|Compi|]>;
//// <[|Compi|] />;
//// <[|Compi|] {...props}><div></div></[|Compi|]>;
//// /** @deprecated */
//// function ttf(_x: unknown) {
//// }
//// [|ttf``|]
//// [|ttf|]``
//// [|ttf|]
//// /** @deprecated */
//// function dec(_c: unknown) { }
//// [|dec|]
//// [|@dec|]
//// @[|dec|]
//// class K { }

// @Filename: b.ts
//// // imports and aliases
//// import * as f from './a';
//// import { [|bar|], [|QW|] } from './a';
//// [|f.bar()|];
//// [|f.foo.faff()|];
//// [|bar()|];
//// f.[|bar|]();
//// f.foo.[|faff|]();
//// [|bar|]();
//// type Z = [|QW|];
//// type A = f.[|Foo|];
//// type B = f.[|QW|];
Expand All @@ -79,7 +79,6 @@

goTo.file('a.ts')
const ranges = test.ranges();

verify.getSuggestionDiagnostics([
{
"code": 6385,
Expand Down
16 changes: 8 additions & 8 deletions tests/cases/fourslash/jsdocDeprecated_suggestion2.ts
Expand Up @@ -5,20 +5,20 @@
//// /** @deprecated */
//// declare function foo(): undefined;
//// declare function foo (a?: string): number | undefined;
//// [|foo()|];
//// [|foo|]();
//// foo('');
//// foo;

//// /** @deprecated */
//// declare function bar(): number;
//// [|bar()|];
//// [|bar|]();
//// [|bar|];

//// /** @deprecated */
//// declare function baz(): number;
//// /** @deprecated */
//// declare function baz(): number | undefined;
//// [|baz()|];
//// [|baz|]();
//// [|baz|];

//// interface Foo {
Expand All @@ -27,7 +27,7 @@
//// (a: number): void
//// }
//// declare const f: Foo;
//// [|f()|];
//// [|f|]();
//// f(1);

//// interface T {
Expand All @@ -37,15 +37,15 @@
//// }
//// declare const t: T;
//// t.createElement();
//// [|t.createElement('xmp')|];
//// t.[|createElement|]('xmp');

//// declare class C {
//// /** @deprecated */
//// constructor ();
//// constructor(v: string)
//// }
//// C;
//// const c = [|new C()|];
//// const c = new [|C|]();

//// interface Ca {
//// /** @deprecated */
Expand All @@ -61,10 +61,10 @@
//// declare const cb: Cb;
//// ca;
//// cb;
//// [|ca()|];
//// [|ca|]();
//// cb();
//// new ca();
//// [|new cb()|];
//// new [|cb|]();

const ranges = test.ranges();
verify.getSuggestionDiagnostics([
Expand Down
8 changes: 4 additions & 4 deletions tests/cases/fourslash/jsdocDeprecated_suggestion3.ts
Expand Up @@ -13,15 +13,15 @@
//// declare function b(): void
//// declare const tb: b;
//// [|b|]
//// [|b()|];
//// [|b|]();

//// interface c { }
//// /** @deprecated */
//// declare function c(): void
//// declare function c(a: number): void
//// declare const tc: c;
//// c;
//// [|c()|];
//// [|c|]();
//// c(1);

//// /** @deprecated */
Expand All @@ -38,8 +38,8 @@
//// /** @deprecated */
//// declare function e(a: number): void
//// [|e|];
//// [|e()|];
//// [|e(1)|];
//// [|e|]();
//// [|e|](1);

//// /** @deprecated */
//// interface f { a: number }
Expand Down