@Override public Node getDeclaringBlock() { return fn.getParent(); } }
/** * Gets the parent node of the value for any assignment to a Name. * For example, in the assignment * {@code var x = 3;} * the parent would be the NAME node. */ private static Node getValueParent(Ref ref) { // there are four types of declarations: VARs, LETs, CONSTs, and ASSIGNs Node n = ref.node.getParent(); return (n != null && NodeUtil.isNameDeclaration(n)) ? ref.node : ref.node.getParent(); }
@Override public void keepSubTree(Node original) { if (original.getParent() != null) { original.detach(); } replacements.add(original); }
private boolean isTopLevel(NodeTraversal t, Node n, ScopeType scopeType) { if (scopeType == ScopeType.EXEC_CONTEXT) { return t.getClosestHoistScopeRoot() == currentScript.rootNode; } else { // Must be ScopeType.BLOCK; return n.getParent() == currentScript.rootNode; } }
private boolean shouldReportThis(Node n) { Node parent = n.getParent(); if (assignLhsChild != null) { // Always report a THIS on the left side of an assign. return true; } // Also report a THIS with a property access. return parent != null && NodeUtil.isGet(parent); } }
private boolean isAssignChain(Node child, Node ancestor) { for (Node n = child; n != ancestor; n = n.getParent()) { if (!n.isAssign()) { return false; } } return true; } };
/** * Checks if target is actually the continue target of labeled continue. The * label can be null if it is an unlabeled continue. */ static boolean isContinueTarget( Node target, String label) { return NodeUtil.isLoopStructure(target) && matchLabel(target.getParent(), label); }
protected Token declarationType() { for (Node current = nameNode; current != null; current = current.getParent()) { if (DECLARATION_TYPES.contains(current.getToken())) { return current.getToken(); } } checkState( isImplicit(), "The nameNode for %s must be a descendant of one of: %s", this, DECLARATION_TYPES); return null; }
/** Whether the node is a CATCH container BLOCK. */ static boolean isTryCatchNodeContainer(Node n) { Node parent = n.getParent(); return parent.isTry() && parent.getSecondChild() == n; }
static boolean isCallTarget(Node n) { Node parent = n.getParent(); return (parent.isCall() || parent.isNew()) && parent.getFirstChild() == n; }
private void replaceWithNodes(NodeTraversal t, Node n, Iterable<Node> replacements) { Node insertPoint = n; for (Node c : replacements) { Node detached = c.detach(); n.getParent().addChildAfter(detached, insertPoint); insertPoint = detached; } n.detach(); t.reportCodeChange(); }
private static void reportIfNaN(NodeTraversal t, Node n) { if (NodeUtil.isNaN(n)) { t.getCompiler().report( t.makeError(n.getParent(), SUSPICIOUS_COMPARISON_WITH_NAN)); } }
private boolean isLValue(Node n) { Node parent = n.getParent(); return (parent.isInc() || parent.isDec() || (NodeUtil.isAssignmentOp(parent) && parent.getFirstChild() == n)); }
void updateModuleBody(Node moduleBody) { checkArgument( moduleBody.isModuleBody() && moduleBody.getParent().getBooleanProp(Node.GOOG_MODULE), moduleBody); moduleBody.setToken(Token.BLOCK); NodeUtil.tryMergeBlock(moduleBody, true); updateEndModule(); popScript(); }
/** 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; } }