Skip to content

Commit 65adeba

Browse files
authored
extend keep_quoted_props over numeric keys (#5094)
fixes #5093
1 parent 7fac839 commit 65adeba

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

lib/output.js

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,28 +1690,21 @@ function OutputStream(options) {
16901690

16911691
function print_property_key(self, output) {
16921692
var key = self.key;
1693-
if (key instanceof AST_Node) {
1694-
output.with_square(function() {
1695-
key.print(output);
1696-
});
1697-
} else if (output.option("quote_keys")) {
1698-
output.print_string(key);
1693+
if (key instanceof AST_Node) return output.with_square(function() {
1694+
key.print(output);
1695+
});
1696+
var quote = self.start && self.start.quote;
1697+
if (output.option("quote_keys") || quote && output.option("keep_quoted_props")) {
1698+
output.print_string(key, quote);
16991699
} else if ("" + +key == key && key >= 0) {
17001700
output.print(make_num(key));
1701+
} else if (self.private) {
1702+
output.print_name(key);
1703+
} else if (RESERVED_WORDS[key] ? !output.option("ie") : is_identifier_string(key)) {
1704+
output.print_name(key);
1705+
return key;
17011706
} else {
1702-
var quote = self.start && self.start.quote;
1703-
if (self.private) {
1704-
output.print_name(key);
1705-
} else if (RESERVED_WORDS[key] ? !output.option("ie") : is_identifier_string(key)) {
1706-
if (quote && output.option("keep_quoted_props")) {
1707-
output.print_string(key, quote);
1708-
} else {
1709-
output.print_name(key);
1710-
return key;
1711-
}
1712-
} else {
1713-
output.print_string(key, quote);
1714-
}
1707+
output.print_string(key, quote);
17151708
}
17161709
}
17171710
DEFPRINT(AST_ObjectKeyVal, function(output) {

test/compress/properties.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,3 +1463,50 @@ issue_4888: {
14631463
}
14641464
expect_stdout: "object"
14651465
}
1466+
1467+
issue_5093: {
1468+
beautify = {
1469+
keep_quoted_props: true,
1470+
}
1471+
input: {
1472+
console.log({
1473+
a: true,
1474+
'42': "PASS",
1475+
"null": [],
1476+
}[6 * 7]);
1477+
}
1478+
expect_exact: 'console.log({a:true,"42":"PASS","null":[]}[6*7]);'
1479+
expect_stdout: "PASS"
1480+
}
1481+
1482+
issue_5093_quote_keys: {
1483+
beautify = {
1484+
keep_quoted_props: true,
1485+
quote_keys: true,
1486+
}
1487+
input: {
1488+
console.log({
1489+
a: true,
1490+
'42': "PASS",
1491+
"null": [],
1492+
}[6 * 7]);
1493+
}
1494+
expect_exact: 'console.log({"a":true,"42":"PASS","null":[]}[6*7]);'
1495+
expect_stdout: "PASS"
1496+
}
1497+
1498+
issue_5093_quote_style: {
1499+
beautify = {
1500+
keep_quoted_props: true,
1501+
quote_style: 3,
1502+
}
1503+
input: {
1504+
console.log({
1505+
a: true,
1506+
'42': "PASS",
1507+
"null": [],
1508+
}[6 * 7]);
1509+
}
1510+
expect_exact: 'console.log({a:true,\'42\':"PASS","null":[]}[6*7]);'
1511+
expect_stdout: "PASS"
1512+
}

0 commit comments

Comments
 (0)