From 549de028b664d565b237ab2c4f79c5ae2f64b1ad Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 15 Dec 2020 13:23:55 +0000 Subject: [PATCH] fix corner case in `objects` (#4381) fixes #4380 --- lib/compress.js | 1 + test/compress/objects.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index 3e70f2eb..fb5bcb74 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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 }); diff --git a/test/compress/objects.js b/test/compress/objects.js index 5e59726d..a02dd084 100644 --- a/test/compress/objects.js +++ b/test/compress/objects.js @@ -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" +} -- 2.34.1