[Pkg-javascript-commits] [uglifyjs] 149/228: suppress switch branch de-duplication upon side effects (#1682)

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 94f84727ce454c3ecf5206ac79dba4a21ec6deb6
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Mar 26 13:32:43 2017 +0800

    suppress switch branch de-duplication upon side effects (#1682)
    
    fixes #1679
---
 lib/compress.js         |  4 +++-
 test/compress/switch.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 8d8387f..8d1ef8a 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2551,12 +2551,14 @@ merge(Compressor.prototype, {
                     } else {
                         body.push(branch);
                     }
-                    blocks[key] = branch;
                     fallthrough = false;
                 } else {
                     body.push(branch);
                     fallthrough = true;
                 }
+                if (branch instanceof AST_Case && branch.expression.has_side_effects(compressor))
+                    blocks = Object.create(null);
+                if (!fallthrough) blocks[key] = branch;
             }
             for (; i < len && fallthrough; i++) {
                 branch = self.body[i];
diff --git a/test/compress/switch.js b/test/compress/switch.js
index 7d3d7d1..481257a 100644
--- a/test/compress/switch.js
+++ b/test/compress/switch.js
@@ -434,3 +434,50 @@ issue_1674: {
     }
     expect_stdout: "PASS"
 }
+
+issue_1679: {
+    options = {
+        dead_code: true,
+        evaluate: true,
+    }
+    input: {
+        var a = 100, b = 10;
+        function f() {
+            switch (--b) {
+              default:
+              case !function x() {}:
+                break;
+              case b--:
+                switch (0) {
+                  default:
+                  case a--:
+                }
+                break;
+              case (a++):
+                break;
+            }
+        }
+        f();
+        console.log(a, b);
+    }
+    expect: {
+        var a = 100, b = 10;
+        function f() {
+            switch (--b) {
+              default:
+              case !function x() {}:
+                break;
+              case b--:
+                switch (0) {
+                  default:
+                  case a--:
+                }
+                break;
+              case (a++):
+            }
+        }
+        f();
+        console.log(a, b);
+    }
+    expect_stdout: true
+}

-- 
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