[Pkg-javascript-commits] [uglifyjs] 148/228: fix side-effects detection on switch statements (#1678)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:25 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit 8a4f86528f5b5c3a0ee0a709ed3a6b908706a5c3
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Mar 26 12:05:44 2017 +0800

    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 c57287b..8d8387f 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 59686ab..4628e37 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"
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list