[Pkg-javascript-commits] [uglifyjs] 451/491: drop assignments to constant expressions only (#2839)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:52:03 UTC 2018


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

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit ec4202590d040942639e01eb8ae83bf7be7180dd
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Jan 23 02:49:54 2018 +0800

    drop assignments to constant expressions only (#2839)
    
    fixes #2838
---
 lib/compress.js               |  6 ++++--
 test/compress/pure_getters.js | 27 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 2803b85..a8fa0e1 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3469,8 +3469,10 @@ merge(Compressor.prototype, {
             while (left instanceof AST_PropAccess) {
                 left = left.expression;
             }
-            if (left instanceof AST_Symbol) return this;
-            return this.right.drop_side_effect_free(compressor);
+            if (left.is_constant_expression(compressor.find_parent(AST_Scope))) {
+                return this.right.drop_side_effect_free(compressor);
+            }
+            return this;
         });
         def(AST_Conditional, function(compressor){
             var consequent = this.consequent.drop_side_effect_free(compressor);
diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js
index 80b0e8e..4e9ae4f 100644
--- a/test/compress/pure_getters.js
+++ b/test/compress/pure_getters.js
@@ -694,3 +694,30 @@ issue_2678: {
     }
     expect_stdout: "PASS"
 }
+
+issue_2838: {
+    options = {
+        pure_getters: true,
+        side_effects: true,
+    }
+    input: {
+        function f(a, b) {
+            (a || b).c = "PASS";
+            (function() {
+                return f(a, b);
+            }).prototype.foo = "bar";
+        }
+        var o = {};
+        f(null, o);
+        console.log(o.c);
+    }
+    expect: {
+        function f(a, b) {
+            (a || b).c = "PASS";
+        }
+        var o = {};
+        f(null, o);
+        console.log(o.c);
+    }
+    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