From 8a4f86528f5b5c3a0ee0a709ed3a6b908706a5c3 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 26 Mar 2017 12:05:44 +0800 Subject: [PATCH] fix side-effects detection on switch statements (#1678) extension of #1675 --- lib/compress.js | 4 ++++ test/compress/issue-1673.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index c57287bf..8d8387f2 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1610,6 +1610,10 @@ merge(Compressor.prototype, { def(AST_Block, function(compressor){ return any(this.body, compressor); }); + def(AST_Case, function(compressor){ + return any(this.body, compressor) + || this.expression.has_side_effects(compressor); + }); def(AST_Try, function(compressor){ return any(this.body, compressor) || this.bcatch && this.bcatch.has_side_effects(compressor) diff --git a/test/compress/issue-1673.js b/test/compress/issue-1673.js index 59686abf..4628e37c 100644 --- a/test/compress/issue-1673.js +++ b/test/compress/issue-1673.js @@ -125,3 +125,35 @@ side_effects_label: { } expect_stdout: "PASS" } + +side_effects_switch: { + options = { + reduce_vars: true, + side_effects: true, + unused: true, + } + input: { + function f() { + function g() { + switch (0) { + default: + case console.log("PASS"): + } + } + g(); + } + f(); + } + expect: { + function f() { + (function() { + switch (0) { + default: + case console.log("PASS"): + } + })(); + } + f(); + } + expect_stdout: "PASS" +} -- 2.34.1