in legacy/javascript/src/refactor.js [135:161]
checkAndAddRedundantFunction(func, name, redundantFunctions) {
if (func.body === null || func.body.body == null) {
return false;
}
const returnIndex = func.body.body.length - 1;
if (returnIndex < 0)
// If returnIndex == -1 when function body is empty
return false;
else {
var returnNode = func.body.body[returnIndex];
if (
returnNode.type === 'ReturnStatement' &&
returnNode.argument !== null &&
this.isPiranhaLiteral(returnNode.argument) &&
typeof returnNode.argument.value === 'boolean'
) {
redundantFunctions[name] = returnNode.argument.value;
}
// TODO introduce a warning here since the assumption of return statement being at the end is violated
return true;
}
}