[Pkg-javascript-commits] [uglifyjs] 159/228: `has_side_effects()` should take `AST_Switch.expression` into account (#1699)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:26 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 c526da59a1a9b1a1c5689cfdcc840b36850ed250
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Mon Mar 27 18:09:35 2017 +0800

    `has_side_effects()` should take `AST_Switch.expression` into account (#1699)
    
    fixes #1698
---
 lib/compress.js         |  8 ++++++--
 test/compress/switch.js | 21 +++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 03c8d5d..1146f30 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1610,9 +1610,13 @@ merge(Compressor.prototype, {
         def(AST_Block, function(compressor){
             return any(this.body, compressor);
         });
+        def(AST_Switch, function(compressor){
+            return this.expression.has_side_effects(compressor)
+                || any(this.body, compressor);
+        });
         def(AST_Case, function(compressor){
-            return any(this.body, compressor)
-                || this.expression.has_side_effects(compressor);
+            return this.expression.has_side_effects(compressor)
+                || any(this.body, compressor);
         });
         def(AST_Try, function(compressor){
             return any(this.body, compressor)
diff --git a/test/compress/switch.js b/test/compress/switch.js
index c3e7630..9f9d356 100644
--- a/test/compress/switch.js
+++ b/test/compress/switch.js
@@ -593,3 +593,24 @@ if_switch_typeof: {
         a;
     }
 }
+
+issue_1698: {
+    options = {
+        side_effects: true,
+    }
+    input: {
+        var a = 1;
+        !function() {
+            switch (a++) {}
+        }();
+        console.log(a);
+    }
+    expect: {
+        var a = 1;
+        !function() {
+            switch (a++) {}
+        }();
+        console.log(a);
+    }
+    expect_stdout: "2"
+}

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