File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
oxc_ecmascript/src/side_effects
oxc_minifier/tests/ecmascript Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -577,7 +577,7 @@ impl<'a> MayHaveSideEffects<'a> for CallExpression<'a> {
577577 return self . arguments . iter ( ) . any ( |e| e. may_have_side_effects ( ctx) ) ;
578578 }
579579
580- let ( ident , name) = match & self . callee {
580+ let ( object , name) = match & self . callee {
581581 Expression :: StaticMemberExpression ( member) if !member. optional => {
582582 ( member. object . get_identifier_reference ( ) , member. property . name . as_str ( ) )
583583 }
@@ -592,10 +592,13 @@ impl<'a> MayHaveSideEffects<'a> for CallExpression<'a> {
592592 _ => return true ,
593593 } ;
594594
595- let Some ( object) = ident. map ( |ident| ident. name . as_str ( ) ) else { return true } ;
595+ let Some ( object) = object else { return true } ;
596+ if !ctx. is_global_reference ( object) {
597+ return true ;
598+ }
596599
597600 #[ rustfmt:: skip]
598- let is_global = match object {
601+ let is_global = match object. name . as_str ( ) {
599602 "Array" => matches ! ( name, "isArray" | "of" ) ,
600603 "ArrayBuffer" => name == "isView" ,
601604 "Date" => matches ! ( name, "now" | "parse" | "UTC" ) ,
Original file line number Diff line number Diff line change 1- use std:: iter;
2-
31use javascript_globals:: GLOBALS ;
42
53use rustc_hash:: FxHashSet ;
@@ -27,7 +25,7 @@ impl Default for Ctx {
2725 global_variable_names : GLOBALS [ "builtin" ]
2826 . keys ( )
2927 . copied ( )
30- . chain ( iter :: once ( "arguments" ) )
28+ . chain ( [ "arguments" , "URL" ] )
3129 . collect :: < FxHashSet < _ > > ( ) ,
3230 annotation : true ,
3331 pure_function_names : vec ! [ ] ,
@@ -927,6 +925,10 @@ fn test_call_expressions() {
927925 test ( "Uint32Array.of()" , false ) ;
928926 test ( "Uint8Array.of()" , false ) ;
929927 test ( "Uint8ClampedArray.of()" , false ) ;
928+
929+ // may have side effects if shadowed
930+ test_with_global_variables ( "Date()" , & [ ] , true ) ;
931+ test_with_global_variables ( "Object.create()" , & [ ] , true ) ;
930932}
931933
932934#[ test]
You can’t perform that action at this time.
0 commit comments