Skip to content

Commit

Permalink
extend keep_quoted_props over numeric keys (#5094)
Browse files Browse the repository at this point in the history
fixes #5093
  • Loading branch information
alexlamsl committed Jul 21, 2021
1 parent 7fac839 commit 65adeba
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
31 changes: 12 additions & 19 deletions lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
47 changes: 47 additions & 0 deletions test/compress/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 65adeba

Please sign in to comment.