fix reduce_vars on do...while (#2596)

This commit is contained in:
Alex Lam S.L
2017-12-15 16:33:19 +08:00
committed by GitHub
parent 8f681b1d17
commit 092d9affb8
2 changed files with 43 additions and 1 deletions

View File

@@ -479,7 +479,17 @@ merge(Compressor.prototype, {
} }
return true; return true;
} }
if (node instanceof AST_DWLoop) { if (node instanceof AST_Do) {
var saved_loop = in_loop;
in_loop = node;
push();
node.body.walk(tw);
node.condition.walk(tw);
pop();
in_loop = saved_loop;
return true;
}
if (node instanceof AST_While) {
var saved_loop = in_loop; var saved_loop = in_loop;
in_loop = node; in_loop = node;
push(); push();

View File

@@ -4867,3 +4867,35 @@ defun_single_use_loop: {
"true", "true",
] ]
} }
do_while: {
options = {
evaluate: true,
reduce_vars: true,
}
input: {
function f(a) {
do {
(function() {
a && (c = "PASS");
})();
} while (a = 0);
}
var c = "FAIL";
f(1);
console.log(c);
}
expect: {
function f(a) {
do {
(function() {
a && (c = "PASS");
})();
} while (a = 0);
}
var c = "FAIL";
f(1);
console.log(c);
}
expect_stdout: "PASS"
}