diff --git a/crates/oxc_minifier/src/peephole/remove_dead_code.rs b/crates/oxc_minifier/src/peephole/remove_dead_code.rs index 5710b1d1e70a0..c07f84cf92e52 100644 --- a/crates/oxc_minifier/src/peephole/remove_dead_code.rs +++ b/crates/oxc_minifier/src/peephole/remove_dead_code.rs @@ -416,22 +416,13 @@ impl<'a> PeepholeOptimizations { if let Some(reference_id) = ident.reference_id.get() { if let Some(symbol_id) = ctx.scoping().get_reference(reference_id).symbol_id() { if ctx.state.empty_functions.contains(&symbol_id) { - if e.arguments.is_empty() { + let mut exprs = + Self::fold_arguments_into_needed_expressions(&mut e.arguments, ctx); + if exprs.is_empty() { *expr = ctx.ast.void_0(e.span); ctx.state.changed = true; return; } - let mut exprs = ctx.ast.vec(); - for arg in e.arguments.drain(..) { - match arg { - Argument::SpreadElement(e) => { - exprs.push(e.unbox().argument); - } - match_expression!(Argument) => { - exprs.push(arg.into_expression()); - } - } - } exprs.push(ctx.ast.void_0(e.span)); *expr = ctx.ast.expression_sequence(e.span, exprs); ctx.state.changed = true; @@ -724,8 +715,8 @@ mod test { test_options("var foo = () => {}; foo()", "", &options); test_options("var foo = () => {}; foo(a)", "a", &options); test_options("var foo = () => {}; foo(a, b)", "a, b", &options); - test_options("var foo = () => {}; foo(...a, b)", "a, b", &options); - test_options("var foo = () => {}; foo(...a, ...b)", "a, b", &options); + test_options("var foo = () => {}; foo(...a, b)", "[...a], b", &options); + test_options("var foo = () => {}; foo(...a, ...b)", "[...a], [...b]", &options); test_options("var foo = () => {}; x = foo()", "x = void 0", &options); test_options("var foo = () => {}; x = foo(a(), b())", "x = (a(), b(), void 0)", &options); test_options("var foo = function () {}; foo()", "", &options); diff --git a/crates/oxc_minifier/src/peephole/remove_unused_expression.rs b/crates/oxc_minifier/src/peephole/remove_unused_expression.rs index 9e9073f002c95..ee145bb5dafd3 100644 --- a/crates/oxc_minifier/src/peephole/remove_unused_expression.rs +++ b/crates/oxc_minifier/src/peephole/remove_unused_expression.rs @@ -580,9 +580,8 @@ impl<'a> PeepholeOptimizations { !call_expr.may_have_side_effects(ctx) } - fn fold_arguments_into_needed_expressions( + pub fn fold_arguments_into_needed_expressions( args: &mut Vec<'a, Argument<'a>>, - ctx: &mut Ctx<'a, '_>, ) -> Vec<'a, Expression<'a>> { ctx.ast.vec_from_iter(args.drain(..).filter_map(|arg| {