Code with Finding: |
class NameReferenceGraphConstruction.Traversal {
@Override
public void enterScope(NodeTraversal t) {
Node root = t.getScopeRoot();
Node parent = root.getParent();
// When we are not in a {{GLOBAL MAIN}}, we need to determine what the
// current function is.
if (!t.inGlobalScope()) {
// TODO(user): A global function foo() is treated as the same
// function as a inner function named foo(). We should use some clever
// naming scheme to avoid this lost of precision.
String name = NodeUtil.getFunctionName(root);
if (name == null) {
// When the name is null, we have a function that is presumably not
// reference-able again and should not be modeled in the name graph.
// A common example would be (function() { ... })();
pushContainingFunction(graph.UNKNOWN);
return;
}
// If we've done type analysis, then we should be able to get the
// correct JSFunctionType for the containing function. If not,
// we're probably going to get an unknown type here.
JSType type = getType(root);
Node gParent = parent.getParent();
Node ggParent = gParent.getParent();
if (NodeUtil.isAssign(parent) &&
NodeUtil.isPrototypeProperty(parent.getFirstChild())) {
pushContainingFunction(
recordPrototypePropDefinition(t, parent.getFirstChild(), type,
parent, gParent, ggParent));
} else {
pushContainingFunction(
recordStaticNameDefinition(
t, name, type, root, parent, gParent, root.getLastChild()));
}
}
}
}
|