Fixed issue where missing method call went unreported if the call target symbol did no have an id assigned or if the called property was used inside the if block on a different target. (#35862)

This commit is contained in:
Titian Cernicova-Dragomir
2020-03-31 00:45:32 +03:00
committed by GitHub
parent 0e15b9f245
commit 3433434142
6 changed files with 268 additions and 5 deletions

View File

@@ -31620,8 +31620,31 @@ namespace ts {
const functionIsUsedInBody = forEachChild(body, function check(childNode): boolean | undefined {
if (isIdentifier(childNode)) {
const childSymbol = getSymbolAtLocation(childNode);
if (childSymbol && childSymbol.id === testedFunctionSymbol.id) {
return true;
if (childSymbol && childSymbol === testedFunctionSymbol) {
// If the test was a simple identifier, the above check is sufficient
if (isIdentifier(ifStatement.expression)) {
return true;
}
// Otherwise we need to ensure the symbol is called on the same target
let testedExpression = testedNode.parent;
let childExpression = childNode.parent;
while (testedExpression && childExpression) {
if (isIdentifier(testedExpression) && isIdentifier(childExpression)) {
return getSymbolAtLocation(testedExpression) === getSymbolAtLocation(childExpression);
}
if (isPropertyAccessExpression(testedExpression) && isPropertyAccessExpression(childExpression)) {
if (getSymbolAtLocation(testedExpression.name) !== getSymbolAtLocation(childExpression.name)) {
return false;
}
childExpression = childExpression.expression;
testedExpression = testedExpression.expression;
}
else {
return false;
}
}
}
}