Added ES6 tests to optimizeArgumentsArray pass
@@ -144,6 +144,56 @@ public final class OptimizeArgumentsArrayTest extends CompilerTestCase {
"function f(p0) { p0; function b() { function c() { }} }");
}
+ // Correct outputs for the following arrow function tests are commented out
+ // TODO(simranarora): Fix the pass so that it produces these correct outputs.
+ public void testArrowFunctions() {
+
+ // simple
+ test(
+ "function f() { () => { alert(arguments[0]); } }",
+ "function f() { (p0) => { alert(p0); } }");
+ // function(p0) { () => { alert(p0); } }
+
+ // no var args
+ testSame("function f() { (a,b,c) => alert(a + b + c); }");
+
+ test(
+ "function f() { (a,b,c) => alert(arguments[0]); }",
+ "function f() { (a,b,c) => alert(a); }");
+ // function f(p0) { (a b,c) => alert(p0); }
+
+ // two var args
+ test(
+ "function f() { (a) => alert(arguments[1] + arguments[2]); }",
+ "function f() { (a, p0, p1) => alert(p0 + p1); }");
+ // function f(p0, p1, p2) { (a) => alert(p1 + p2); }
+
+ // test with required params
+ test(
+ "function f() { (req0, var_args) => alert(req0 + arguments[1]); }",
+ "function f() { (req0, var_args) => alert(req0 + var_args); }");
+ // function f(p0) { (req0, var_args) => alert(req0 + p0); }
+ }
+
+ public void testArrowFunctionIsInnerFunction() {
+
+ test("function f() { ( ) => { arguments[0] }}",
+ "function f() { (p0) => { p0 }}");
+ // function f(p0) { ( ) => { p0 }}
+
+ test(
+ "function f( ) { arguments[0]; ( ) => { arguments[0] }}",
+ "function f(p1) { p1; (p0) => { p0 }}");
+ // function f(p0) { p0; ( ) => { p0 }}
+ }
+
+ public void testArrowFunctionDeclaration() {
+
+ test("function f() { var f = () => { alert(arguments[0]); } }",
+ "function f() { var f = (p0) => { alert(p0); } }");
+ //"function f(p0) { var f = () => { alert(p0); } }"
+ }
+
public void testNoOptimizationWhenGetProp() {
testSame("function f() { arguments[0]; arguments.size }");
}
