Skip to content

Commit

Permalink
Have LiveVariableAnalysisEs6 to be compatible with rest and default p…
Browse files Browse the repository at this point in the history
…arameters.

Adding some more tests for fuller coverage with ES6 features.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=163526307
  • Loading branch information
lillymliu authored and blickly committed Jul 31, 2017
1 parent e04692d commit f232880
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,11 @@ private void addToSetIfLocal(Node node, BitSet set) {
void markAllParametersEscaped() {
Node paramList = NodeUtil.getFunctionParameters(jsScope.getRootNode());
for (Node arg = paramList.getFirstChild(); arg != null; arg = arg.getNext()) {
escaped.add(jsScope.getVar(arg.getString()));
if (arg.isRest() || arg.isDefaultValue()) {
escaped.add(jsScope.getVar(arg.getFirstChild().getString()));
} else {
escaped.add(jsScope.getVar(arg.getString()));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,20 @@ public void testArgumentsArray() {
// escaped set.
assertEscaped("arguments[0]", "param1");
assertEscaped("arguments[0]", "param2");
assertEscaped("arguments[0]", "param3");
assertEscaped("var args = arguments", "param1");
assertEscaped("var args = arguments", "param2");
assertEscaped("var args = arguments", "param3");
assertNotEscaped("arguments = []", "param1");
assertNotEscaped("arguments = []", "param2");
assertNotEscaped("arguments = []", "param3");
assertEscaped("arguments[0] = 1", "param1");
assertEscaped("arguments[0] = 1", "param2");
assertEscaped("arguments[0] = 1", "param3");
assertEscaped("arguments[arguments[0]] = 1", "param1");
assertEscaped("arguments[arguments[0]] = 1", "param2");
assertEscaped("arguments[arguments[0]] = 1", "param3");

}

public void testTryCatchFinally() {
Expand Down Expand Up @@ -335,11 +341,15 @@ public void testDestructuring() {
assertNotLiveBeforeX("X: var [...a] = f();", "a");
assertNotEscaped("var [a, ...b] = [1, 2];", "b");
assertNotEscaped("var [a, ...b] = [1, 2];", "a");
assertNotEscaped("var [a, ,b] = [1, 2, 3];", "a");
assertNotEscaped("var [a, ,b] = [1, 2, 3];", "b");


assertLiveBeforeX("var {a: x, b: y} = g(); X:x", "x");
assertNotLiveBeforeX("X: var {a: x, b: y} = g();", "y");
assertNotEscaped("var {a: x, b: y} = g()", "x");
assertNotEscaped("var {a: x, b: y} = g()", "y");
assertNotEscaped("var {a: x = 3, b: y} = g();", "x");
}

public void testComplicatedDeclaration() {
Expand Down Expand Up @@ -426,7 +436,7 @@ private static LiveVariablesAnalysisEs6 computeLiveness(String src) {
compiler.setLifeCycleStage(LifeCycleStage.NORMALIZED);

// Set up test case
src = "function _FUNCTION(param1, param2){" + src + "}";
src = "function _FUNCTION(param1, param2 = 1, ...param3){" + src + "}";
Node n = compiler.parseTestCode(src).removeFirstChild();
checkState(n.isFunction(), n);
Node script = new Node(Token.SCRIPT, n);
Expand Down

0 comments on commit f232880

Please sign in to comment.