aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-03-26 12:05:44 +0800
committerGitHub <noreply@github.com>2017-03-26 12:05:44 +0800
commit8a4f86528f5b5c3a0ee0a709ed3a6b908706a5c3 (patch)
tree58621ddb70618223ce94af45ec7b9f1fabdf5bf7
parentadb0e882e926249eada4f8f5afaae01aa469face (diff)
downloadtracifyjs-8a4f86528f5b5c3a0ee0a709ed3a6b908706a5c3.tar.gz
tracifyjs-8a4f86528f5b5c3a0ee0a709ed3a6b908706a5c3.zip
fix side-effects detection on switch statements (#1678)
extension of #1675
-rw-r--r--lib/compress.js4
-rw-r--r--test/compress/issue-1673.js32
2 files changed, 36 insertions, 0 deletions
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"
+}