[Pkg-javascript-commits] [uglifyjs] 292/491: fix argument/atom collision by `properties` (#2514)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:45 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 c141ae6f8dcfa058f03ae3580275c87b564b77a3
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Nov 25 22:52:46 2017 +0800

    fix argument/atom collision by `properties` (#2514)
    
    fixes #2513
---
 lib/compress.js             | 19 +++++++++++--------
 test/compress/properties.js | 26 ++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 744a1ea..22415f4 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -4708,6 +4708,17 @@ merge(Compressor.prototype, {
         if (compressor.option("properties")) {
             var key = prop.evaluate(compressor);
             if (key !== prop) {
+                if (typeof key == "string") {
+                    if (key == "undefined") {
+                        key = undefined;
+                    } else {
+                        var value = parseFloat(key);
+                        if (value.toString() == key) {
+                            key = value;
+                        }
+                    }
+                }
+                prop = self.property = best_of_expression(prop, make_node_from_constant(key, prop).transform(compressor));
                 var property = "" + key;
                 if (is_identifier_string(property)
                     && property.length <= prop.print_to_string().length + 1) {
@@ -4716,14 +4727,6 @@ merge(Compressor.prototype, {
                         property: property
                     }).optimize(compressor);
                 }
-                if (!(prop instanceof AST_Number)) {
-                    var value = parseFloat(property);
-                    if (value.toString() == property) {
-                        prop = self.property = make_node(AST_Number, prop, {
-                            value: value
-                        });
-                    }
-                }
             }
         }
         if (is_lhs(self, compressor.parent())) return self;
diff --git a/test/compress/properties.js b/test/compress/properties.js
index f2e5932..6d4c028 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -1028,3 +1028,29 @@ new_this: {
         }(42);
     }
 }
+
+issue_2513: {
+    options = {
+        evaluate: true,
+        properties: true,
+    }
+    input: {
+        !function(Infinity, NaN, undefined) {
+            console.log("a"[1/0], "b"["Infinity"]);
+            console.log("c"[0/0], "d"["NaN"]);
+            console.log("e"[void 0], "f"["undefined"]);
+        }(0, 0, 0);
+    }
+    expect: {
+        !function(Infinity, NaN, undefined) {
+            console.log("a"[1/0], "b"[1/0]);
+            console.log("c".NaN, "d".NaN);
+            console.log("e"[void 0], "f"[void 0]);
+        }(0, 0, 0);
+    }
+    expect_stdout: [
+        "undefined undefined",
+        "undefined undefined",
+        "undefined undefined",
+    ]
+}

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