Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inlining object spread properties #1071

Merged
merged 1 commit into from Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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