Skip to content

Commit

Permalink
Fix inlining object spread properties (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Sep 16, 2021
1 parent c4fcdcc commit c8fa225
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/compress/index.js
Expand Up @@ -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--;
}
}
}
Expand Down
25 changes: 25 additions & 0 deletions test/compress/expansions.js
Expand Up @@ -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 = [...[,]]
Expand Down

0 comments on commit c8fa225

Please sign in to comment.