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> {
577
577
return self . arguments . iter ( ) . any ( |e| e. may_have_side_effects ( ctx) ) ;
578
578
}
579
579
580
- let ( ident , name) = match & self . callee {
580
+ let ( object , name) = match & self . callee {
581
581
Expression :: StaticMemberExpression ( member) if !member. optional => {
582
582
( member. object . get_identifier_reference ( ) , member. property . name . as_str ( ) )
583
583
}
@@ -592,10 +592,13 @@ impl<'a> MayHaveSideEffects<'a> for CallExpression<'a> {
592
592
_ => return true ,
593
593
} ;
594
594
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
+ }
596
599
597
600
#[ rustfmt:: skip]
598
- let is_global = match object {
601
+ let is_global = match object. name . as_str ( ) {
599
602
"Array" => matches ! ( name, "isArray" | "of" ) ,
600
603
"ArrayBuffer" => name == "isView" ,
601
604
"Date" => matches ! ( name, "now" | "parse" | "UTC" ) ,
Original file line number Diff line number Diff line change 1
- use std:: iter;
2
-
3
1
use javascript_globals:: GLOBALS ;
4
2
5
3
use rustc_hash:: FxHashSet ;
@@ -27,7 +25,7 @@ impl Default for Ctx {
27
25
global_variable_names : GLOBALS [ "builtin" ]
28
26
. keys ( )
29
27
. copied ( )
30
- . chain ( iter :: once ( "arguments" ) )
28
+ . chain ( [ "arguments" , "URL" ] )
31
29
. collect :: < FxHashSet < _ > > ( ) ,
32
30
annotation : true ,
33
31
pure_function_names : vec ! [ ] ,
@@ -927,6 +925,10 @@ fn test_call_expressions() {
927
925
test ( "Uint32Array.of()" , false ) ;
928
926
test ( "Uint8Array.of()" , false ) ;
929
927
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 ) ;
930
932
}
931
933
932
934
#[ test]
You can’t perform that action at this time.
0 commit comments