From c8fa225cb4241d68c51a43f311720d73af0eb390 Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Thu, 16 Sep 2021 16:16:10 -0400 Subject: [PATCH] Fix inlining object spread properties (#1071) --- lib/compress/index.js | 2 ++ test/compress/expansions.js | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/compress/index.js b/lib/compress/index.js index 4c393151b..7c62c8235 100644 --- a/lib/compress/index.js +++ b/lib/compress/index.js @@ -4335,9 +4335,11 @@ function inline_object_prop_spread(props, compressor) { // non-iterable value silently does nothing; it is thus safe // to remove. AST_String is the only iterable AST_Constant. props.splice(i, 1); + i--; } else if (is_nullish(expr, compressor)) { // Likewise, null and undefined can be silently removed. props.splice(i, 1); + i--; } } } diff --git a/test/compress/expansions.js b/test/compress/expansions.js index ca651efdc..af90f0935 100644 --- a/test/compress/expansions.js +++ b/test/compress/expansions.js @@ -103,6 +103,31 @@ object_spread: { ] } +object_spread_nullish_undefined: { + input: { + let o = { ...undefined, ...{a: true} } + id(o); + } + + expect: { + let o = {a: true}; + id(o) + } +} + +object_spread_nullish_null: { + input: { + let o = { ...null, ...{a: true} } + id(o); + } + + expect: { + let o = {a: true}; + id(o) + } +} + + avoid_spread_hole: { input: { let x = [...[,]]