fix corner case in `objects` (#4381)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 15 Dec 2020 13:23:55 +0000 (13:23 +0000)
committerGitHub <noreply@github.com>
Tue, 15 Dec 2020 13:23:55 +0000 (21:23 +0800)
fixes #4380

lib/compress.js
test/compress/objects.js

index 3e70f2e..fb5bcb7 100644 (file)
@@ -10118,6 +10118,7 @@ merge(Compressor.prototype, {
             }
             if (found && !generated && typeof key == "string" && /^[0-9]+$/.test(key)) {
                 generated = true;
+                if (keys.has(key)) prop = keys.get(key)[0];
                 prop.key = make_node(AST_Number, prop, {
                     value: +key
                 });
index 5e59726..a02dd08 100644 (file)
@@ -387,3 +387,29 @@ issue_4269_5: {
     expect_stdout: "PASS"
     node_version: ">=4"
 }
+
+issue_4380: {
+    options = {
+        evaluate: true,
+        objects: true,
+    }
+    input: {
+        console.log({
+            get 0() {
+                return "FAIL 1";
+            },
+            0: "FAIL 2",
+            [0]: "PASS",
+        }[0]);
+    }
+    expect: {
+        console.log({
+            get 0() {
+                return "FAIL 1";
+            },
+            [0]: ("FAIL 2", "PASS"),
+        }[0]);
+    }
+    expect_stdout: "PASS"
+    node_version: ">=4"
+}