mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
feat(es/minifier): Remove noop spreads (#6803)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/6788.
This commit is contained in:
parent
b5adb7b842
commit
8f683e3f77
@ -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) {
|
||||
|
@ -0,0 +1,4 @@
|
||||
const foo = { ...(null && {}) };
|
||||
const bar = { ...null };
|
||||
|
||||
console.log(foo, bar);
|
@ -0,0 +1 @@
|
||||
console.log({}, {});
|
Loading…
Reference in New Issue
Block a user