@Override public void visit(NodeTraversal t, Node n, Node parent) { switch (n.getType()) { case Token.SCRIPT: updateEndScript(); break; } } }
@Override public boolean apply(Node n) { return n.getType() == type; } });
/** * @return Whether this expression denotes an optional {@code @param}. */ public boolean isOptionalArg() { return root.getType() == Token.EQUALS; }
/** * @return Whether this expression denotes a rest args {@code @param}. */ public boolean isVarArgs() { return root.getType() == Token.ELLIPSIS; }
@Override public boolean apply(Node input) { int nodeType = input.getType(); return nodeType == Token.RETURN || nodeType == Token.BREAK || nodeType == Token.CONTINUE; } };
/** * Asserts that it's OK to define this node's name. * The node should have a source name and be of the specified type. */ void assertDefinitionNode(Node n, int type) { Preconditions.checkState(sourceName != null); Preconditions.checkState(n.getType() == type, n); }
/** * Marks this function or constructor call's side effect flags. * This property is only meaningful for {@link Token#CALL} and * {@link Token#NEW} nodes. */ public void setSideEffectFlags(int flags) { Preconditions.checkArgument( getType() == Token.CALL || getType() == Token.NEW, "setIsNoSideEffectsCall only supports CALL and NEW nodes, got %s", Token.name(getType())); putIntProp(SIDE_EFFECT_FLAGS, flags); }
/** * Whether the node type has lower precedence than "precedence" */ static boolean isLowerPrecedence(Node n, final int precedence) { return NodeUtil.precedence(n.getType()) < precedence; }
private static boolean isDeclarationParent(Node parent) { switch (parent.getType()) { case Token.DECLARE: case Token.EXPORT: return true; default: return isStatementParent(parent); } }
private void validateNamespaceName(Node n) { switch (n.getType()) { case Token.NAME: validateName(n); break; case Token.GETPROP: validateGetProp(n); break; } }
private void checkInvalidIn(NodeTraversal t, Node n) { if (n.getType() == Token.IN) { reportIfNonObject(t, n.getLastChild(), SUSPICIOUS_IN_OPERATOR); } }
private void checkNonObjectInstanceOf(NodeTraversal t, Node n) { if (n.getType() == Token.INSTANCEOF) { reportIfNonObject( t, n.getFirstChild(), SUSPICIOUS_INSTANCEOF_LEFT_OPERAND); } }
private String getPropName(Node n) { switch (n.getType()) { case Token.GETPROP: return n.getLastChild().getString(); case Token.MEMBER_FUNCTION_DEF: return n.getString(); } throw new RuntimeException("Unexpected node type: " + n); }
private void validateVarOrOptionalExpression(Node n) { if (NodeUtil.isNameDeclaration(n)) { validateNameDeclarationHelper(n.getType(), n); } else { validateOptionalExpression(n); } }
private void validateAssignmentTarget(Node n) { if (!n.isValidAssignmentTarget()) { violation("Expected assignment target expression but was " + Token.name(n.getType()), n); } }
private void validateVarOrAssignmentTarget(Node n) { if (NodeUtil.isNameDeclaration(n)) { // Only one NAME can be declared for FOR-IN expressions. validateChildCount(n, 1); validateNameDeclarationHelper(n.getType(), n); } else { validateAssignmentTarget(n); } }
static boolean isNaN(Node n) { return (n.isName() && n.getString().equals("NaN")) || (n.getType() == Token.DIV && n.getFirstChild().isNumber() && n.getFirstChild().getDouble() == 0 && n.getLastChild().isNumber() && n.getLastChild().getDouble() == 0); }
public void splitDeclaration(Node n, Node parent) { while (n.getFirstChild() != n.getLastChild()) { Node child = n.getLastChild().detachFromParent(); Node newVar = IR.declaration(child, n.getType()).srcref(n); parent.addChildAfter(newVar, n); compiler.reportCodeChange(); } } }
private void visitImportNode(Node importNode) { Node defaultImport = importNode.getFirstChild(); if (defaultImport.isName()) { visitRequire(defaultImport.getString(), importNode); } Node namedImports = defaultImport.getNext(); if (namedImports.getType() == Token.IMPORT_SPECS) { for (Node importSpec : namedImports.children()) { visitRequire(importSpec.getLastChild().getString(), importNode); } } }