[Pkg-javascript-commits] [uglifyjs] 445/491: avoid duplicate property names in object literals under "use strict" (#2818)

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 e21bab7ce65e6a4db0ea966b3336eaab2a634e6e
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Jan 19 20:13:50 2018 +0800

    avoid duplicate property names in object literals under "use strict" (#2818)
    
    fixes #2816
---
 lib/compress.js             | 12 +++++++++---
 test/compress/properties.js | 27 +++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index bda5d7a..00593e8 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -893,7 +893,7 @@ merge(Compressor.prototype, {
                 sequencesize_2(statements, compressor);
             }
             if (compressor.option("join_vars")) {
-                join_consecutive_vars(statements, compressor);
+                join_consecutive_vars(statements);
             }
             if (compressor.option("collapse_vars")) {
                 collapse(statements, compressor);
@@ -1746,8 +1746,14 @@ merge(Compressor.prototype, {
                     prop = prop.evaluate(compressor);
                 }
                 if (prop instanceof AST_Node) break;
+                prop = "" + prop;
+                if (compressor.has_directive("use strict")) {
+                    if (!all(def.value.properties, function(node) {
+                        return node.key != prop && node.key.name != prop;
+                    })) break;
+                }
                 def.value.properties.push(make_node(AST_ObjectKeyVal, node, {
-                    key: "" + prop,
+                    key: prop,
                     value: node.right
                 }));
                 exprs.shift();
@@ -1756,7 +1762,7 @@ merge(Compressor.prototype, {
             return trimmed && exprs;
         }
 
-        function join_consecutive_vars(statements, compressor) {
+        function join_consecutive_vars(statements) {
             var defs;
             for (var i = 0, j = -1, len = statements.length; i < len; i++) {
                 var stat = statements[i];
diff --git a/test/compress/properties.js b/test/compress/properties.js
index 53684da..dbc7bf2 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -1561,3 +1561,30 @@ join_object_assignments_regex: {
     }
     expect_stdout: "1"
 }
+
+issue_2816: {
+    options = {
+        join_vars: true,
+    }
+    input: {
+        "use strict";
+        var o = {
+            a: 1
+        };
+        o.b = 2;
+        o.a = 3;
+        o.c = 4;
+        console.log(o.a, o.b, o.c);
+    }
+    expect: {
+        "use strict";
+        var o = {
+            a: 1,
+            b: 2
+        };
+        o.a = 3;
+        o.c = 4;
+        console.log(o.a, o.b, o.c);
+    }
+    expect_stdout: "3 2 4"
+}

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