@Override public boolean apply(Node node) { return node.isContinue() && !node.hasChildren(); } };
private void visitBlock(Node blockNode) { checkArgument(blockNode.isBlock()); // We don't do flow analysis yet so we're going to assume everything written up to this // block is read. if (blockNode.hasChildren()) { markAllPropsRead(); } }
public static Node propdef(Node string, Node value) { checkState(string.isStringKey()); checkState(!string.hasChildren()); checkState(mayBeExpression(value)); string.addChildToFront(value); return string; }
/** * Permanently delete all the children of the given node, including reporting changes. */ public static void deleteChildren(Node n, AbstractCompiler compiler) { while (n.hasChildren()) { deleteNode(n.getFirstChild(), compiler); } }
/** * @return Whether BLOCK (from a TRY node) contains a CATCH. * @see NodeUtil#getCatchBlock */ static boolean hasCatchHandler(Node n) { checkArgument(n.isBlock()); return n.hasChildren() && n.getFirstChild().isCatch(); }
/** * @return Whether any LiveRangeChecker would be interested in the node. */ public static boolean shouldVisit(Node n) { return (n.isName() || (n.hasChildren() && n.getFirstChild().isName())); }
private void removeIfUnnamedBreak(Node maybeBreak) { if (maybeBreak != null && maybeBreak.isBreak() && !maybeBreak.hasChildren()) { reportChangeToEnclosingScope(maybeBreak); maybeBreak.detach(); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (!foundNonEmptyReturn) { if (n.isReturn() && n.hasChildren() && !n.getFirstChild().matchesQualifiedName("undefined")) { foundNonEmptyReturn = true; } } } };
static MeasuredNode[] normalizeChildren(Node node, MeasuredNode[] children) { if (children != null || !node.hasChildren()) { return children; } else { MeasuredNode[] measuredChildren = new MeasuredNode[node.getChildCount()]; int child = 0; for (Node c : node.children()) { measuredChildren[child++] = forNode(c); } return measuredChildren; } }
public static Node declaration(Node lhs, Node value, Token type) { if (lhs.isName()) { checkState(!lhs.hasChildren()); } else { checkState(lhs.isArrayPattern() || lhs.isObjectPattern()); lhs = new Node(Token.DESTRUCTURING_LHS, lhs); } Preconditions.checkState(mayBeExpression(value), "%s can't be an expression", value); lhs.addChildToBack(value); return new Node(type, lhs); }
static boolean isExceptionPossible(Node n) { // TODO(johnlenz): maybe use ControlFlowAnalysis.mayThrowException? checkState(n.isReturn() || n.isThrow(), n); return n.isThrow() || (n.hasChildren() && !NodeUtil.isLiteralValue(n.getLastChild(), true)); }
private static boolean isAlwaysInlinable(Node fn) { checkArgument(fn.isFunction()); Node body = NodeUtil.getFunctionBody(fn); return (!body.hasChildren()) || (body.hasOneChild() && body.getFirstChild().isReturn()); }
public static boolean hasReturnDeclaredNullable(Node n) { return n.isBlock() && n.hasChildren() && isReturnTypeNullable(n.getParent()) && !hasSingleThrow(n); }
private void validateReturn(Node n) { validateNodeType(Token.RETURN, n); validateMaximumChildCount(n, 1); if (n.hasChildren()) { validateExpression(n.getFirstChild()); } }
private void validateBreak(Node n) { validateNodeType(Token.BREAK, n); validateMaximumChildCount(n, 1); if (n.hasChildren()) { validateLabelName(n.getFirstChild()); } }
/** * @param fnNode The function to inspect. * @return Whether the function has parameters, var/const/let, class, or function declarations. */ private static boolean hasLocalNames(Node fnNode) { Node block = NodeUtil.getFunctionBody(fnNode); return NodeUtil.getFunctionParameters(fnNode).hasChildren() || NodeUtil.has( block, new NodeUtil.MatchDeclaration(), new NodeUtil.MatchShallowStatement()); }
/** * @return Whether the node is a goog.module file's SCRIPT node. */ static boolean isGoogModuleFile(Node n) { return n.isScript() && n.hasChildren() && n.getFirstChild().isModuleBody() && isGoogModuleCall(n.getFirstFirstChild()); }
private void validateYield(Node n) { validateFeature(Feature.GENERATORS, n); validateNodeType(Token.YIELD, n); validateChildCountIn(n, 0, 1); if (n.hasChildren()) { validateExpression(n.getFirstChild()); } }
/** Remove values from enums */ private void simplifyEnumValues(AbstractCompiler compiler) { if (getRhs().isObjectLit() && getRhs().hasChildren()) { for (Node key : getRhs().children()) { removeStringKeyValue(key); } compiler.reportChangeToEnclosingScope(getRhs()); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isReturn() && n.hasChildren()) { Node retVal = n.getFirstChild(); n.removeChild(retVal); parent.replaceChild(n, IR.exprResult( IR.assign( IR.getprop(IR.name("module"), IR.string("exports")), retVal)) .useSourceInfoFromForTree(n)); } } }