@@ -176,23 +176,22 @@ where
176176 // { location: x = parent } = {};
177177 // if let Some(name) = p.binding.iden && name == "location" {
178178 // self.jschanges.add(rewrite!(p.span(), TempVar));
179- // *location_assigned = true;
180- // }
179+ // *location_assigned = true;
180+ // }
181181 // we still need to rewrite whatever stuff might be in the default expression
182182 walk:: walk_expression ( self , & d. init ) ;
183183 }
184184 AssignmentTargetMaybeDefault :: ObjectAssignmentTarget ( p) => {
185-
186185 self . recurse_object_assignment_target ( p, restids, location_assigned) ;
187186 }
188- AssignmentTargetMaybeDefault :: AssignmentTargetIdentifier ( p) => {
189- if p. name == "location" {
190- self . jschanges . add ( rewrite ! ( p. span( ) , TempVar ) ) ;
191- * location_assigned = true ;
192- }
187+ AssignmentTargetMaybeDefault :: AssignmentTargetIdentifier ( p) => {
188+ if p. name == "location" {
189+ self . jschanges . add ( rewrite ! ( p. span( ) , TempVar ) ) ;
190+ * location_assigned = true ;
191+ }
193192 }
194193 AssignmentTargetMaybeDefault :: ArrayAssignmentTarget ( a) => {
195- self . recurse_array_assignment_target ( a, restids, location_assigned) ;
194+ self . recurse_array_assignment_target ( a, restids, location_assigned) ;
196195 }
197196 _ => { }
198197 }
@@ -201,39 +200,41 @@ where
201200 }
202201 }
203202 fn recurse_array_assignment_target (
204- & mut self ,
205- s : & oxc:: ast:: ast:: ArrayAssignmentTarget < ' data > ,
206- restids : & mut Vec < Atom < ' data > > ,
207- location_assigned : & mut bool ,
208- ) {
209- // note that i don't actually have to care about the rest param here since it wont have dangerous props. i still need to keep track of the object destructure rests though
210- for elem in & s. elements {
211- if let Some ( elem) = elem {
212- match elem {
213- AssignmentTargetMaybeDefault :: AssignmentTargetWithDefault ( p) => {
214- if let Some ( name) = p. binding . get_identifier_name ( ) && name == "location" {
215- self . jschanges . add ( rewrite ! ( p. span( ) , TempVar ) ) ;
216- * location_assigned = true ;
217- }
218- walk:: walk_expression ( self , & p. init ) ;
219- }
220- AssignmentTargetMaybeDefault :: AssignmentTargetIdentifier ( p) => {
221- if p. name == "location" {
222- self . jschanges . add ( rewrite ! ( p. span( ) , TempVar ) ) ;
223- * location_assigned = true ;
224- }
225- }
226- AssignmentTargetMaybeDefault :: ObjectAssignmentTarget ( o) => {
227- self . recurse_object_assignment_target ( o, restids, location_assigned) ;
228- }
229- AssignmentTargetMaybeDefault :: ArrayAssignmentTarget ( a) => {
230- self . recurse_array_assignment_target ( a, restids, location_assigned) ;
231- }
232- _ => { }
233- }
234- }
235- }
236- }
203+ & mut self ,
204+ s : & oxc:: ast:: ast:: ArrayAssignmentTarget < ' data > ,
205+ restids : & mut Vec < Atom < ' data > > ,
206+ location_assigned : & mut bool ,
207+ ) {
208+ // note that i don't actually have to care about the rest param here since it wont have dangerous props. i still need to keep track of the object destructure rests though
209+ for elem in & s. elements {
210+ if let Some ( elem) = elem {
211+ match elem {
212+ AssignmentTargetMaybeDefault :: AssignmentTargetWithDefault ( p) => {
213+ if let Some ( name) = p. binding . get_identifier_name ( )
214+ && name == "location"
215+ {
216+ self . jschanges . add ( rewrite ! ( p. span( ) , TempVar ) ) ;
217+ * location_assigned = true ;
218+ }
219+ walk:: walk_expression ( self , & p. init ) ;
220+ }
221+ AssignmentTargetMaybeDefault :: AssignmentTargetIdentifier ( p) => {
222+ if p. name == "location" {
223+ self . jschanges . add ( rewrite ! ( p. span( ) , TempVar ) ) ;
224+ * location_assigned = true ;
225+ }
226+ }
227+ AssignmentTargetMaybeDefault :: ObjectAssignmentTarget ( o) => {
228+ self . recurse_object_assignment_target ( o, restids, location_assigned) ;
229+ }
230+ AssignmentTargetMaybeDefault :: ArrayAssignmentTarget ( a) => {
231+ self . recurse_array_assignment_target ( a, restids, location_assigned) ;
232+ }
233+ _ => { }
234+ }
235+ }
236+ }
237+ }
237238
238239 fn scramitize ( & mut self , span : Span ) {
239240 self . jschanges . add ( rewrite ! ( span, Scramitize ) ) ;
@@ -429,18 +430,18 @@ where
429430
430431 fn visit_unary_expression ( & mut self , it : & UnaryExpression < ' data > ) {
431432 if matches ! ( it. operator, UnaryOperator :: Typeof ) {
432- match it. argument {
433- Expression :: Identifier ( _) =>{
434- // `typeof location` -> `typeof $wrap(location)` seems like a sane rewrite but it's incorrect
433+ match it. argument {
434+ Expression :: Identifier ( _) => {
435+ // `typeof location` -> `typeof $wrap(location)` seems like a sane rewrite but it's incorrect
435436 // typeof has the special property of not caring whether the identifier is undefined
436437 // and this won't escape anyway, so don't rewrite
437- return ;
438- }
439- _=> {
440- // `typeof (location)` / `typeof location.href` / `typeof function()`
441- // this is safe to rewrite
442- }
443- }
438+ return ;
439+ }
440+ _ => {
441+ // `typeof (location)` / `typeof location.href` / `typeof function()`
442+ // this is safe to rewrite
443+ }
444+ }
444445 }
445446 walk:: walk_unary_expression ( self , it) ;
446447 }
@@ -471,7 +472,7 @@ where
471472 }
472473
473474 fn visit_binding_pattern ( & mut self , it : & BindingPattern < ' data > ) {
474- if !self . flags . destructure_rewrites {
475+ if !self . flags . destructure_rewrites {
475476 return ;
476477 }
477478
@@ -522,7 +523,7 @@ where
522523 fn visit_assignment_expression ( & mut self , it : & AssignmentExpression < ' data > ) {
523524 match & it. left {
524525 AssignmentTarget :: AssignmentTargetIdentifier ( s) => {
525- // location = ...
526+ // location = ...
526527 if [ "location" ] . contains ( & s. name . to_string ( ) . as_str ( ) ) {
527528 self . jschanges . add ( rewrite ! (
528529 it. span,
@@ -535,7 +536,7 @@ where
535536 }
536537 }
537538 AssignmentTarget :: StaticMemberExpression ( s) => {
538- // window.location = ...
539+ // window.location = ...
539540 if UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) ) {
540541 self . jschanges . add ( rewrite ! (
541542 s. property. span( ) ,
@@ -549,15 +550,15 @@ where
549550 walk:: walk_expression ( self , & s. object ) ;
550551 }
551552 AssignmentTarget :: ComputedMemberExpression ( s) => {
552- // window["location"] = ...
553+ // window["location"] = ...
553554 self . walk_computed_member_expression ( s) ;
554555 // `window`
555556 walk:: walk_expression ( self , & s. object ) ;
556557 // `"location"`
557558 walk:: walk_expression ( self , & s. expression ) ;
558559 }
559560 AssignmentTarget :: ObjectAssignmentTarget ( o) => {
560- if !self . flags . destructure_rewrites {
561+ if !self . flags . destructure_rewrites {
561562 return ;
562563 }
563564
@@ -566,22 +567,32 @@ where
566567 self . recurse_object_assignment_target ( o, & mut restids, & mut location_assigned) ;
567568
568569 if restids. len ( ) > 0 || location_assigned {
569- self . jschanges
570- . add ( rewrite ! ( it. span, WrapObjectAssignment { restids, location_assigned } ) ) ;
570+ self . jschanges . add ( rewrite ! (
571+ it. span,
572+ WrapObjectAssignment {
573+ restids,
574+ location_assigned
575+ }
576+ ) ) ;
571577 }
572578 return ;
573579 }
574580 AssignmentTarget :: ArrayAssignmentTarget ( a) => {
575- if !self . flags . destructure_rewrites {
581+ if !self . flags . destructure_rewrites {
576582 return ;
577583 }
578584
579- let mut restids: Vec < Atom < ' data > > = Vec :: new ( ) ;
580- let mut location_assigned: bool = false ;
581- self . recurse_array_assignment_target ( a, & mut restids, & mut location_assigned) ;
582- if restids. len ( ) > 0 || location_assigned {
583- self . jschanges
584- . add ( rewrite ! ( it. span, WrapObjectAssignment { restids, location_assigned } ) ) ;
585+ let mut restids: Vec < Atom < ' data > > = Vec :: new ( ) ;
586+ let mut location_assigned: bool = false ;
587+ self . recurse_array_assignment_target ( a, & mut restids, & mut location_assigned) ;
588+ if restids. len ( ) > 0 || location_assigned {
589+ self . jschanges . add ( rewrite ! (
590+ it. span,
591+ WrapObjectAssignment {
592+ restids,
593+ location_assigned
594+ }
595+ ) ) ;
585596 }
586597 }
587598 _ => { }
0 commit comments