Keep const in own scope while compressing

- Fixes #1205
- Fix provided by @kzc
This commit is contained in:
Anthony Van de Gejuchte
2016-07-14 18:43:50 +02:00
committed by Richard van Velzen
parent eb63fece2f
commit 7eb52d2837
2 changed files with 44 additions and 2 deletions

View File

@@ -810,7 +810,7 @@ merge(Compressor.prototype, {
CHANGED = true;
}
else if (stat instanceof AST_For
&& prev instanceof AST_Definitions
&& prev instanceof AST_Var
&& (!stat.init || stat.init.TYPE == prev.TYPE)) {
CHANGED = true;
a.pop();

View File

@@ -145,3 +145,45 @@ parse_do_while_without_semicolon: {
do x(); while (false);y();
}
}
keep_collapse_const_in_own_block_scope: {
options = {
join_vars: true,
loops: true
}
input: {
var i=2;
const c=5;
while(i--)
console.log(i);
console.log(c);
}
expect: {
var i=2;
const c=5;
for(;i--;)
console.log(i);
console.log(c);
}
}
keep_collapse_const_in_own_block_scope_2: {
options = {
join_vars: true,
loops: true
}
input: {
const c=5;
var i=2; // Moves to loop, while it did not in previous test
while(i--)
console.log(i);
console.log(c);
}
expect: {
const c=5;
for(var i=2;i--;)
console.log(i);
console.log(c);
}
}