Improve deprecated suggestion node position

This commit is contained in:
kingwl
2020-07-22 19:07:12 +08:00
parent 56865f722d
commit cd5dde5d79
4 changed files with 63 additions and 33 deletions

View File

@@ -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);
}
}
@@ -27534,9 +27534,41 @@ 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 = getSignautreSuggestionNode(node);
errorOrSuggestion(/*isError*/ false, suggestionNode, Diagnostics._0_is_deprecated, signatureToString(signature));
}
}
function getSignautreSuggestionNode(node: CallLikeExpression): Node {
switch (node.kind) {
case SyntaxKind.CallExpression:
case SyntaxKind.Decorator:
case SyntaxKind.NewExpression:
return getDeprecatedSuggestionNode(node.expression);
case SyntaxKind.TaggedTemplateExpression:
return getDeprecatedSuggestionNode(node.tag);
case SyntaxKind.JsxOpeningElement:
case SyntaxKind.JsxSelfClosingElement:
return node.tagName;
default:
return node;
}
}
function getDeprecatedSuggestionNode(node: Node): Node {
node = skipParentheses(node);
switch (node.kind) {
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;
}
}
@@ -30927,8 +30959,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));