Skip to content

Commit

Permalink
Remove hoisting up vars in the function block scope into the function…
Browse files Browse the repository at this point in the history
… parameter scope in DeadAssignmentsElimination

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=160557898
  • Loading branch information
lillymliu authored and brad4d committed Jun 30, 2017
1 parent 2634911 commit e29e6b5
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/com/google/javascript/jscomp/DeadAssignmentsElimination.java
Expand Up @@ -118,13 +118,6 @@ private void eliminateDeadAssignments(NodeTraversal t) {
return; return;
} }


// Elevate all variable declarations up till the function scope
// so the liveness analysis has all variables for the process.
for (Var var : blockScope.getVarIterable()) {
checkArgument(!var.isClass());
functionScope.declare(var.getName(), var.getNameNode(), var.getInput());
}

// Computes liveness information first. // Computes liveness information first.
ControlFlowGraph<Node> cfg = t.getControlFlowGraph(); ControlFlowGraph<Node> cfg = t.getControlFlowGraph();
liveness = liveness =
Expand Down Expand Up @@ -242,11 +235,11 @@ private void tryRemoveAssignment(NodeTraversal t, Node n, Node exprRoot,
} }
String name = lhs.getString(); String name = lhs.getString();
checkState(t.getScope().isFunctionBlockScope()); checkState(t.getScope().isFunctionBlockScope());
Scope functionScope = t.getScope().getParent(); Scope functionBlockScope = t.getScope();
if (!functionScope.isDeclaredSloppy(name, false)) { if (!functionBlockScope.isDeclaredSloppy(name, false)) {
return; return;
} }
Var var = functionScope.getVar(name); Var var = functionBlockScope.getVar(name);


if (liveness.getEscapedLocals().contains(var)) { if (liveness.getEscapedLocals().contains(var)) {
return; // Local variable that might be escaped due to closures. return; // Local variable that might be escaped due to closures.
Expand Down

0 comments on commit e29e6b5

Please sign in to comment.