@@ -242,13 +242,10 @@ impl<'a> PeepholeOptimizations {
242242 expr : & mut BinaryExpression < ' a > ,
243243 ctx : & mut Ctx < ' a , ' _ > ,
244244 ) -> Option < Expression < ' a > > {
245- let Expression :: UnaryExpression ( unary_expr) = & expr. left else { return None } ;
245+ let Expression :: UnaryExpression ( unary_expr) = & mut expr. left else { return None } ;
246246 if !unary_expr. operator . is_typeof ( ) {
247247 return None ;
248248 }
249- if !expr. right . is_specific_string_literal ( "undefined" ) {
250- return None ;
251- }
252249 let ( new_eq_op, new_comp_op) = match expr. operator {
253250 BinaryOperator :: Equality | BinaryOperator :: StrictEquality => {
254251 ( BinaryOperator :: StrictEquality , BinaryOperator :: GreaterThan )
@@ -258,19 +255,22 @@ impl<'a> PeepholeOptimizations {
258255 }
259256 _ => return None ,
260257 } ;
261- if let Expression :: Identifier ( ident) = & unary_expr. argument {
262- if ctx. is_global_reference ( ident) {
263- let left = expr. left . take_in ( ctx. ast ) ;
264- let right = ctx. ast . expression_string_literal ( expr. right . span ( ) , "u" , None ) ;
265- return Some ( ctx. ast . expression_binary ( expr. span , left, new_comp_op, right) ) ;
266- }
258+ if !expr. right . is_specific_string_literal ( "undefined" ) {
259+ return None ;
267260 }
268-
269- let Expression :: UnaryExpression ( unary_expr) = expr. left . take_in ( ctx. ast ) else {
270- unreachable ! ( )
271- } ;
272- let right = ctx. ast . void_0 ( expr. right . span ( ) ) ;
273- Some ( ctx. ast . expression_binary ( expr. span , unary_expr. unbox ( ) . argument , new_eq_op, right) )
261+ if let Expression :: Identifier ( ident) = & unary_expr. argument
262+ && ctx. is_global_reference ( ident)
263+ {
264+ let left = expr. left . take_in ( ctx. ast ) ;
265+ let right = ctx. ast . expression_string_literal ( expr. right . span ( ) , "u" , None ) ;
266+ return Some ( ctx. ast . expression_binary ( expr. span , left, new_comp_op, right) ) ;
267+ }
268+ Some ( ctx. ast . expression_binary (
269+ expr. span ,
270+ unary_expr. take_in ( ctx. ast ) . argument ,
271+ new_eq_op,
272+ ctx. ast . void_0 ( expr. right . span ( ) ) ,
273+ ) )
274274 }
275275
276276 /// Remove unary `+` if `ToNumber` conversion is done by the parent expression
0 commit comments