aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-19 16:14:57 +0000
committerGitHub <noreply@github.com>2020-12-20 00:14:57 +0800
commitacc2d7d8455ed7302a78948b3c8678990dc1765a (patch)
tree071b26ecb6ba8456171c9b550a0582d8056a9129
parent9a5aede94147bf5769054fd933b1c15690915d25 (diff)
downloadtracifyjs-acc2d7d8455ed7302a78948b3c8678990dc1765a.tar.gz
tracifyjs-acc2d7d8455ed7302a78948b3c8678990dc1765a.zip
fix corner case in `objects` (#4416)
fixes #4415
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/objects.js19
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 1aab3680..5081120c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -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, {
diff --git a/test/compress/objects.js b/test/compress/objects.js
index a02dd084..d35f1538 100644
--- a/test/compress/objects.js
+++ b/test/compress/objects.js
@@ -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"
+}