diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-07-21 23:12:57 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-22 06:12:57 +0800 |
commit | 65adeba55da7eb39daaa21044523141490effd6f (patch) | |
tree | ed26182d436033a9dd9332b87fe39b6ae5d00ae3 | |
parent | 7fac839c62ef4881d3132e45aa9a18e30d7a3932 (diff) | |
download | tracifyjs-65adeba55da7eb39daaa21044523141490effd6f.tar.gz tracifyjs-65adeba55da7eb39daaa21044523141490effd6f.zip |
extend `keep_quoted_props` over numeric keys (#5094)
fixes #5093
-rw-r--r-- | lib/output.js | 31 | ||||
-rw-r--r-- | test/compress/properties.js | 47 |
2 files changed, 59 insertions, 19 deletions
diff --git a/lib/output.js b/lib/output.js index afc89055..0cf379dd 100644 --- a/lib/output.js +++ b/lib/output.js @@ -1690,28 +1690,21 @@ function OutputStream(options) { function print_property_key(self, output) { var key = self.key; - if (key instanceof AST_Node) { - output.with_square(function() { - key.print(output); - }); - } else if (output.option("quote_keys")) { - output.print_string(key); + if (key instanceof AST_Node) return output.with_square(function() { + key.print(output); + }); + var quote = self.start && self.start.quote; + if (output.option("quote_keys") || quote && output.option("keep_quoted_props")) { + output.print_string(key, quote); } else if ("" + +key == key && key >= 0) { output.print(make_num(key)); + } else if (self.private) { + output.print_name(key); + } else if (RESERVED_WORDS[key] ? !output.option("ie") : is_identifier_string(key)) { + output.print_name(key); + return key; } else { - var quote = self.start && self.start.quote; - if (self.private) { - output.print_name(key); - } else if (RESERVED_WORDS[key] ? !output.option("ie") : is_identifier_string(key)) { - if (quote && output.option("keep_quoted_props")) { - output.print_string(key, quote); - } else { - output.print_name(key); - return key; - } - } else { - output.print_string(key, quote); - } + output.print_string(key, quote); } } DEFPRINT(AST_ObjectKeyVal, function(output) { diff --git a/test/compress/properties.js b/test/compress/properties.js index 929c444e..fb0db99e 100644 --- a/test/compress/properties.js +++ b/test/compress/properties.js @@ -1463,3 +1463,50 @@ issue_4888: { } expect_stdout: "object" } + +issue_5093: { + beautify = { + keep_quoted_props: true, + } + input: { + console.log({ + a: true, + '42': "PASS", + "null": [], + }[6 * 7]); + } + expect_exact: 'console.log({a:true,"42":"PASS","null":[]}[6*7]);' + expect_stdout: "PASS" +} + +issue_5093_quote_keys: { + beautify = { + keep_quoted_props: true, + quote_keys: true, + } + input: { + console.log({ + a: true, + '42': "PASS", + "null": [], + }[6 * 7]); + } + expect_exact: 'console.log({"a":true,"42":"PASS","null":[]}[6*7]);' + expect_stdout: "PASS" +} + +issue_5093_quote_style: { + beautify = { + keep_quoted_props: true, + quote_style: 3, + } + input: { + console.log({ + a: true, + '42': "PASS", + "null": [], + }[6 * 7]); + } + expect_exact: 'console.log({a:true,\'42\':"PASS","null":[]}[6*7]);' + expect_stdout: "PASS" +} |