From 04ec38dc4793bb31e9f3bbd0f43449ea4b2b0bfb Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Mon, 6 Jan 2025 02:21:26 +0000 Subject: [PATCH] feat(minifier): remove unused arrow function expressions (#8262) --- .../src/ast_passes/peephole_remove_dead_code.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs b/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs index 6e65a5fa6130f..29225a2a55bee 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_remove_dead_code.rs @@ -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() @@ -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 () {})()"); + } }