@@ -23,16 +23,10 @@ use crate::{
2323//
2424// maybe move this out of this lib?
2525const UNSAFE_GLOBALS : & [ & str ] = & [
26- "window" ,
27- "self" ,
28- "globalThis" ,
29- "this" ,
3026 "parent" ,
3127 "top" ,
3228 "location" ,
33- "document" ,
34- "eval" ,
35- "frames" ,
29+ "eval"
3630] ;
3731
3832pub struct Visitor < ' alloc , ' data , E >
@@ -71,17 +65,25 @@ where
7165
7266 fn rewrite_ident ( & mut self , name : & Atom , span : Span ) {
7367 if UNSAFE_GLOBALS . contains ( & name. as_str ( ) ) {
74- self . jschanges . add ( rewrite ! ( span, WrapFn { wrap : true } ) ) ;
68+ self . jschanges . add ( rewrite ! ( span, WrapFn { enclose : true } ) ) ;
7569 }
7670 }
7771
7872 fn walk_member_expression ( & mut self , it : & Expression ) -> bool {
7973 match it {
8074 Expression :: Identifier ( s) => {
81- self . rewrite_ident ( & s. name , s. span ) ;
82- true
75+ false
8376 }
84- Expression :: StaticMemberExpression ( s) => self . walk_member_expression ( & s. object ) ,
77+ Expression :: StaticMemberExpression ( s) => {
78+ if UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) ) {
79+ // self.jschanges.add(rewrite!(s.span, WrapAccess {
80+ // ident: s.property.name,
81+ // propspan: s.property.span,
82+ // }
83+ // ));
84+ }
85+ self . walk_member_expression ( & s. object )
86+ } ,
8587 Expression :: ComputedMemberExpression ( s) => self . walk_member_expression ( & s. object ) ,
8688 _ => false ,
8789 }
@@ -109,7 +111,7 @@ where
109111 //
110112 if UNSAFE_GLOBALS . contains ( & it. name . as_str ( ) ) {
111113 self . jschanges
112- . add ( rewrite ! ( it. span, WrapFn { wrap : false } ) ) ;
114+ . add ( rewrite ! ( it. span, WrapFn { enclose : false } ) ) ;
113115 }
114116 // }
115117 }
@@ -132,21 +134,41 @@ where
132134 return ; // unwise to walk the rest of the tree
133135 }
134136
135- if !self . flags . strict_rewrites
136- && !UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) )
137- && let Expression :: Identifier ( _) | Expression :: ThisExpression ( _) = & s. object
138- {
139- // cull tree - this should be safe
140- return ;
141- }
137+ if UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) ) {
138+ self . jschanges . add ( rewrite ! ( it. span( ) , WrapAccess {
139+ ident: s. property. name,
140+ propspan: Span :: new( s. property. span. start-1 , s. property. span. end) ,
141+ enclose: false ,
142+ } ) ) ;
143+ }
144+ // if !self.flags.strict_rewrites
145+ // && !UNSAFE_GLOBALS.contains(&s.property.name.as_str())
146+ // && let Expression::Identifier(_) | Expression::ThisExpression(_) = &s.object
147+ // {
148+ // // cull tree - this should be safe
149+ // return;
150+ // }
151+
152+ // if self.flags.scramitize
153+ // && !matches!(s.object, Expression::MetaProperty(_) | Expression::Super(_))
154+ // {
155+ // self.scramitize(s.object.span());
156+ // }
157+ }
142158
143- if self . flags . scramitize
144- && !matches ! ( s. object, Expression :: MetaProperty ( _) | Expression :: Super ( _) )
145- {
146- self . scramitize ( s. object . span ( ) ) ;
147- }
159+ match & it. object ( ) {
160+ Expression :: Identifier ( _) => {
161+ return ;
162+ }
163+ Expression :: ThisExpression ( _) => {
164+ // this is safe, we don't need to walk it
165+ return ;
166+ }
167+ _=>{ }
148168 }
149169
170+
171+
150172 walk:: walk_member_expression ( self , it) ;
151173 }
152174 fn visit_this_expression ( & mut self , it : & ThisExpression ) {
0 commit comments