From 6f0433879ca1b5358c1140903ac6b5e071c962a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Santos?= Date: Sun, 27 Jun 2021 14:38:07 +0100 Subject: [PATCH] remove expansions from objects when we know the value being expanded is nullish. Closes #1004 --- lib/compress/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/compress/index.js b/lib/compress/index.js index 80a0f615e..9c0fb5f2c 100644 --- a/lib/compress/index.js +++ b/lib/compress/index.js @@ -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) { @@ -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); } } } @@ -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; });