fix corner case in `objects` (#4416)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 19 Dec 2020 16:14:57 +0000 (16:14 +0000)
committerGitHub <noreply@github.com>
Sat, 19 Dec 2020 16:14:57 +0000 (00:14 +0800)
fixes #4415

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

index 1aab368..5081120 100644 (file)
@@ -10198,7 +10198,7 @@ merge(Compressor.prototype, {
                 flush();
                 values.push(prop);
             }
-            if (found && !generated && typeof key == "string" && /^[0-9]+$/.test(key)) {
+            if (found && !generated && typeof key == "string" && /^[1-9]*[0-9]$/.test(key)) {
                 generated = true;
                 if (keys.has(key)) prop = keys.get(key)[0];
                 prop.key = make_node(AST_Number, prop, {
index a02dd08..d35f153 100644 (file)
@@ -413,3 +413,22 @@ issue_4380: {
     expect_stdout: "PASS"
     node_version: ">=4"
 }
+
+issue_4415: {
+    options = {
+        evaluate: true,
+        objects: true,
+    }
+    input: {
+        console.log({
+            ["00"]: "FAIL",
+        }[0] || "PASS");
+    }
+    expect: {
+        console.log({
+            "00": "FAIL",
+        }[0] || "PASS");
+    }
+    expect_stdout: "PASS"
+    node_version: ">=4"
+}