File tree Expand file tree Collapse file tree
oxc_ecmascript/src/constant_evaluation
oxc_minifier/src/peephole Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -395,9 +395,10 @@ pub trait ConstantEvaluation<'a>: MayHaveSideEffects {
395395 match expr. operator {
396396 UnaryOperator :: Typeof => {
397397 let s = match & expr. argument {
398- Expression :: ObjectExpression ( _) | Expression :: ArrayExpression ( _)
399- if expr. argument . is_literal_value ( true ) =>
400- {
398+ Expression :: ObjectExpression ( _) | Expression :: ArrayExpression ( _) => {
399+ if self . expression_may_have_side_effects ( & expr. argument ) {
400+ return None ;
401+ }
401402 "object"
402403 }
403404 Expression :: FunctionExpression ( _) => "function" ,
Original file line number Diff line number Diff line change @@ -1158,7 +1158,9 @@ mod test {
11581158 fold ( "x = typeof [1]" , "x = \" object\" " ) ;
11591159 fold ( "x = typeof [1,[]]" , "x = \" object\" " ) ;
11601160 fold ( "x = typeof {}" , "x = \" object\" " ) ;
1161+ test ( "var foo; NOOP(x = typeof { foo })" , "var foo; NOOP(x = \" object\" )" ) ;
11611162 fold ( "x = typeof function() {}" , "x = 'function'" ) ;
1163+ fold_same ( "x = typeof foo" ) ; // no sideeffect, but we don't know the result
11621164
11631165 fold_same ( "x = typeof[1,[foo()]]" ) ;
11641166 fold_same ( "x = typeof{bathwater:baby()}" ) ;
You can’t perform that action at this time.
0 commit comments