fix corner case in collapse_vars (#3699)

fixes #3698
This commit is contained in:
Alex Lam S.L
2020-01-30 00:08:53 +08:00
committed by GitHub
parent 2ba5f391e0
commit a3754068dd
2 changed files with 83 additions and 7 deletions

View File

@@ -7658,3 +7658,79 @@ call_3_symbol: {
}
expect_stdout: "function"
}
issue_3698_1: {
options = {
collapse_vars: true,
}
input: {
var log = console.log;
var a, b = 0, c = 0;
(function() {
a = b;
})(b++, (b++, c++));
log(a, b, c);
}
expect: {
var log = console.log;
var a, b = 0, c = 0;
(function() {
a = b;
})(b++, (b++, c++));
log(a, b, c);
}
expect_stdout: "2 2 1"
}
issue_3698_2: {
options = {
collapse_vars: true,
reduce_vars: true,
}
input: {
var log = console.log;
var a, b = 0, c = 0, d = 1;
(function f() {
a = b;
d-- && f();
})(b++, (b++, c++));
log(a, b, c, d);
}
expect: {
var log = console.log;
var a, b = 0, c = 0, d = 1;
(function f() {
a = b;
d-- && f();
})(b++, (b++, c++));
log(a, b, c, d);
}
expect_stdout: "2 2 1 -1"
}
issue_3698_3: {
options = {
collapse_vars: true,
reduce_vars: true,
}
input: {
var a = 0, b = 0;
(function f(c) {
{
b++;
var bar_1 = (b = 1 + b, c = 0);
a-- && f();
}
})();
console.log(b);
}
expect: {
var a = 0, b = 0;
(function f(c) {
var bar_1 = (b = 1 + ++b, c = 0);
a-- && f();
})();
console.log(b);
}
expect_stdout: "2"
}