File tree 2 files changed +25
-0
lines changed
crates/oxc_minifier/src/peephole
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -306,6 +306,14 @@ impl<'a> Traverse<'a> for LatePeepholeOptimizations {
306
306
fn exit_catch_clause ( & mut self , catch : & mut CatchClause < ' a > , ctx : & mut TraverseCtx < ' a > ) {
307
307
self . substitute_catch_clause ( catch, Ctx ( ctx) ) ;
308
308
}
309
+
310
+ fn exit_call_expression ( & mut self , e : & mut CallExpression < ' a > , _ctx : & mut TraverseCtx < ' a > ) {
311
+ Self :: remove_empty_spread_arguments ( & mut e. arguments ) ;
312
+ }
313
+
314
+ fn exit_new_expression ( & mut self , e : & mut NewExpression < ' a > , _ctx : & mut TraverseCtx < ' a > ) {
315
+ Self :: remove_empty_spread_arguments ( & mut e. arguments ) ;
316
+ }
309
317
}
310
318
311
319
pub struct DeadCodeElimination {
Original file line number Diff line number Diff line change @@ -620,6 +620,17 @@ impl<'a> LatePeepholeOptimizations {
620
620
pub fn remove_dead_code_exit_class_body ( body : & mut ClassBody < ' a > , _ctx : Ctx < ' a , ' _ > ) {
621
621
body. body . retain ( |e| !matches ! ( e, ClassElement :: StaticBlock ( s) if s. body. is_empty( ) ) ) ;
622
622
}
623
+
624
+ pub fn remove_empty_spread_arguments ( args : & mut Vec < ' a , Argument < ' a > > ) {
625
+ if args. len ( ) != 1 {
626
+ return ;
627
+ }
628
+ let Argument :: SpreadElement ( e) = & args[ 0 ] else { return } ;
629
+ let Expression :: ArrayExpression ( e) = & e. argument else { return } ;
630
+ if e. elements . is_empty ( ) {
631
+ args. drain ( ..) ;
632
+ }
633
+ }
623
634
}
624
635
625
636
/// <https://github.com/google/closure-compiler/blob/v20240609/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java>
@@ -898,4 +909,10 @@ mod test {
898
909
test_same ( "throw foo; export let bar" ) ;
899
910
test_same ( "throw foo; export default bar" ) ;
900
911
}
912
+
913
+ #[ test]
914
+ fn remove_empty_spread_arguments ( ) {
915
+ test ( "foo(...[])" , "foo()" ) ;
916
+ test ( "new Foo(...[])" , "new Foo()" ) ;
917
+ }
901
918
}
You can’t perform that action at this time.
0 commit comments