class NameAnalyzer.RefNode {
void remove();
}
class NameAnalyzer.JsNameRefNode {
public void remove() {
// Setters have VAR, FUNCTION, or ASSIGN parent nodes. CALL parent
// nodes are global refs, and are handled later in this function.
Node containingNode = parent.getParent();
switch (parent.getType()) {
case Token.VAR:
Preconditions.checkState(parent.hasOneChild());
replaceWithRhs(containingNode, parent);
break;
case Token.FUNCTION:
replaceWithRhs(containingNode, parent);
break;
case Token.ASSIGN:
if (NodeUtil.isExpressionNode(containingNode)) {
replaceWithRhs(containingNode.getParent(), containingNode);
} else {
replaceWithRhs(containingNode, parent);
}
break;
}
}
}
class NameAnalyzer.PrototypeSetNode {
@Override public void remove() {
Node gramps = parent.getParent();
if (NodeUtil.isExpressionNode(gramps)) {
// name.prototype.foo = function() { ... };
changeProxy.removeChild(gramps.getParent(), gramps);
} else {
// ... name.prototype.foo = function() { ... } ...
changeProxy.replaceWith(gramps, parent,
parent.getLastChild().cloneTree());
}
}
}
class NameAnalyzer.ClassDefiningFunctionNode {
public void remove() {
Preconditions.checkState(node.getType() == Token.CALL);
if (NodeUtil.isExpressionNode(parent)) {
changeProxy.removeChild(gramps, parent);
} else {
changeProxy.replaceWith(
parent, node, new Node(Token.VOID, Node.newNumber(0)));
}
}
}
class NameAnalyzer.InstanceOfCheckNode {
public void remove() {
changeProxy.replaceWith(gramps, parent, new Node(Token.FALSE));
}
}
|