fix(41295): handle deprecated callbacks (#41310)

This commit is contained in:
Oleksandr T 2020-12-05 02:37:25 +02:00 committed by GitHub
parent a5c3cb4194
commit f0340005a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 9 deletions

View File

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

View 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]
},
]);

View 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]
},
]);