aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-08-21 01:05:10 +0100
committerGitHub <noreply@github.com>2020-08-21 08:05:10 +0800
commitaa83ecdb3b1ab4c50cb8347b559e13c3dcf8b343 (patch)
treeeca262c51319b60e7dfbd640ccf81cbc4d5a7744
parenta153176469d49b851b884b96261f01ea8026ba82 (diff)
downloadtracifyjs-aa83ecdb3b1ab4c50cb8347b559e13c3dcf8b343.tar.gz
tracifyjs-aa83ecdb3b1ab4c50cb8347b559e13c3dcf8b343.zip
fix corner case in `switches` (#4060)
fixes #4059
-rw-r--r--lib/compress.js5
-rw-r--r--test/compress/switch.js31
2 files changed, 34 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 8bc8b37e..f15776c8 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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;
}
diff --git a/test/compress/switch.js b/test/compress/switch.js
index 83bc40f5..e3f6859d 100644
--- a/test/compress/switch.js
+++ b/test/compress/switch.js
@@ -1150,3 +1150,34 @@ drop_switch_8: {
(C !== D ? y : z)();
}
}
+
+issue_4059: {
+ options = {
+ conditionals: true,
+ dead_code: true,
+ evaluate: true,
+ switches: true,
+ }
+ input: {
+ switch (0) {
+ default:
+ case 1:
+ break;
+ case a:
+ break;
+ var a;
+ }
+ console.log("PASS");
+ }
+ expect: {
+ switch (0) {
+ default:
+ break;
+ case a:
+ break;
+ var a;
+ }
+ console.log("PASS");
+ }
+ expect_stdout: "PASS"
+}