@Override public boolean apply(Node input) { return !input.isFunction(); } };
@Override public void visit(Node n) { if (n.isFunction()) { compiler.reportFunctionDeleted(n); } } });
/** * Checks whether the given constructor/member function belongs to a named class, as * opposed to an anonymous class. */ static boolean hasNamedClass(Node functionNode) { checkArgument(functionNode.isFunction()); return getClassName(functionNode) != null; }
@Override public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent) { if (n.isFunction()) { return false; } if (n.isYield()) { checkState(yieldNode == null); yieldNode = n; return false; } return true; }
/** * If the value is a literal, we can cross more boundaries to inline it. */ private boolean canMoveAggressively(Node value) { // Function expressions and other mutable objects can move within // the same basic block. return NodeUtil.isLiteralValue(value, true) || value.isFunction(); }
@Override public void exitScope(NodeTraversal nodeTraversal) { if (nodeTraversal.getScopeRoot().isFunction()) { namespaceStack.pop(); } }
/** * Return a BLOCK node for the given FUNCTION node. */ public static Node getFunctionBody(Node fn) { checkArgument(fn.isFunction(), fn); return fn.getLastChild(); }
@Override public final boolean shouldTraverse(NodeTraversal t, Node n, Node parent) { // Don't enter any new functions return !n.isFunction() || n == scope.getRootNode(); }
@Override public void exitScope(NodeTraversal t) { if (t.inGlobalScope() || t.getScopeRoot().isFunction()) { thisStack.remove(thisStack.size() - 1); } }
@Override public boolean apply(Node n) { if (n.isName()) { return n.getString().equals("eval"); } if (!assumeMinimumCapture && n.isFunction()) { return n != fnNode; } return false; } };
private int getFunctionParamCount(Node n) { Preconditions.checkArgument(n.isFunction(), "Expected a function node, found %s", n); return n.getSecondChild().getChildCount(); }
private void handleFunction(Node node) { // A block transfer control to its first child if it is not empty. checkState(node.isFunction()); checkState(node.getChildCount() == 3); createEdge(node, Branch.UNCOND, computeFallThrough(node.getLastChild())); checkState(exceptionHandler.peek() == node); exceptionHandler.pop(); }
@Override void visitPreorder(NodeTraversal t, Node n, Node parent) { if (parent == null) { handleFunctionInputs(); } else if (n.isFunction()) { defineFunctionLiteral(n); } }
/** If this is a non-function prototype assign, return the prop name. Otherwise, return null. */ private String processNonFunctionPrototypeAssign(Node n, Node parent) { if (isAssignRValue(n, parent) && !n.isFunction()) { return getPrototypePropertyNameFromRValue(n); } return null; }
private void validateBlockScopedFunctions(Node n) { if (n.isFunction() && n.getParent().isBlock() && !n.getGrandparent().isFunction()) { maybeWarnForFeature(n, Feature.BLOCK_SCOPED_FUNCTION_DECLARATION); } }
/** @return Whether the given property declaration is assigned to a function. */ private boolean isFunctionProperty(Node n) { // TODO(dylandavidson): getAssignedValue does not support GETELEM. if (n.isGetElem()) { return false; } Node assignedValue = NodeUtil.getAssignedValue(n); return assignedValue != null && assignedValue.isFunction(); }
/** Set the given function/class node to an empty name */ public static void removeName(Node n) { checkState(n.isFunction() || n.isClass()); Node originalName = n.getFirstChild(); Node emptyName = n.isFunction() ? IR.name("") : IR.empty(); n.replaceChild(originalName, emptyName.useSourceInfoFrom(originalName)); }
private boolean isNewControlBranch(Node n) { return n != null && (NodeUtil.isControlStructure(n) || n.isHook() || n.isAnd() || n.isOr() || n.isFunction()); } }
/** Recurses through a tree, marking all function nodes as changed. */ static void markNewScopesChanged(Node node, AbstractCompiler compiler) { if (node.isFunction()) { compiler.reportChangeToChangeScope(node); } for (Node child = node.getFirstChild(); child != null; child = child.getNext()) { markNewScopesChanged(child, compiler); } }
@Override void visitPreorder(NodeTraversal t, Node n, Node parent) { // These are not descended into, so must be done preorder if (n.isFunction()) { if (parent.isMemberFunctionDef() && parent.getString().equals("constructor")) { // Constructor has already been analyzed, so pull that here. setDeferredType(n, currentScope.getRootNode().getJSType()); } else { defineFunctionLiteral(n); } } }