feat(minifier): remove unused arrow function expressions (#8262)

This commit is contained in:
camc314 2025-01-06 02:21:26 +00:00
parent e446c15619
commit 04ec38dc47

View file

@ -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 () {})()");
}
}