@@ -359,6 +359,34 @@ where
359359 }
360360 }
361361
362+ fn handle_assignment_target_member ( & mut self , target : & AssignmentTarget < ' data > ) {
363+ match target {
364+ AssignmentTarget :: StaticMemberExpression ( s) => {
365+ // window.location = ...
366+ if UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) ) {
367+ self . jschanges . add ( rewrite ! (
368+ s. property. span( ) ,
369+ RewriteProperty {
370+ ident: s. property. name
371+ }
372+ ) ) ;
373+ }
374+
375+ // walk the left hand side of the member expression (`window` for the `window.location = ...` case)
376+ walk:: walk_expression ( self , & s. object ) ;
377+ }
378+ AssignmentTarget :: ComputedMemberExpression ( s) => {
379+ // window["location"] = ...
380+ self . handle_computed_member_expression ( s) ;
381+ // `window`
382+ walk:: walk_expression ( self , & s. object ) ;
383+ // `"location"`
384+ walk:: walk_expression ( self , & s. expression ) ;
385+ }
386+ _ => { }
387+ }
388+ }
389+
362390 fn handle_for_of_in ( & mut self , left : & ForStatementLeft < ' data > , right : & Expression < ' data > , body : & Statement < ' data > ) {
363391 let mut restids: Vec < Atom < ' data > > = Vec :: new ( ) ;
364392 let mut location_assigned: bool = false ;
@@ -374,28 +402,8 @@ where
374402 }
375403 }
376404
377- // TODO: this logic is duplicated in visit_assignment_target. can it be merged?
378- AssignmentTarget :: StaticMemberExpression ( s) => {
379- // window.location = ...
380- if UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) ) {
381- self . jschanges . add ( rewrite ! (
382- s. property. span( ) ,
383- RewriteProperty {
384- ident: s. property. name
385- }
386- ) ) ;
387- }
388-
389- // walk the left hand side of the member expression (`window` for the `window.location = ...` case)
390- walk:: walk_expression ( self , & s. object ) ;
391- }
392- AssignmentTarget :: ComputedMemberExpression ( s) => {
393- // window["location"] = ...
394- self . handle_computed_member_expression ( s) ;
395- // `window`
396- walk:: walk_expression ( self , & s. object ) ;
397- // `"location"`
398- walk:: walk_expression ( self , & s. expression ) ;
405+ AssignmentTarget :: StaticMemberExpression ( _) | AssignmentTarget :: ComputedMemberExpression ( _) => {
406+ self . handle_assignment_target_member ( target) ;
399407 }
400408 AssignmentTarget :: ObjectAssignmentTarget ( o) => {
401409 self . recurse_object_assignment_target ( o, & mut restids, & mut location_assigned) ;
@@ -838,27 +846,8 @@ where
838846 ) ) ;
839847 }
840848 }
841- AssignmentTarget :: StaticMemberExpression ( s) => {
842- // window.location = ...
843- if UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) ) {
844- self . jschanges . add ( rewrite ! (
845- s. property. span( ) ,
846- RewriteProperty {
847- ident: s. property. name
848- }
849- ) ) ;
850- }
851-
852- // walk the left hand side of the member expression (`window` for the `window.location = ...` case)
853- walk:: walk_expression ( self , & s. object ) ;
854- }
855- AssignmentTarget :: ComputedMemberExpression ( s) => {
856- // window["location"] = ...
857- self . handle_computed_member_expression ( s) ;
858- // `window`
859- walk:: walk_expression ( self , & s. object ) ;
860- // `"location"`
861- walk:: walk_expression ( self , & s. expression ) ;
849+ AssignmentTarget :: StaticMemberExpression ( _) | AssignmentTarget :: ComputedMemberExpression ( _) => {
850+ self . handle_assignment_target_member ( & it. left ) ;
862851 }
863852 AssignmentTarget :: ObjectAssignmentTarget ( o) => {
864853 if !self . flags . destructure_rewrites {
0 commit comments