Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions crates/oxc_minifier/src/peephole/remove_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_minifier/src/peephole/remove_unused_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
Loading