private static Node fixupFreeCall(Node call) { checkState(call.isCall()); call.putBooleanProp(Node.FREE_CALL, true); return call; }
/** * @param node A node * @return Whether the call is a NEW or CALL node. */ public static boolean isCallOrNew(Node node) { return node.isCall() || node.isNew(); }
private Node getCallArgument(Node n, int i) { Preconditions.checkArgument(n.isCall(), "Expected a call node, found %s", n); return n.getChildAtIndex(i + 1); }
private int getCallParamCount(Node n) { Preconditions.checkArgument(n.isCall(), "Expected a call node, found %s", n); return n.getChildCount() - 1; }
private ImmutableList<Node> getCallParams(Node n) { Preconditions.checkArgument(n.isCall(), "Expected a call node, found %s", n); ImmutableList.Builder<Node> builder = new ImmutableList.Builder<>(); for (int i = 0; i < getCallParamCount(n); i++) { builder.add(getCallArgument(n, i)); } return builder.build(); }
/** * @return Whether the call has a local result. */ static boolean callHasLocalResult(Node n) { checkState(n.isCall() || n.isTaggedTemplateLit(), n); return (n.getSideEffectFlags() & Node.FLAG_LOCAL_RESULTS) > 0; }
private String getCallName(Node n) { Preconditions.checkArgument(n.isCall(), "Expected a call node, found %s", n); return n.getFirstChild().getString(); }
/** * @return Whether the call represents a class definition. */ static boolean isGoogDefineClass(Node value) { if (value != null && value.isCall()) { return value.getFirstChild().matchesQualifiedName("goog.defineClass"); } return false; }
/** * Is this node a call expression statement? * * @param n The node * @return True if {@code n} is EXPR_RESULT and {@code n}'s * first child is CALL */ public static boolean isExprCall(Node n) { return n.isExprResult() && n.getFirstChild().isCall(); }
/** * A faster version of {@link #isCallTo(Node, String)}. * * @param n node to check if a call * @param targetMethod the prebuilt AST getprop node that represents the method to check */ public static boolean isCallTo(Node n, Node targetMethod) { if (!n.isCall()) { return false; } return n.getFirstChild().matchesQualifiedName(targetMethod); }
private static boolean hasSpreadCallArgument(Node callNode) { checkArgument(callNode.isCall(), callNode); for (Node arg = callNode.getSecondChild(); arg != null; arg = arg.getNext()) { if (arg.isSpread()) { return true; } } return false; }
/** * Returns whether the node is an argument of a function that returns * a unique id (the last part of the qualified name matches * GET_UNIQUE_ID_FUNCTION). */ private static boolean insideGetUniqueIdCall(Node n) { Node parent = n.getParent(); String name = parent.isCall() ? parent.getFirstChild().getQualifiedName() : null; return name != null && name.endsWith(GET_UNIQUE_ID_FUNCTION); }
/** * Whether the provided node acts as the target function in a call expression including * .call expressions. For example, returns true for 'x' in 'x.call()'. */ static boolean isCallTarget(Node n) { Node parent = n.getParent(); return ((parent.getFirstChild() == n) && parent.isCall()) || (parent.isGetProp() && parent.getParent().isCall() && parent.getLastChild().getString().equals("call")); }
private static boolean isStringValueOfCall(Node node) { return node.isCall() // Do not optimize if the parameter was removed && node.hasXChildren(2) && isStringValueOfMethodName(node.getFirstChild()); }
static boolean isCallTarget(Node n) { Node parent = n.getParent(); return (parent.isCall() || parent.isNew()) && parent.getFirstChild() == n; }
/** Returns whether the node is an argument of a goog.getCssName call. */ private static boolean insideGetCssNameCall(Node n) { Node parent = n.getParent(); return parent.isCall() && parent.getFirstChild().matchesQualifiedName(GET_CSS_NAME_FUNCTION); }
private Node createNewSuperCall(Node superClassQNameNode, Node superCall, JSType thisType) { checkArgument(superClassQNameNode.isQualifiedName(), superClassQNameNode); checkArgument(superCall.isCall(), superCall); Node callee = superCall.getFirstChild(); if (callee.isSuper()) { return createNewSuperCallWithDotCall(superClassQNameNode, superCall, thisType); } else { return createNewSuperCallWithDotApply(superClassQNameNode, superCall, thisType); } }
@Override public void visit(NodeTraversal t, Node n, Node parent) { if (n.isCall() && isGoogDefineClass(n) && !validateUsage(n)) { compiler.report(JSError.make(n, GOOG_CLASS_TARGET_INVALID)); } maybeRewriteClassDefinition(t, n); }
private void visitSuper(NodeTraversal t, Node n, Node parent) { if (parent.isCall()) { visitSuperCall(t, n, parent); } else if (parent.isGetProp() || parent.isGetElem()) { visitSuperAccess(t, n); } else { t.report(n, INVALID_SUPER_USAGE); } }
static boolean isUnannotatedCallback(Node n) { JSDocInfo jsdoc = getBestJSDocInfo(n); return n.isFunction() && n.getParent().isCall() && n != n.getParent().getFirstChild() && jsdoc == null && !functionHasInlineJsdocs(n); }