aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-06 05:59:04 +0000
committerGitHub <noreply@github.com>2020-12-06 13:59:04 +0800
commit37f4f56752e0672ff8b76b1618266eae628088f7 (patch)
tree2f6dd45755f12c56456049d8ff6bf50d2be59942 /lib
parent1e4985ed9e0822118ad01313af09008af1e9f036 (diff)
downloadtracifyjs-37f4f56752e0672ff8b76b1618266eae628088f7.tar.gz
tracifyjs-37f4f56752e0672ff8b76b1618266eae628088f7.zip
fix corner case in `properties` (#4330)
fixes #4329
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js
index a78cf6ef..82474b5c 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -9689,13 +9689,26 @@ merge(Compressor.prototype, {
});
});
+ function is_integer(key) {
+ return /^[0-9]+$/.test(key);
+ }
+
OPT(AST_Spread, function(self, compressor) {
if (compressor.option("properties")) {
var exp = self.expression;
if (compressor.parent() instanceof AST_Object) {
if (exp instanceof AST_Object && all(exp.properties, function(node) {
return node instanceof AST_ObjectKeyVal;
- })) return List.splice(exp.properties);
+ })) return List.splice(exp.properties.map(function(node) {
+ var key = node.key;
+ if (!(key instanceof AST_Node) && is_integer(key)) {
+ node = node.clone();
+ node.key = make_node(AST_Number, node, {
+ value: +key
+ });
+ }
+ return node;
+ }));
} else if (exp instanceof AST_Array) return List.splice(exp.elements.map(function(node) {
return node instanceof AST_Hole ? make_node(AST_Undefined, node).optimize(compressor) : node;
}));
@@ -9971,7 +9984,7 @@ merge(Compressor.prototype, {
var prop = self.properties[i];
var key = prop.key;
if (key instanceof AST_Node) key = key.evaluate(compressor);
- if (typeof key != "string" || /[0-9]+/.test(key)) break;
+ if (is_integer(key)) break;
if (key !== prop.key) prop.key = "" + key;
}
var keys = new Dictionary();