fix corner cases in reduce_vars (#5097)

fixes #5096
This commit is contained in:
Alex Lam S.L
2021-07-23 10:17:20 +01:00
committed by GitHub
parent ec7fadcb5b
commit 6a3fe9d1df
3 changed files with 191 additions and 28 deletions

View File

@@ -6413,3 +6413,125 @@ issue_5067: {
}
expect: {}
}
issue_5096_1: {
options = {
evaluate: true,
passes: 2,
reduce_vars: true,
side_effects: true,
toplevel: true,
}
input: {
var a, b = "FAIL", c = 1;
do {
a && a();
a = function() {
b = "PASS";
};
} while (c--);
console.log(b);
}
expect: {
var a, b = "FAIL", c = 1;
do {
a && a();
a = function() {
b = "PASS";
};
} while (c--);
console.log(b);
}
expect_stdout: "PASS"
}
issue_5096_2: {
options = {
passes: 2,
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var a, b = "FAIL", c = 1;
do {
a && a();
a = function() {
b = "PASS";
};
} while (c--);
console.log(b);
}
expect: {
var a, b = "FAIL", c = 1;
do {
a && a();
a = function() {
b = "PASS";
};
} while (c--);
console.log(b);
}
expect_stdout: "PASS"
}
issue_5096_3: {
options = {
evaluate: true,
reduce_vars: true,
side_effects: true,
toplevel: true,
}
input: {
var b = "FAIL", c = 1;
do {
a && a();
var a = function() {
b = "PASS";
};
} while (c--);
console.log(b);
}
expect: {
var b = "FAIL", c = 1;
do {
a && a();
var a = function() {
b = "PASS";
};
} while (c--);
console.log(b);
}
expect_stdout: "PASS"
}
issue_5096_4: {
options = {
reduce_vars: true,
side_effects: true,
toplevel: true,
unused: true,
}
input: {
var b = "FAIL", c = 1;
do {
a && a();
var a = function() {
b = "PASS";
};
} while (c--);
console.log(b);
}
expect: {
var b = "FAIL", c = 1;
do {
a && a();
var a = function() {
b = "PASS";
};
} while (c--);
console.log(b);
}
expect_stdout: "PASS"
}