From 71c3639a8d7bcc9efdb01466e9f257cf65482716 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 23 Aug 2021 17:53:31 -0400 Subject: [PATCH] Remove useless branch check The branch can't be the default, because it would have already been handled by the switch removal code. --- lib/compress/index.js | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/lib/compress/index.js b/lib/compress/index.js index ceb43eba0..10efba64d 100644 --- a/lib/compress/index.js +++ b/lib/compress/index.js @@ -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]; @@ -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;