Skip to content

Commit

Permalink
Remove useless branch check
Browse files Browse the repository at this point in the history
The branch can't be the default, because it would have already been handled by the switch removal code.
  • Loading branch information
jridgewell committed Aug 23, 2021
1 parent 804e52f commit 71c3639
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions lib/compress/index.js
Expand Up @@ -1770,27 +1770,17 @@ def_optimize(AST_Switch, function(self, compressor) {
// This is the last case body, and we've already pruned any breaks, so it's
// safe to hoist.
let branch = body[0];
if (branch === default_or_exact) {
let statements = [statement(self.expression)];
if (branch.expression) {
statements.push(statement(branch.expression));
}
return make_node(AST_BlockStatement, branch, {
body: statements.concat(branch.body)
}).optimize(compressor);
} else {
return make_node(AST_If, self, {
condition: make_node(AST_Binary, self, {
operator: "===",
left: self.expression,
right: branch.expression,
}),
body: make_node(AST_BlockStatement, branch, {
body: branch.body
}),
alternative: null
}).optimize(compressor);
}
return make_node(AST_If, self, {
condition: make_node(AST_Binary, self, {
operator: "===",
left: self.expression,
right: branch.expression,
}),
body: make_node(AST_BlockStatement, branch, {
body: branch.body
}),
alternative: null
}).optimize(compressor);
}
if (body.length === 2 && default_or_exact && !has_nested_break(self)) {
let branch = body[0] === default_or_exact ? body[1] : body[0];
Expand Down Expand Up @@ -1892,7 +1882,6 @@ def_optimize(AST_Switch, function(self, compressor) {
root.walk(tw);
return has_break;
}

function is_break(node, stack) {
return node instanceof AST_Break
&& stack.loopcontrol_target(node) === self;
Expand Down

0 comments on commit 71c3639

Please sign in to comment.