private FlowScope traverseChildren(Node n, FlowScope scope) { for (Node el = n.getFirstChild(); el != null; el = el.getNext()) { scope = traverse(el, scope); } return scope; }
/** Removes any keys after the given key, and adds them in order to a new object pattern */ private static Node createNewObjectPatternFromSuccessiveKeys(Node stringKey) { Node newPattern = stringKey.getParent().cloneNode(); // copies the JSType for (Node next = stringKey.getNext(); next != null; ) { Node newKey = next; next = newKey.getNext(); newPattern.addChildToBack(newKey.detach()); } return newPattern; } }
private void traverseChildren(Node n) { for (Node child = n.getFirstChild(); child != null; ) { // child could be replaced, in which case our child node // would no longer point to the true next Node next = child.getNext(); traverseBranch(child, n); child = next; } }
@Override public void process(Node externs, Node root) { for (Node script = root.getFirstChild(); script != null; script = script.getNext()) { processFile(script); } }
@Override public void process(Node externs, Node root) { for (Node c = root.getFirstChild(); c != null; c = c.getNext()) { checkState(c.isScript()); hotSwapScript(c, null); } }
private static boolean hasSpreadCallArgument(Node callNode) { checkArgument(callNode.isCall(), callNode); for (Node arg = callNode.getSecondChild(); arg != null; arg = arg.getNext()) { if (arg.isSpread()) { return true; } } return false; }
/** A post-order traversal, calling Visitor.visit for each descendant matching the predicate. */ public static void visitPostOrder( Node node, Visitor visitor, Predicate<Node> traverseChildrenPred) { if (traverseChildrenPred.apply(node)) { for (Node c = node.getFirstChild(); c != null; c = c.getNext()) { visitPostOrder(c, visitor, traverseChildrenPred); } } visitor.visit(node); }
@Override boolean isAssignedValueLocal() { if (NodeUtil.isExpressionResultUsed(assignNode)) { // assigned value may escape or be aliased return false; } else { Node targetNode = assignNode.getFirstChild(); Node valueNode = targetNode.getNext(); return NodeUtil.evaluatesToLocalValue(valueNode) || isLocalDefaultValueAssignment(targetNode, valueNode); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { Node sibling = n.getNext(); if (sibling != null && sibling.isString() && NodeUtil.isGet(parent) && isGlobalThisObject(t, n)) { exportedVariables.add(sibling.getString()); } }
private void validateArrayLit(Node n) { validateNodeType(Token.ARRAYLIT, n); for (Node c = n.getFirstChild(); c != null; c = c.getNext()) { // EMPTY is allowed to represent empty slots. validateOptionalExpression(c); } }
/** @see #findCalledFunctions(Node) */ private static void findCalledFunctions(Node node, Set<String> changed) { checkArgument(changed != null); // For each referenced function, add a new reference if (node.isName() && isCandidateUsage(node)) { changed.add(node.getString()); } for (Node c = node.getFirstChild(); c != null; c = c.getNext()) { findCalledFunctions(c, changed); } }
private void traverse(Node n, Visitor callback) { Node next = null; for (Node c = n.getFirstChild(); c != null; c = next) { next = c.getNext(); // in case the child is remove, grab the next node now traverse(c, callback); } callback.visit(n); }
void tryMinimizeSwitchExits(Node n, Token exitType, @Nullable String labelName) { checkState(n.isSwitch()); // Skipping the switch condition, visit all the children. for (Node c = n.getSecondChild(); c != null; c = c.getNext()) { if (c != n.getLastChild()) { tryMinimizeSwitchCaseExits(c, exitType, labelName); } else { // Last case, the last case block can be optimized more aggressively. tryMinimizeExits(c.getLastChild(), exitType, labelName); } } }
/** * Processes the goog.inherits call. */ private void processInheritsCall(Node n) { if (n.getChildCount() == 3) { Node subClass = n.getSecondChild(); Node superClass = subClass.getNext(); if (subClass.isUnscopedQualifiedName() && superClass.isUnscopedQualifiedName()) { knownClosureSubclasses.add(subClass.getQualifiedName()); } } }
private void traverseObjectPattern(Node objectPattern, Scope scope) { for (Node propertyNode = objectPattern.getFirstChild(); propertyNode != null; propertyNode = propertyNode.getNext()) { if (propertyNode.isComputedProp()) { traverseObjectPatternComputedProperty(propertyNode, scope); } else { traverseObjectPatternStringKey(propertyNode, scope); } } }
private void validateCall(Node n) { validateNodeType(Token.CALL, n); validateMinimumChildCount(n, 1); for (Node c = n.getFirstChild(); c != null; c = c.getNext()) { validateExpression(c); } }
/** Recurses through a tree, marking all function nodes as changed. */ static void markNewScopesChanged(Node node, AbstractCompiler compiler) { if (node.isFunction()) { compiler.reportChangeToChangeScope(node); } for (Node child = node.getFirstChild(); child != null; child = child.getNext()) { markNewScopesChanged(child, compiler); } }
void addObjectPattern(Node n) { add("{"); for (Node child = n.getFirstChild(); child != null; child = child.getNext()) { if (child != n.getFirstChild()) { cc.listSeparator(); } add(child); } add("}"); }