/** * @return The TRY node for the specified CATCH node. */ private static Node getTryForCatch(Node n) { return n.getGrandparent(); }
/** * @return The TRY node for the specified CATCH node. */ private static Node getTryForCatch(Node n) { return n.getGrandparent(); }
/** * @param scopeRoot the Node which is the root of the current scope * @return the goog.scope() CALL node containing the scopeRoot, or null if scopeRoot is not * in a goog.scope() call. */ private Node findScopeMethodCall(Node scopeRoot) { Node n = scopeRoot.getGrandparent(); if (isCallToScopeMethod(n)) { return n; } return null; }
/** * @param scopeRoot the Node which is the root of the current scope * @return the goog.scope() CALL node containing the scopeRoot, or null if scopeRoot is not * in a goog.scope() call. */ private Node findScopeMethodCall(Node scopeRoot) { Node n = scopeRoot.getGrandparent(); if (isCallToScopeMethod(n)) { return n; } return null; }
Node getGrandparent() { return getNode().getGrandparent(); }
private static boolean isEs6Constructor(Node fnNode) { return fnNode.isFunction() && fnNode.getGrandparent() != null && fnNode.getGrandparent().isClassMembers() && fnNode.getParent().matchesQualifiedName("constructor"); }
static boolean isValidCfgRoot(Node n) { switch (n.getType()) { case Token.FUNCTION: case Token.SCRIPT: return true; case Token.BLOCK: // Only valid for top level synthetic block if (n.getParent() == null || n.getGrandparent() == null) { return true; } default: return false; } }
private static boolean isClinitFieldAssignment(Node node) { return node.getParent().isExprResult() && node.getGrandparent().isBlock() && isClinitMethod(node.getGrandparent().getParent()); }
@Override public void visit(Node n) { if (n.isString() && n.getString().equals("$") && n.getParent().isGetProp() && n.getGrandparent().isGetProp()) { Node dollarChildProp = n.getGrandparent(); dollarChildProp.setType(Token.GETELEM); compiler.reportCodeChange(); } } },
@Override public void visit(Node n) { if (n.isString() && n.getString().equals("$") && n.getParent().isGetProp() && n.getGrandparent().isGetProp()) { Node dollarChildProp = n.getGrandparent(); dollarChildProp.setToken(Token.GETELEM); compiler.reportChangeToEnclosingScope(dollarChildProp); } } });
/** * Is this node a hoisted function declaration? A function declaration in the * scope root is hoisted to the top of the scope. * See {@link #isFunctionDeclaration}). */ public static boolean isHoistedFunctionDeclaration(Node n) { return isFunctionDeclaration(n) && (n.getParent().isScript() || n.getGrandparent().isFunction()); }
private void findPrototypeProps(String type, Set<String> props) { Name slot = namespace.getSlot(type); if (slot != null) { for (Ref ref : slot.getRefs()) { if (ref.type == Ref.Type.PROTOTYPE_GET) { Node fullName = ref.getNode().getGrandparent(); if (fullName.isGetProp()) { props.add(fullName.getLastChild().getString()); } } } } }
private void findPrototypeProps(String type, Set<String> props) { Name slot = namespace.getSlot(type); if (slot != null) { for (Ref ref : slot.getRefs()) { if (ref.type == Ref.Type.PROTOTYPE_GET) { Node fullName = ref.getNode().getGrandparent(); if (fullName.isGetProp()) { props.add(fullName.getLastChild().getString()); } } } } }
private void validateBlockScopedFunctions(Node n) { if (n.isFunction() && n.getParent().isBlock() && !n.getGrandparent().isFunction()) { maybeWarnForFeature(n, Feature.BLOCK_SCOPED_FUNCTION_DECLARATION); } }
static boolean isClassMethod(Node functionNode) { checkArgument(functionNode.isFunction()); Node parent = functionNode.getParent(); if (parent.isMemberFunctionDef() && parent.getParent().isClassMembers()) { // ES6 class return true; } // goog.defineClass return parent.isStringKey() && parent.getParent().isObjectLit() && parent.getGrandparent().isCall() && parent.getGrandparent().getFirstChild().matchesQualifiedName("goog.defineClass"); }
private boolean isTopLevelAssignLhs(Node n) { Node parent = n.getParent(); return parent.isAssign() && n == parent.getFirstChild() && parent.getParent().isExprResult() && parent.getGrandparent().isScript(); }
private void maybeSplitMultiVar(Node rhsNode) { Node statementNode = rhsNode.getGrandparent(); if (!statementNode.isVar() || !statementNode.hasMoreThanOneChild()) { return; } Node nameNode = rhsNode.getParent(); nameNode.detach(); rhsNode.detach(); statementNode.getParent().addChildBefore(IR.var(nameNode, rhsNode), statementNode); }
private void validateFunctionStatement(Node n) { validateNodeType(Token.FUNCTION, n); validateChildCount(n); validateName(n.getFirstChild()); validateParameters(n.getSecondChild()); validateFunctionBody(n.getLastChild(), false); validateFunctionFeatures(n); if (n.getParent().isBlock() && !n.getGrandparent().isFunction()) { // e.g. if (true) { function f() {} } validateFeature(Feature.BLOCK_SCOPED_FUNCTION_DECLARATION, n); } }
static boolean isEnumDecl(Node n) { if (n.isVar() || n.isName() && n.getParent().isVar() || (n.isGetProp() && n.getParent().isAssign() && n.getGrandparent().isExprResult()) || (n.isAssign() && n.getParent().isExprResult())) { JSDocInfo jsdoc = getBestJSDocInfo(n); return jsdoc != null && jsdoc.hasEnumParameterType(); } return false; }
static boolean isEnumDecl(Node n) { if (NodeUtil.isNameDeclaration(n) || (n.isName() && NodeUtil.isNameDeclaration(n.getParent())) || (n.isGetProp() && n.getParent().isAssign() && n.getGrandparent().isExprResult()) || (n.isAssign() && n.getParent().isExprResult())) { JSDocInfo jsdoc = getBestJSDocInfo(n); return jsdoc != null && jsdoc.hasEnumParameterType(); } return false; }