Skip to content

Commit

Permalink
feat(minifier): remove unused arrow function expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Jan 5, 2025
1 parent 0e5b5ec commit 944a397
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ impl<'a, 'b> PeepholeRemoveDeadCode {
Expression::FunctionExpression(function_expr) if function_expr.id.is_none() => {
Some(ctx.ast.statement_empty(SPAN))
}
Expression::ArrowFunctionExpression(_) => Some(ctx.ast.statement_empty(SPAN)),
// `typeof x` -> ``
Expression::UnaryExpression(unary_expr)
if unary_expr.operator.is_typeof()
Expand Down Expand Up @@ -583,4 +584,14 @@ mod test {
fold_same("delete x.y");
fold_same("delete x.y.z()");
}

#[test]
fn test_fold_function() {
fold("() => {}", "");
fold_same("var k = () => {}");
fold_same("var k = function () {}");
// TODO: fold the following...
fold_same("(() => {})()");
fold_same("(function () {})()");
}
}

0 comments on commit 944a397

Please sign in to comment.