Skip to content

Commit

Permalink
remove expansions from objects when we know the value being expanded …
Browse files Browse the repository at this point in the history
…is nullish. Closes #1004
  • Loading branch information
fabiosantoscode committed Jun 27, 2021
1 parent bfc332c commit 6f04338
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/compress/index.js
Expand Up @@ -7469,7 +7469,7 @@ def_optimize(AST_Array, function(self, compressor) {
return self;
});

function inline_object_prop_spread(props) {
function inline_object_prop_spread(props, compressor) {
for (var i = 0; i < props.length; i++) {
var prop = props[i];
if (prop instanceof AST_Expansion) {
Expand All @@ -7487,6 +7487,9 @@ function inline_object_prop_spread(props) {
// non-iterable value silently does nothing; it is thus safe
// to remove. AST_String is the only iterable AST_Constant.
props.splice(i, 1);
} else if (is_nullish(expr, compressor)) {
// Likewise, null and undefined can be silently removed.
props.splice(i, 1);
}
}
}
Expand All @@ -7497,7 +7500,7 @@ def_optimize(AST_Object, function(self, compressor) {
if (optimized !== self) {
return optimized;
}
inline_object_prop_spread(self.properties);
inline_object_prop_spread(self.properties, compressor);
return self;
});

Expand Down

1 comment on commit 6f04338

@WofWca
Copy link
Contributor

@WofWca WofWca commented on 6f04338 Feb 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests have been added in #1071.

Please sign in to comment.