Code with Finding: |
class NameReferenceGraphConstruction.Traversal {
@SuppressWarnings("fallthrough")
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
switch (n.getType()) {
case Token.NAME:
case Token.GETPROP:
if (NodeUtil.isGetProp(parent) ||
parent.getType() == Token.REF_SPECIAL) {
// We will resolve this when we visit parent later in the traversal.
return;
} else if (NodeUtil.isFunction(parent)) {
// Function declarations have been taken care of in enterScope();
return;
} else if (NodeUtil.isAssign(parent)) {
// Handled below.
return;
}
if (isLocalNameReference(t, n)) {
// Ignore all local variable references unless is creates a closure.
return;
}
if (isPrototypeNameReference(n)) {
recordPrototypePropUse(t, n, parent);
} else if (isStaticNameReference(n, t.getScope())) {
recordStaticNameUse(t, n, parent);
} else {
recordUnknownUse(t, n, parent);
}
break;
case Token.ASSIGN:
Node lhs = n.getFirstChild();
Node rhs = n.getLastChild();
if (NodeUtil.isFunction(rhs)) {
// These are recorded when entering the scope.
return;
}
if (NodeUtil.isName(lhs) ||
NodeUtil.isGetProp(lhs) ||
NodeUtil.isGetProp(rhs)) {
if (NodeUtil.isPrototypeProperty(lhs)) {
Name name = recordPrototypePropDefinition(
t, lhs, getType(rhs), n, parent, parent.getParent());
name.setAliased(true);
}
}
maybeAliasNamesOnAssign(lhs, rhs);
break;
case Token.VAR:
// var foo = bar;
Node varName = n.getFirstChild();
Node assignedValue = varName.getFirstChild();
if (assignedValue == null) {
return;
}
maybeAliasNamesOnAssign(varName, assignedValue);
break;
case Token.CALL:
Node param = n.getFirstChild();
// We need to alias every name that is passed as a parameter because
// they have different names inside the function's scope.
while ((param = param.getNext()) != null) {
if (NodeUtil.isName(param) || NodeUtil.isGetProp(param)) {
safeAlias(param);
}
}
maybeRecordExport(n);
break;
}
}
}
|