Improve deprecated suggestion node position (#39702)

* Improve deprecated suggestion node position

* fix typo

* Simplify code

* merge helper function
This commit is contained in:
Wenlu Wang
2020-08-11 08:37:11 +08:00
committed by GitHub
parent a80f60c6d6
commit 57e2fe0462
4 changed files with 56 additions and 33 deletions

View File

@@ -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));