aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-04-30 15:21:15 +0100
committerGitHub <noreply@github.com>2021-04-30 22:21:15 +0800
commit8e4a19ffec0506c25aebb05e2c84ec32ff307642 (patch)
treea038cd39f9becc9b3b80674ee2645ea1ce8c08bd /lib/compress.js
parentd833e66d23cab3c9c03a99a9cf118647bf862868 (diff)
downloadtracifyjs-8e4a19ffec0506c25aebb05e2c84ec32ff307642.tar.gz
tracifyjs-8e4a19ffec0506c25aebb05e2c84ec32ff307642.zip
fix corner case in `spreads` (#4883)
fixes #4882
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 384e0e89..ce126c80 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -11649,13 +11649,23 @@ merge(Compressor.prototype, {
found = true;
var exp = prop.expression;
if (compressor.option("spreads") && exp instanceof AST_Object && all(exp.properties, function(prop) {
- return !(prop instanceof AST_ObjectGetter || prop instanceof AST_Spread);
+ if (prop instanceof AST_ObjectGetter) return false;
+ if (prop instanceof AST_Spread) return false;
+ if (prop.key !== "__proto__") return true;
+ if (prop instanceof AST_ObjectSetter) return true;
+ return !prop.value.has_side_effects(compressor);
})) {
changed = true;
exp.properties.forEach(function(prop) {
- process(prop instanceof AST_ObjectSetter ? make_node(AST_ObjectKeyVal, prop, {
- key: prop.key,
- value: make_node(AST_Undefined, prop).optimize(compressor)
+ var key = prop.key;
+ var setter = prop instanceof AST_ObjectSetter;
+ if (key === "__proto__") {
+ if (!setter) return;
+ key = make_node_from_constant(key, prop);
+ }
+ process(setter ? make_node(AST_ObjectKeyVal, prop, {
+ key: key,
+ value: make_node(AST_Undefined, prop).optimize(compressor),
}) : prop);
});
} else {
@@ -11695,7 +11705,7 @@ merge(Compressor.prototype, {
if (key instanceof AST_Node) {
found = true;
key = key.evaluate(compressor);
- if (key === prop.key) {
+ if (key === prop.key || key === "__proto__") {
generated = true;
} else {
key = prop.key = "" + key;
@@ -11711,9 +11721,7 @@ merge(Compressor.prototype, {
if (found && !generated && typeof key == "string" && RE_POSITIVE_INTEGER.test(key)) {
generated = true;
if (keys.has(key)) prop = keys.get(key)[0];
- prop.key = make_node(AST_Number, prop, {
- value: +key
- });
+ prop.key = make_node(AST_Number, prop, { value: +key });
}
}
});