Skip to content

Commit

Permalink
Refactor LiveVariablesAnalysisES6 and add edit to markEscapedParameters
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=159610298
  • Loading branch information
simran-arora authored and blickly committed Jun 21, 2017
1 parent 844b9a0 commit 27bf939
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/com/google/javascript/jscomp/LiveVariablesAnalysisEs6.java
Expand Up @@ -168,22 +168,21 @@ private void addScopeVariables() {
// add the hoisted variables from this child scope
if ((v.isLet() || v.isConst()) && !jsScope.isFunctionScope()) {
continue;

}
scopeVariables.put(v.getName(), num);
num++;
}
}
} else if (jsScope.isFunctionBlockScope()) {
for (Var v : jsScope.getParent().getVarIterable()) {
scopeVariables.put(v.getName(), num);
num++;
}
} else {

for (Var v : jsScope.getVarIterable()) {
scopeVariables.put(v.getName(), num);
num++;
if (jsScope.isFunctionBlockScope()) {
for (Var v : jsScope.getParent().getVarIterable()) {
scopeVariables.put(v.getName(), num);
num++;
}
}
} else {

for (Var v : jsScope.getVarIterable()) {
scopeVariables.put(v.getName(), num);
num++;
Expand Down Expand Up @@ -368,8 +367,14 @@ private void addToSetIfLocal(Node node, BitSet set) {
*/
void markAllParametersEscaped() {
if (jsScope.isFunctionScope()) {
Node lp = jsScope.getRootNode().getSecondChild();
for (Node arg = lp.getFirstChild(); arg != null; arg = arg.getNext()) {
Node paramList = NodeUtil.getFunctionParameters(jsScope.getRootNode());
for (Node arg = paramList.getFirstChild(); arg != null; arg = arg.getNext()) {
escaped.add(jsScope.getVar(arg.getString()));
}
} else {
Node enclosingFunction = NodeUtil.getEnclosingFunction(jsScope.getRootNode());
Node paramList = NodeUtil.getFunctionParameters(enclosingFunction);
for (Node arg = paramList.getFirstChild(); arg != null; arg = arg.getNext()) {
escaped.add(jsScope.getVar(arg.getString()));
}
}
Expand Down

0 comments on commit 27bf939

Please sign in to comment.