/** * Get the node that corresponds to an expression declared with var, let or const. * This has the AST structure VAR/LET/CONST -> NAME -> NODE * @param node */ private Node getNameDeclaredGrandchild(Node node) { if (!NodeUtil.isNameDeclaration(node)) { return null; } return node.getFirstFirstChild(); }
/** * @return The expression that is part of the return. */ private static Node getBlockReturnExpression(Node n) { Preconditions.checkState(isReturnExpressBlock(n)); return n.getFirstFirstChild(); }
/** * @return The expression that is part of the return. */ private static Node getBlockReturnExpression(Node n) { checkState(isReturnExpressBlock(n)); return n.getFirstFirstChild(); }
/** * @return {@code true} if the node an assignment to a prototype property of * some constructor. */ public static boolean isPrototypePropertyDeclaration(Node n) { return isExprAssign(n) && isPrototypeProperty(n.getFirstFirstChild()); }
/** * @return A prototype member declaration representation if there is one * else it returns {@code null}. */ private static PrototypeMemberDeclaration extractDeclaration(Node n) { if (!NodeUtil.isPrototypePropertyDeclaration(n)) { return null; } Node lhs = n.getFirstFirstChild(); return new PrototypeMemberDeclaration(lhs, n); } }
private static boolean isGoogModuleCall(Node n) { if (isExprCall(n)) { Node target = n.getFirstFirstChild(); return (target.matchesQualifiedName("goog.module")); } return false; }
static boolean isGoogModuleCall(Node n) { if (isExprCall(n)) { Node target = n.getFirstFirstChild(); return (target.matchesQualifiedName("goog.module")); } return false; }
static boolean isGoogModuleDeclareLegacyNamespaceCall(Node n) { if (isExprCall(n)) { Node target = n.getFirstFirstChild(); return (target.matchesQualifiedName("goog.module.declareLegacyNamespace")); } return false; }
/** * @return The name being assigned to. */ private Node getSimpleAssignmentName(Node n) { checkState(isSimpleAssignment(n)); if (NodeUtil.isExprAssign(n)) { return n.getFirstFirstChild(); } else { // A var declaration. return n.getFirstChild(); } }
/** * @return The condition of a conditional statement. */ private Node getConditionalStatementCondition(Node n) { if (n.isIf()) { return NodeUtil.getConditionExpression(n); } else { checkState(isExprConditional(n)); return n.getFirstFirstChild(); } }
private static Node getName(Node n) { if (n.isVar()) { return n.getFirstChild(); } else if (NodeUtil.isExprAssign(n)) { return n.getFirstFirstChild(); } throw new IllegalStateException(); }
/** * @return The condition of a conditional statement. */ private Node getConditionalStatementCondition(Node n) { if (n.isIf()) { return NodeUtil.getConditionExpression(n); } else { Preconditions.checkState(isExprConditional(n)); return n.getFirstFirstChild(); } }
private static Node getName(Node n) { if (NodeUtil.isNameDeclaration(n)) { return n.getFirstChild(); } else if (NodeUtil.isExprAssign(n)) { return n.getFirstFirstChild(); } throw new IllegalStateException(); }
private static Node getValue(Node n) { if (NodeUtil.isNameDeclaration(n)) { return n.getFirstFirstChild(); } else if (NodeUtil.isExprAssign(n)) { return n.getFirstChild().getLastChild(); } throw new IllegalStateException(); }
private static Node getValue(Node n) { if (n.isVar()) { return n.getFirstFirstChild(); } else if (NodeUtil.isExprAssign(n)) { return n.getFirstChild().getLastChild(); } throw new IllegalStateException(); }
/** * Matches literal value declarations {@code var foo = 3;} or stub declarations like * {@code var bar;}. */ private static boolean isClassFieldDeclaration(Node node) { return node.getParent().isScript() && node.isVar() && (!node.getFirstChild().hasChildren() || (node.getFirstFirstChild() != null && NodeUtil.isLiteralValue( node.getFirstFirstChild(), false /* includeFunctions */))); }
private boolean isFunctionDecl(Node n) { return n.isFunction() || (n.isVar() && n.getFirstFirstChild() != null && n.getFirstFirstChild().isFunction()) || n.isAssign() && n.getFirstChild().isQualifiedName() && n.getLastChild().isFunction(); }
private static boolean isPrototypePropertyDeclaration(Node n) { if (NodeUtil.isExprAssign(n) && isPrototypeProperty(n.getFirstFirstChild())) { return true; } if (n.isObjectLit()) { JSDocInfo jsdoc = n.getJSDocInfo(); return jsdoc != null && jsdoc.getLendsName() != null && jsdoc.getLendsName().endsWith("prototype"); } return false; }
/** * @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 boolean isAssignToEmptyFn(Node node, String enclosingFnName) { if (!NodeUtil.isExprAssign(node)) { return false; } Node lhs = node.getFirstFirstChild(); Node rhs = node.getFirstChild().getLastChild(); return NodeUtil.isEmptyFunctionExpression(rhs) && lhs.matchesQualifiedName(enclosingFnName); } }