fix corner cases in reduce_vars & unused (#3955)
fixes #3953 fixes #3956 fixes #3957
This commit is contained in:
@@ -2652,3 +2652,41 @@ issue_3951: {
|
||||
"0",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3956: {
|
||||
options = {
|
||||
collapse_vars: true,
|
||||
evaluate: true,
|
||||
inline: true,
|
||||
passes: 2,
|
||||
reduce_vars: true,
|
||||
sequences: true,
|
||||
side_effects: true,
|
||||
toplevel: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
(function(a) {
|
||||
function f(b) {
|
||||
console.log(b);
|
||||
a = 1;
|
||||
}
|
||||
var c = f(c += 0);
|
||||
(function(d) {
|
||||
console.log(d);
|
||||
})(console.log(a) ^ 1, c);
|
||||
})();
|
||||
}
|
||||
expect: {
|
||||
var c, d;
|
||||
c += 0,
|
||||
console.log(NaN),
|
||||
d = 1 ^ console.log(1),
|
||||
console.log(d);
|
||||
}
|
||||
expect_stdout: [
|
||||
"NaN",
|
||||
"1",
|
||||
"1",
|
||||
]
|
||||
}
|
||||
|
||||
@@ -2715,3 +2715,23 @@ issue_3944: {
|
||||
}
|
||||
expect_stdout: "false"
|
||||
}
|
||||
|
||||
issue_3953: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
(a += 0 * (a = 0)) && console.log("PASS");
|
||||
}
|
||||
f(1);
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
(a += 0 * (a = 0)) && console.log("PASS");
|
||||
}
|
||||
f(1);
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
@@ -7273,3 +7273,53 @@ local_assignment_loop: {
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
}
|
||||
|
||||
issue_3957_1: {
|
||||
options = {
|
||||
evaluate: true,
|
||||
reduce_vars: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
while (a += console.log(a = 0))
|
||||
a = 0;
|
||||
}
|
||||
f("FAIL");
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
while (a += console.log(a = 0))
|
||||
a = 0;
|
||||
}
|
||||
f("FAIL");
|
||||
}
|
||||
expect_stdout: [
|
||||
"0",
|
||||
"0",
|
||||
]
|
||||
}
|
||||
|
||||
issue_3957_2: {
|
||||
options = {
|
||||
reduce_vars: true,
|
||||
unused: true,
|
||||
}
|
||||
input: {
|
||||
function f(a) {
|
||||
while (a += console.log(a = 0))
|
||||
a = 0;
|
||||
}
|
||||
f("FAIL");
|
||||
}
|
||||
expect: {
|
||||
function f(a) {
|
||||
while (a += console.log(a = 0))
|
||||
a = 0;
|
||||
}
|
||||
f("FAIL");
|
||||
}
|
||||
expect_stdout: [
|
||||
"0",
|
||||
"0",
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user