extend keep_quoted_props over numeric keys (#5094)

fixes #5093
This commit is contained in:
Alex Lam S.L
2021-07-21 23:12:57 +01:00
committed by GitHub
parent 7fac839c62
commit 65adeba55d
2 changed files with 59 additions and 19 deletions

View File

@@ -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) {