[Pkg-javascript-commits] [uglifyjs] 66/228: fix chained assignment with `unused` (#1540)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:17 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 17b81350d46e369588523b421d4528212f0f3207
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Mar 3 04:45:20 2017 +0800

    fix chained assignment with `unused` (#1540)
    
    When #1450 optimises `a=b=42`, it stops after the first variable even if both are unused.
    
    fixes #1539
---
 lib/compress.js              | 17 ++++++++++-------
 test/compress/drop-unused.js | 21 +++++++++++++++++++++
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index deb55ad..0cc9c51 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1801,14 +1801,17 @@ merge(Compressor.prototype, {
                         }
                         return node;
                     }
-                    if (drop_vars && assign_as_unused
-                        && node instanceof AST_Assign
-                        && node.operator == "="
-                        && node.left instanceof AST_SymbolRef) {
-                        var def = node.left.definition();
-                        if (!(def.id in in_use_ids) && self.variables.get(def.name) === def) {
-                            return node.right;
+                    if (drop_vars && assign_as_unused) {
+                        var n = node;
+                        while (n instanceof AST_Assign
+                            && n.operator == "="
+                            && n.left instanceof AST_SymbolRef) {
+                            var def = n.left.definition();
+                            if (def.id in in_use_ids
+                                || self.variables.get(def.name) !== def) break;
+                            n = n.right;
                         }
+                        if (n !== node) return n;
                     }
                     if (node instanceof AST_For) {
                         descend(node, this);
diff --git a/test/compress/drop-unused.js b/test/compress/drop-unused.js
index c1ca1b5..4b61318 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -679,3 +679,24 @@ const_assign: {
         }
     }
 }
+
+issue_1539: {
+    options = {
+        cascade: true,
+        sequences: true,
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        function f() {
+            var a, b;
+            a = b = 42;
+            return a;
+        }
+    }
+    expect: {
+        function f() {
+            return 42;
+        }
+    }
+}

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