[Pkg-javascript-commits] [uglifyjs] 97/228: scan RHS of dropped assignments (#1581)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:20 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 7e465d4a01f2cbcae24e1c60ee96969c14130287
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Mar 9 05:22:27 2017 +0800

    scan RHS of dropped assignments (#1581)
    
    - similar case as #1578 but against #1450 instead
    - fix `this` binding in #1450 as well
    
    closes #1580
---
 lib/compress.js              | 18 ++++++++----------
 test/compress/drop-unused.js | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 302f8f5..f6b76ec 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1901,17 +1901,15 @@ merge(Compressor.prototype, {
                         }
                         return node;
                     }
-                    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 (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 maintain_this_binding(tt.parent(), node, node.right.transform(tt));
                         }
-                        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 9c96056..728557a 100644
--- a/test/compress/drop-unused.js
+++ b/test/compress/drop-unused.js
@@ -725,3 +725,39 @@ vardef_value: {
         }
     }
 }
+
+assign_binding: {
+    options = {
+        cascade: true,
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        function f() {
+            var a;
+            a = f.g, a();
+        }
+    }
+    expect: {
+        function f() {
+            (0, f.g)();
+        }
+    }
+}
+
+assign_chain: {
+    options = {
+        unused: true,
+    }
+    input: {
+        function f() {
+            var a, b;
+            x = a = y = b = 42;
+        }
+    }
+    expect: {
+        function f() {
+            x = y = 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