fix corner case

add test
This commit is contained in:
alexlamsl 2017-12-31 22:12:47 +08:00
parent ab09e869f9
commit 4999af294a
2 changed files with 28 additions and 3 deletions

View File

@ -1677,10 +1677,9 @@ merge(Compressor.prototype, {
} else if (stat instanceof AST_For) {
if (prev instanceof AST_Var && (!stat.init || stat.init.TYPE == prev.TYPE)) {
if (stat.init) {
stat.init.definitions = prev.definitions.concat(stat.init.definitions);
} else {
stat.init = prev;
prev.definitions = prev.definitions.concat(stat.init.definitions);
}
stat.init = prev;
statements[j] = stat;
CHANGED = true;
} else if (defs && stat.init && defs.TYPE == stat.init.TYPE && declarations_only(stat.init)) {

View File

@ -833,3 +833,29 @@ hoist_decl: {
for (y(); 0;) z();
}
}
for_init_var: {
options = {
join_vars: true,
unused: false,
}
input: {
var a = "PASS";
(function() {
var b = 42;
for (var c = 5; c > 0;) c--;
a = "FAIL";
var a;
})();
console.log(a);
}
expect: {
var a = "PASS";
(function() {
for (var b = 42, c = 5, a; c > 0;) c--;
a = "FAIL";
})();
console.log(a);
}
expect_stdout: "PASS"
}