[Pkg-javascript-commits] [uglifyjs] 414/491: fix corner case in #2763 (#2766)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:58 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 23ec484806e1ed1cc7c2580abbd3ff050367b358
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Jan 11 21:18:08 2018 +0800

    fix corner case in #2763 (#2766)
---
 lib/compress.js             | 21 +++++++++------------
 test/compress/properties.js | 26 ++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index b093832..8687317 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1698,6 +1698,8 @@ merge(Compressor.prototype, {
 
         function join_object_assignments(defn, body) {
             if (!(defn instanceof AST_Definitions)) return;
+            var def = defn.definitions[defn.definitions.length - 1];
+            if (!(def.value instanceof AST_Object)) return;
             var exprs;
             if (body instanceof AST_Assign) {
                 exprs = [ body ];
@@ -1705,17 +1707,14 @@ merge(Compressor.prototype, {
                 exprs = body.expressions.slice();
             }
             if (!exprs) return;
+            var trimmed = false;
             do {
                 var node = exprs[0];
                 if (!(node instanceof AST_Assign)) break;
                 if (!(node.left instanceof AST_PropAccess)) break;
                 var sym = node.left.expression;
                 if (!(sym instanceof AST_SymbolRef)) break;
-                var def = find_if(function(def) {
-                    return def.name.name == sym.name
-                        && def.value instanceof AST_Object;
-                }, defn.definitions);
-                if (!def) break;
+                if (def.name.name != sym.name) break;
                 if (!node.right.is_constant_expression(scope)) break;
                 var prop = node.left.property;
                 if (prop instanceof AST_Node) {
@@ -1727,8 +1726,9 @@ merge(Compressor.prototype, {
                     value: node.right
                 }));
                 exprs.shift();
+                trimmed = true;
             } while (exprs.length);
-            return exprs;
+            return trimmed && exprs;
         }
 
         function join_consecutive_vars(statements, compressor) {
@@ -1766,14 +1766,11 @@ merge(Compressor.prototype, {
                 } else if (stat instanceof AST_SimpleStatement) {
                     var exprs = join_object_assignments(prev, stat.body);
                     if (exprs) {
-                        if (exprs.length > 0) {
-                            stat.body = make_sequence(stat.body, exprs);
-                            statements[++j] = stat;
-                        }
                         CHANGED = true;
-                    } else {
-                        statements[++j] = stat;
+                        if (!exprs.length) continue;
+                        stat.body = make_sequence(stat.body, exprs);
                     }
+                    statements[++j] = stat;
                 } else {
                     statements[++j] = stat;
                 }
diff --git a/test/compress/properties.js b/test/compress/properties.js
index d70eb85..6b368e6 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -1162,3 +1162,29 @@ join_object_assignments_2: {
     }
     expect_stdout: "1 4 6"
 }
+
+join_object_assignments_3: {
+    options = {
+        evaluate: true,
+        join_vars: true,
+    }
+    input: {
+        console.log(function() {
+            var o = {
+                a: "PASS",
+            }, a = o.a;
+            o.a = "FAIL";
+            return a;
+        }());
+    }
+    expect: {
+        console.log(function() {
+            var o = {
+                a: "PASS",
+            }, a = o.a;
+            o.a = "FAIL";
+            return a;
+        }());
+    }
+    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