mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Improve deprecated suggestion node position (#39702)
* Improve deprecated suggestion node position * fix typo * Simplify code * merge helper function
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user