mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 20:25:48 -06:00
fix(41295): handle deprecated callbacks (#41310)
This commit is contained in:
parent
a5c3cb4194
commit
f0340005a3
@ -13844,9 +13844,14 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isUncalledFunctionReference(node: Node, symbol: Symbol) {
|
||||
return !(symbol.flags & (SymbolFlags.Function | SymbolFlags.Method))
|
||||
|| !isCallLikeExpression(findAncestor(node, n => !isAccessExpression(n)) || node.parent)
|
||||
&& every(symbol.declarations, d => !isFunctionLike(d) || !!(getCombinedNodeFlags(d) & NodeFlags.Deprecated));
|
||||
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) {
|
||||
const parent = findAncestor(node.parent, n => !isAccessExpression(n)) || node.parent;
|
||||
if (isCallLikeExpression(parent)) {
|
||||
return isCallOrNewExpression(parent) && isIdentifier(node) && hasMatchingArgument(parent, node);
|
||||
}
|
||||
return every(symbol.declarations, d => !isFunctionLike(d) || !!(getCombinedNodeFlags(d) & NodeFlags.Deprecated));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function getPropertyTypeForIndexType(originalObjectType: Type, objectType: Type, indexType: Type, fullIndexType: Type, suppressNoImplicitAnyError: boolean, accessNode: ElementAccessExpression | IndexedAccessTypeNode | PropertyName | BindingName | SyntheticExpression | undefined, accessFlags: AccessFlags, noUncheckedIndexedAccessCandidate?: boolean, reportDeprecated?: boolean) {
|
||||
@ -20953,16 +20958,16 @@ namespace ts {
|
||||
return isMatchingReference(source, target) || containsMatchingReference(source, target);
|
||||
}
|
||||
|
||||
function hasMatchingArgument(callExpression: CallExpression, reference: Node) {
|
||||
if (callExpression.arguments) {
|
||||
for (const argument of callExpression.arguments) {
|
||||
function hasMatchingArgument(expression: CallExpression | NewExpression, reference: Node) {
|
||||
if (expression.arguments) {
|
||||
for (const argument of expression.arguments) {
|
||||
if (isOrContainsMatchingReference(reference, argument)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callExpression.expression.kind === SyntaxKind.PropertyAccessExpression &&
|
||||
isOrContainsMatchingReference(reference, (<PropertyAccessExpression>callExpression.expression).expression)) {
|
||||
if (expression.expression.kind === SyntaxKind.PropertyAccessExpression &&
|
||||
isOrContainsMatchingReference(reference, (<PropertyAccessExpression>expression.expression).expression)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -22875,7 +22880,7 @@ namespace ts {
|
||||
|
||||
const localOrExportSymbol = getExportSymbolOfValueSymbolIfExported(symbol);
|
||||
const sourceSymbol = localOrExportSymbol.flags & SymbolFlags.Alias ? resolveAlias(localOrExportSymbol) : localOrExportSymbol;
|
||||
if (getDeclarationNodeFlagsFromSymbol(sourceSymbol) & NodeFlags.Deprecated && isUncalledFunctionReference(node.parent, sourceSymbol)) {
|
||||
if (getDeclarationNodeFlagsFromSymbol(sourceSymbol) & NodeFlags.Deprecated && isUncalledFunctionReference(node, sourceSymbol)) {
|
||||
errorOrSuggestion(/* isError */ false, node, Diagnostics._0_is_deprecated, node.escapedText as string);
|
||||
}
|
||||
|
||||
|
||||
22
tests/cases/fourslash/jsdocDeprecated_suggestion12.ts
Normal file
22
tests/cases/fourslash/jsdocDeprecated_suggestion12.ts
Normal file
@ -0,0 +1,22 @@
|
||||
///<reference path="fourslash.ts" />
|
||||
|
||||
// @filename: foo.ts
|
||||
/////**
|
||||
//// * @deprecated
|
||||
//// */
|
||||
////function foo() {};
|
||||
////function bar(fn: () => void) {
|
||||
//// fn();
|
||||
////}
|
||||
////bar([|foo|]);
|
||||
|
||||
goTo.file('foo.ts');
|
||||
const ranges = test.ranges();
|
||||
verify.getSuggestionDiagnostics([
|
||||
{
|
||||
"code": 6385,
|
||||
"message": "'foo' is deprecated",
|
||||
"reportsDeprecated": true,
|
||||
"range": ranges[0]
|
||||
},
|
||||
]);
|
||||
25
tests/cases/fourslash/jsdocDeprecated_suggestion13.ts
Normal file
25
tests/cases/fourslash/jsdocDeprecated_suggestion13.ts
Normal file
@ -0,0 +1,25 @@
|
||||
///<reference path="fourslash.ts" />
|
||||
|
||||
// @filename: foo.ts
|
||||
/////**
|
||||
//// * @deprecated
|
||||
//// */
|
||||
////function foo() {};
|
||||
////
|
||||
////class Foo {
|
||||
//// constructor(fn: () => void) {
|
||||
//// fn();
|
||||
//// }
|
||||
////}
|
||||
////new Foo([|foo|]);
|
||||
|
||||
goTo.file('foo.ts');
|
||||
const ranges = test.ranges();
|
||||
verify.getSuggestionDiagnostics([
|
||||
{
|
||||
"code": 6385,
|
||||
"message": "'foo' is deprecated",
|
||||
"reportsDeprecated": true,
|
||||
"range": ranges[0]
|
||||
},
|
||||
]);
|
||||
Loading…
x
Reference in New Issue
Block a user