feat(es/minifier): Remove noop spreads (#6803)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6788.
This commit is contained in:
Donny/강동윤 2023-01-13 15:55:04 +09:00 committed by GitHub
parent b5adb7b842
commit 8f683e3f77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -12,6 +12,7 @@ use swc_ecma_visit::{noop_visit_mut_type, VisitMut, VisitMutWith, VisitWith};
use tracing::{debug, span, Level};
use self::{ctx::Ctx, misc::DropOpts};
use super::util::is_pure_undefined_or_null;
#[cfg(feature = "debug")]
use crate::debug::dump;
use crate::{
@ -760,6 +761,16 @@ impl VisitMut for Pure<'_> {
fn visit_mut_prop_or_spreads(&mut self, exprs: &mut Vec<PropOrSpread>) {
self.visit_par(exprs);
exprs.retain(|e| {
if let PropOrSpread::Spread(spread) = e {
if is_pure_undefined_or_null(&self.expr_ctx, &spread.expr) {
return false;
}
}
true
})
}
fn visit_mut_return_stmt(&mut self, s: &mut ReturnStmt) {

View File

@ -0,0 +1,4 @@
const foo = { ...(null && {}) };
const bar = { ...null };
console.log(foo, bar);

View File

@ -0,0 +1 @@
console.log({}, {});