mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 12:53:27 -05:00
Improve deprecated suggestion node position
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user