class FunctionInjector {
/**
* @param fnName The name of this function. This either the name of the
* variable to which the function is assigned or the name from the FUNCTION
* node.
* @param fnNode The FUNCTION node of the function to inspect.
* @return Whether the function node meets the minimum requirements for
* inlining.
*/
boolean doesFunctionMeetMinimumRequirements(
String fnName, Node fnNode) {
Node block = NodeUtil.getFunctionBody(fnNode);
// Don't inline recursive functions, nor functions that contain
// 'this', 'arguments' references.
if (NodeUtil.isNameReferenced(block, fnName)) {
return false;
}
String fnRecursionName = fnNode.getFirstChild().getString();
if (fnRecursionName != null
&& !fnRecursionName.isEmpty()
&& !fnRecursionName.equals(fnName)
&& NodeUtil.isNameReferenced(block, fnRecursionName)) {
return false;
}
// nor functions that contain 'arguments' references.
if (NodeUtil.isNameReferenced(block, "arguments")) {
return false;
}
return true;
}
}