2013-01-16 19:59:19 +00:00
|
|
|
holes_and_undefined: {
|
|
|
|
|
input: {
|
Fix output for arrays whose last element is a hole: [1,,]
1529ab96 started to do this (by considering holes to be separate from
"undefined") but it still converted
[1,,] (length 2, last element hole, trailing comma)
to
[1,] (length 1, trailing comma)
Unfortunately the test suite doesn't really make this clear: the new test here
passes with or without this patch because run-tests.js beautifys the expected
output (in "make_code"), which does the incorrect transformation! If you make
some manual change to arrays.js to make the test fail and see the INPUT and
OUTPUT, then you can see that without this fix, [1,,] -> [1,], and with this fix
it stays [1,,].
2013-01-16 19:59:19 +00:00
|
|
|
w = [1,,];
|
2013-01-16 19:59:19 +00:00
|
|
|
x = [1, 2, undefined];
|
|
|
|
|
y = [1, , 2, ];
|
|
|
|
|
z = [1, undefined, 3];
|
|
|
|
|
}
|
|
|
|
|
expect: {
|
Fix output for arrays whose last element is a hole: [1,,]
1529ab96 started to do this (by considering holes to be separate from
"undefined") but it still converted
[1,,] (length 2, last element hole, trailing comma)
to
[1,] (length 1, trailing comma)
Unfortunately the test suite doesn't really make this clear: the new test here
passes with or without this patch because run-tests.js beautifys the expected
output (in "make_code"), which does the incorrect transformation! If you make
some manual change to arrays.js to make the test fail and see the INPUT and
OUTPUT, then you can see that without this fix, [1,,] -> [1,], and with this fix
it stays [1,,].
2013-01-16 19:59:19 +00:00
|
|
|
w=[1,,];
|
2013-01-16 19:59:19 +00:00
|
|
|
x=[1,2,void 0];
|
|
|
|
|
y=[1,,2];
|
|
|
|
|
z=[1,void 0,3];
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-09-19 15:20:45 +00:00
|
|
|
|
|
|
|
|
constant_join: {
|
|
|
|
|
options = {
|
|
|
|
|
unsafe : true,
|
|
|
|
|
evaluate : true
|
|
|
|
|
};
|
|
|
|
|
input: {
|
|
|
|
|
var a = [ "foo", "bar", "baz" ].join("");
|
2013-09-22 10:12:34 +00:00
|
|
|
var a1 = [ "foo", "bar", "baz" ].join();
|
2013-09-19 15:20:45 +00:00
|
|
|
var b = [ "foo", 1, 2, 3, "bar" ].join("");
|
|
|
|
|
var c = [ boo(), "foo", 1, 2, 3, "bar", bar() ].join("");
|
2013-09-22 10:12:34 +00:00
|
|
|
var c1 = [ boo(), bar(), "foo", 1, 2, 3, "bar", bar() ].join("");
|
|
|
|
|
var c2 = [ 1, 2, "foo", "bar", baz() ].join("");
|
2013-09-19 15:20:45 +00:00
|
|
|
var d = [ "foo", 1 + 2 + "bar", "baz" ].join("-");
|
2013-09-20 04:24:25 +00:00
|
|
|
var e = [].join(foo + bar);
|
2013-09-22 10:12:34 +00:00
|
|
|
var f = [].join("");
|
|
|
|
|
var g = [].join("foo");
|
2013-09-19 15:20:45 +00:00
|
|
|
}
|
|
|
|
|
expect: {
|
|
|
|
|
var a = "foobarbaz";
|
2013-09-22 10:12:34 +00:00
|
|
|
var a1 = "foo,bar,baz";
|
2013-09-19 15:20:45 +00:00
|
|
|
var b = "foo123bar";
|
2013-09-22 10:12:34 +00:00
|
|
|
var c = boo() + "foo123bar" + bar();
|
|
|
|
|
var c1 = "" + boo() + bar() + "foo123bar" + bar();
|
|
|
|
|
var c2 = "12foobar" + baz();
|
2013-09-19 15:20:45 +00:00
|
|
|
var d = "foo-3bar-baz";
|
2013-09-20 04:24:25 +00:00
|
|
|
var e = [].join(foo + bar);
|
2013-09-22 10:12:34 +00:00
|
|
|
var f = "";
|
|
|
|
|
var g = "";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constant_join_2: {
|
|
|
|
|
options = {
|
|
|
|
|
unsafe : true,
|
|
|
|
|
evaluate : true
|
|
|
|
|
};
|
|
|
|
|
input: {
|
|
|
|
|
var a = [ "foo", "bar", boo(), "baz", "x", "y" ].join("");
|
|
|
|
|
var b = [ "foo", "bar", boo(), "baz", "x", "y" ].join("-");
|
|
|
|
|
var c = [ "foo", "bar", boo(), "baz", "x", "y" ].join("really-long-separator");
|
|
|
|
|
var d = [ "foo", "bar", boo(),
|
|
|
|
|
[ "foo", 1, 2, 3, "bar" ].join("+"),
|
|
|
|
|
"baz", "x", "y" ].join("-");
|
|
|
|
|
var e = [ "foo", "bar", boo(),
|
|
|
|
|
[ "foo", 1, 2, 3, "bar" ].join("+"),
|
|
|
|
|
"baz", "x", "y" ].join("really-long-separator");
|
|
|
|
|
var f = [ "str", "str" + variable, "foo", "bar", "moo" + foo ].join("");
|
|
|
|
|
}
|
|
|
|
|
expect: {
|
|
|
|
|
var a = "foobar" + boo() + "bazxy";
|
|
|
|
|
var b = [ "foo-bar", boo(), "baz-x-y" ].join("-");
|
|
|
|
|
var c = [ "foo", "bar", boo(), "baz", "x", "y" ].join("really-long-separator");
|
|
|
|
|
var d = [ "foo-bar", boo(), "foo+1+2+3+bar-baz-x-y" ].join("-");
|
|
|
|
|
var e = [ "foo", "bar", boo(),
|
|
|
|
|
"foo+1+2+3+bar",
|
|
|
|
|
"baz", "x", "y" ].join("really-long-separator");
|
2013-09-22 12:26:10 +00:00
|
|
|
var f = "strstr" + variable + "foobarmoo" + foo;
|
2013-09-19 15:20:45 +00:00
|
|
|
}
|
|
|
|
|
}
|
2017-01-26 11:14:18 +00:00
|
|
|
|
|
|
|
|
for_loop: {
|
|
|
|
|
options = {
|
|
|
|
|
unsafe : true,
|
2017-01-26 11:59:32 +00:00
|
|
|
unused : true,
|
2017-01-26 11:14:18 +00:00
|
|
|
evaluate : true,
|
|
|
|
|
reduce_vars : true
|
|
|
|
|
};
|
|
|
|
|
input: {
|
|
|
|
|
function f0() {
|
|
|
|
|
var a = [1, 2, 3];
|
|
|
|
|
for (var i = 0; i < a.length; i++) {
|
|
|
|
|
console.log(a[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function f1() {
|
|
|
|
|
var a = [1, 2, 3];
|
|
|
|
|
for (var i = 0, len = a.length; i < len; i++) {
|
|
|
|
|
console.log(a[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function f2() {
|
|
|
|
|
var a = [1, 2, 3];
|
|
|
|
|
for (var i = 0; i < a.length; i++) {
|
|
|
|
|
a[i]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
expect: {
|
|
|
|
|
function f0() {
|
|
|
|
|
var a = [1, 2, 3];
|
|
|
|
|
for (var i = 0; i < 3; i++)
|
|
|
|
|
console.log(a[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function f1() {
|
|
|
|
|
var a = [1, 2, 3];
|
2017-01-26 11:59:32 +00:00
|
|
|
for (var i = 0; i < 3; i++)
|
2017-01-26 11:14:18 +00:00
|
|
|
console.log(a[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function f2() {
|
|
|
|
|
var a = [1, 2, 3];
|
|
|
|
|
for (var i = 0; i < a.length; i++)
|
|
|
|
|
a[i]++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|