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 authored and GitHub committed 2020-03-30 14:45:32 -07:00
1 parent 0e15b9f245
commit 3433434142
6 files changed
+268 -5

No files matched your search

+25 -2
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;
}
}
}
}