Skip to content

Commit

Permalink
feat(es/minifier): Remove noop spreads (#6803)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #6788.
  • Loading branch information
kdy1 committed Jan 13, 2023
1 parent b5adb7b commit 8f683e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/swc_ecma_minifier/src/compress/pure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions crates/swc_ecma_minifier/tests/pass-1/issue-6788/1/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const foo = { ...(null && {}) };
const bar = { ...null };

console.log(foo, bar);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log({}, {});

0 comments on commit 8f683e3

Please sign in to comment.