fix corner case in switches (#4060)

fixes #4059
This commit is contained in:
Alex Lam S.L
2020-08-21 01:05:10 +01:00
committed by GitHub
parent a153176469
commit aa83ecdb3b
2 changed files with 34 additions and 2 deletions

View File

@@ -5918,7 +5918,7 @@ merge(Compressor.prototype, {
self.body = body;
if (compressor.option("conditionals")) switch (body.length) {
case 1:
if (!no_break(self)) break;
if (!no_break(body[0])) break;
var exp = body[0].expression;
var statements = body[0].body.slice();
if (body[0] !== default_branch && body[0] !== exact_match) return make_node(AST_If, self, {
@@ -5942,7 +5942,7 @@ merge(Compressor.prototype, {
body: statements,
}).optimize(compressor);
case 2:
if (!member(default_branch, body)) break;
if (!member(default_branch, body) || !no_break(body[1])) break;
var statements = body[0].body.slice();
var exclusive = statements.length && is_break(statements[statements.length - 1], compressor);
if (exclusive) statements.pop();
@@ -5982,6 +5982,7 @@ merge(Compressor.prototype, {
|| node instanceof AST_SimpleStatement) return true;
if (is_break(node, tw)) found = true;
});
tw.push(self);
node.walk(tw);
return !found;
}