mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Improve deprecated suggestion node position (#39702)
* Improve deprecated suggestion node position * fix typo * Simplify code * merge helper function
This commit is contained in:
parent
a80f60c6d6
commit
57e2fe0462
@ -24711,7 +24711,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);
|
||||
}
|
||||
}
|
||||
@ -27595,9 +27595,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 {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -30992,8 +31017,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));
|
||||
|
||||
@ -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 */
|
||||
@ -37,8 +37,8 @@
|
||||
//// constructor() {
|
||||
//// }
|
||||
//// }
|
||||
//// var c = [|new C()|]
|
||||
//// [|c.m()|]
|
||||
//// var c = new [|C|]()
|
||||
//// c.[|m|]()
|
||||
//// c.[|m|]
|
||||
//// new [|D|]()
|
||||
//// C
|
||||
@ -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|];
|
||||
@ -79,7 +79,6 @@
|
||||
|
||||
goTo.file('a.ts')
|
||||
const ranges = test.ranges();
|
||||
|
||||
verify.getSuggestionDiagnostics([
|
||||
{
|
||||
"code": 6385,
|
||||
|
||||
@ -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 {
|
||||
@ -27,7 +27,7 @@
|
||||
//// (a: number): void
|
||||
//// }
|
||||
//// declare const f: Foo;
|
||||
//// [|f()|];
|
||||
//// [|f|]();
|
||||
//// f(1);
|
||||
|
||||
//// interface T {
|
||||
@ -37,7 +37,7 @@
|
||||
//// }
|
||||
//// declare const t: T;
|
||||
//// t.createElement();
|
||||
//// [|t.createElement('xmp')|];
|
||||
//// t.[|createElement|]('xmp');
|
||||
|
||||
//// declare class C {
|
||||
//// /** @deprecated */
|
||||
@ -45,7 +45,7 @@
|
||||
//// constructor(v: string)
|
||||
//// }
|
||||
//// C;
|
||||
//// const c = [|new C()|];
|
||||
//// const c = new [|C|]();
|
||||
|
||||
//// interface Ca {
|
||||
//// /** @deprecated */
|
||||
@ -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([
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
//// declare function b(): void
|
||||
//// declare const tb: b;
|
||||
//// [|b|]
|
||||
//// [|b()|];
|
||||
//// [|b|]();
|
||||
|
||||
//// interface c { }
|
||||
//// /** @deprecated */
|
||||
@ -21,7 +21,7 @@
|
||||
//// declare function c(a: number): void
|
||||
//// declare const tc: c;
|
||||
//// c;
|
||||
//// [|c()|];
|
||||
//// [|c|]();
|
||||
//// c(1);
|
||||
|
||||
//// /** @deprecated */
|
||||
@ -38,8 +38,8 @@
|
||||
//// /** @deprecated */
|
||||
//// declare function e(a: number): void
|
||||
//// [|e|];
|
||||
//// [|e()|];
|
||||
//// [|e(1)|];
|
||||
//// [|e|]();
|
||||
//// [|e|](1);
|
||||
|
||||
//// /** @deprecated */
|
||||
//// interface f { a: number }
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user