diff --git a/src/com/google/javascript/jscomp/DataFlowAnalysis.java b/src/com/google/javascript/jscomp/DataFlowAnalysis.java index bea456ee9b5..c18f4a3d95b 100644 --- a/src/com/google/javascript/jscomp/DataFlowAnalysis.java +++ b/src/com/google/javascript/jscomp/DataFlowAnalysis.java @@ -215,9 +215,9 @@ final void analyze(int maxSteps) { if (flow(curNode)) { // If there is a change in the current node, we want to grab the list // of nodes that this node affects. - List> nextNodes = isForward() ? - cfg.getDirectedSuccNodes(curNode) : - cfg.getDirectedPredNodes(curNode); + List> nextNodes = + isForward() ? cfg.getDirectedSuccNodes(curNode) : cfg.getDirectedPredNodes(curNode); + for (DiGraphNode nextNode : nextNodes) { if (nextNode != cfg.getImplicitReturn()) { orderedWorkSet.add(nextNode); @@ -544,64 +544,16 @@ public int hashCode() { /** * Compute set of escaped variables. When a variable is escaped in a dataflow analysis, it can be - * reference outside of the code that we are analyzing. A variable is escaped if any of the + * referenced outside of the code that we are analyzing. A variable is escaped if any of the * following is true: * - *

- * - *

    - *
  1. It is defined as the exception name in CATCH clause so it became a variable local not to - * our definition of scope. - *
  2. Exported variables as they can be needed after the script terminates. - *
  3. Names of named functions because in JavaScript, function foo(){} does not kill - * foo in the dataflow. - */ - static void computeEscaped( - final Scope jsScope, - final Set escaped, - AbstractCompiler compiler, - ScopeCreator scopeCreator) { - // TODO(user): Very good place to store this information somewhere. - - AbstractPostOrderCallback finder = new AbstractPostOrderCallback() { - @Override - public void visit(NodeTraversal t, Node n, Node parent) { - if (jsScope == t.getScope() || !n.isName() - || parent.isFunction()) { - return; - } - String name = n.getString(); - Var var = t.getScope().getVar(name); - if (var != null && var.scope == jsScope) { - escaped.add(jsScope.getVar(name)); - } - } - }; - - NodeTraversal t = new NodeTraversal(compiler, finder, scopeCreator); - t.traverseAtScope(jsScope); - - // 1: Remove the exception name in CATCH which technically isn't local to - // begin with. - for (Var var : jsScope.getVarIterable()) { - if (var.getParentNode().isCatch() || - compiler.getCodingConvention().isExported(var.getName())) { - escaped.add(var); - } - } - } - - /** - * Alternate implementation of compute escaped for ES6. - * - * It should only be run when the jsScope is a function scope. - * - * The definition of escaped are * 1. Exported variables as they can be needed after the script terminates. * 2. Names of named functions because in JavaScript, function foo(){} does not kill * foo in the dataflow. + * + * @param jsScope Must be a function scope */ - static void computeEscapedEs6( + static void computeEscaped( final Scope jsScope, final Set escaped, AbstractCompiler compiler, diff --git a/src/com/google/javascript/jscomp/LiveVariablesAnalysis.java b/src/com/google/javascript/jscomp/LiveVariablesAnalysis.java index 18aa71c4514..48f85a75a9b 100644 --- a/src/com/google/javascript/jscomp/LiveVariablesAnalysis.java +++ b/src/com/google/javascript/jscomp/LiveVariablesAnalysis.java @@ -154,7 +154,7 @@ public int hashCode() { this.allVarsInFn = new HashMap<>(); this.orderedVars = new ArrayList<>(); - computeEscapedEs6(jsScope, escaped, compiler, scopeCreator); + computeEscaped(jsScope, escaped, compiler, scopeCreator); NodeUtil.getAllVarsDeclaredInFunction( allVarsInFn, orderedVars, compiler, scopeCreator, jsScope); diff --git a/src/com/google/javascript/jscomp/MaybeReachingVariableUse.java b/src/com/google/javascript/jscomp/MaybeReachingVariableUse.java index 3971b72cb38..459a5b5f7b9 100644 --- a/src/com/google/javascript/jscomp/MaybeReachingVariableUse.java +++ b/src/com/google/javascript/jscomp/MaybeReachingVariableUse.java @@ -64,7 +64,7 @@ class MaybeReachingVariableUse extends // TODO(user): Maybe compute it somewhere else and re-use the escape // local set here. - computeEscapedEs6(jsScope.getParent(), escaped, compiler, scopeCreator); + computeEscaped(jsScope.getParent(), escaped, compiler, scopeCreator); NodeUtil.getAllVarsDeclaredInFunction( allVarsInFn, orderedVars, compiler, scopeCreator, jsScope.getParent()); } @@ -110,8 +110,8 @@ public ReachingUses(ReachingUses other) { @Override public boolean equals(Object other) { - return (other instanceof ReachingUses) && - ((ReachingUses) other).mayUseMap.equals(this.mayUseMap); + return (other instanceof ReachingUses) + && ((ReachingUses) other).mayUseMap.equals(this.mayUseMap); } @Override diff --git a/src/com/google/javascript/jscomp/MustBeReachingVariableDef.java b/src/com/google/javascript/jscomp/MustBeReachingVariableDef.java index 64367645d42..388459f4839 100644 --- a/src/com/google/javascript/jscomp/MustBeReachingVariableDef.java +++ b/src/com/google/javascript/jscomp/MustBeReachingVariableDef.java @@ -61,7 +61,7 @@ final class MustBeReachingVariableDef extends this.escaped = new HashSet<>(); this.allVarsInFn = new HashMap<>(); this.orderedVars = new ArrayList<>(); - computeEscapedEs6(jsScope.getParent(), escaped, compiler, scopeCreator); + computeEscaped(jsScope.getParent(), escaped, compiler, scopeCreator); NodeUtil.getAllVarsDeclaredInFunction( allVarsInFn, orderedVars, compiler, scopeCreator, jsScope.getParent()); } @@ -152,8 +152,7 @@ public MustDef(MustDef other) { @Override public boolean equals(Object other) { - return (other instanceof MustDef) && - ((MustDef) other).reachingDef.equals(this.reachingDef); + return (other instanceof MustDef) && ((MustDef) other).reachingDef.equals(this.reachingDef); } @Override