File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -335,6 +335,15 @@ impl<'a> DeadCodeElimination {
335335}
336336
337337impl < ' a > Traverse < ' a , MinifierState < ' a > > for DeadCodeElimination {
338+ fn exit_variable_declarator (
339+ & mut self ,
340+ decl : & mut VariableDeclarator < ' a > ,
341+ ctx : & mut TraverseCtx < ' a > ,
342+ ) {
343+ let mut ctx = Ctx :: new ( ctx) ;
344+ self . inner . init_symbol_value ( decl, & mut ctx) ;
345+ }
346+
338347 fn exit_statement ( & mut self , stmt : & mut Statement < ' a > , ctx : & mut TraverseCtx < ' a > ) {
339348 let mut ctx = Ctx :: new ( ctx) ;
340349 self . inner . remove_dead_code_exit_statement ( stmt, & mut ctx) ;
Original file line number Diff line number Diff line change @@ -140,6 +140,11 @@ fn dce_logical_expression() {
140140
141141 test ( "foo = false && bar()" , "foo = false" ) ;
142142 test ( "foo = true && bar()" , "foo = bar()" ) ;
143+
144+ test (
145+ "const x = 'keep'; const y = 'remove'; foo(x || y), foo(y && x)" ,
146+ "const x = 'keep'; const y = 'remove'; foo(x), foo(x);" ,
147+ ) ;
143148}
144149
145150#[ test]
You can’t perform that action at this time.
0 commit comments