@@ -4,13 +4,13 @@ use oxc::{
44 allocator:: { Allocator , StringBuilder } ,
55 ast:: ast:: {
66 AssignmentExpression , AssignmentTarget , AssignmentTargetMaybeDefault ,
7- AssignmentTargetProperty , BindingPattern , BindingPatternKind , BindingProperty ,
8- CallExpression , ComputedMemberExpression , DebuggerStatement , ExportAllDeclaration ,
9- ExportNamedDeclaration , Expression , FunctionBody , IdentifierReference , ImportDeclaration ,
10- ImportExpression , MemberExpression , MetaProperty , NewExpression , ObjectAssignmentTarget ,
11- ObjectExpression , ObjectPattern , ObjectPropertyKind , PrivateIdentifier , PropertyKey ,
12- ReturnStatement , SimpleAssignmentTarget , StringLiteral , ThisExpression , UnaryExpression ,
13- UnaryOperator , UpdateExpression ,
7+ AssignmentTargetProperty , AssignmentTargetPropertyIdentifier , BindingPattern ,
8+ BindingPatternKind , BindingProperty , CallExpression , ComputedMemberExpression ,
9+ DebuggerStatement , ExportAllDeclaration , ExportNamedDeclaration , Expression , FunctionBody ,
10+ IdentifierReference , ImportDeclaration , ImportExpression , MemberExpression , MetaProperty ,
11+ NewExpression , ObjectAssignmentTarget , ObjectExpression , ObjectPattern , ObjectPropertyKind ,
12+ PrivateIdentifier , PropertyKey , ReturnStatement , SimpleAssignmentTarget , StringLiteral ,
13+ ThisExpression , UnaryExpression , UnaryOperator , UpdateExpression ,
1414 } ,
1515 ast_visit:: { Visit , walk} ,
1616 span:: { Atom , GetSpan , Span } ,
@@ -104,10 +104,21 @@ where
104104 }
105105 }
106106
107- fn recurse_object_assignment_target ( & mut self , s : & ObjectAssignmentTarget < ' data > ) {
108- if s. rest . is_some ( ) {
109- // infeasible to rewrite :(
110- eprintln ! ( "cannot rewrite rest parameters" ) ;
107+ fn recurse_object_assignment_target (
108+ & mut self ,
109+ s : & ObjectAssignmentTarget < ' data > ,
110+ restids : & mut Vec < Atom < ' data > > ,
111+ ) {
112+ if let Some ( r) = & s. rest {
113+ // { ...rest } = self;
114+ match & r. target {
115+ AssignmentTarget :: AssignmentTargetIdentifier ( i) => {
116+ // keep track of the name so we can clean it later
117+ // i don't really care about the rest being `location` here, if someone wants to redirect to `https://proxy.com/[Object object]` they can
118+ restids. push ( i. name ) ;
119+ }
120+ _ => panic ! ( "what?" ) ,
121+ }
111122 return ;
112123 }
113124 for prop in & s. properties {
@@ -168,7 +179,7 @@ where
168179 walk:: walk_expression ( self , & d. init ) ;
169180 }
170181 AssignmentTargetMaybeDefault :: ObjectAssignmentTarget ( p) => {
171- self . recurse_object_assignment_target ( p) ;
182+ self . recurse_object_assignment_target ( p, restids ) ;
172183 }
173184 _ => { }
174185 }
@@ -487,7 +498,13 @@ where
487498 walk:: walk_expression ( self , & s. expression ) ;
488499 }
489500 AssignmentTarget :: ObjectAssignmentTarget ( o) => {
490- self . recurse_object_assignment_target ( o) ;
501+ let mut restids: Vec < Atom < ' data > > = Vec :: new ( ) ;
502+ self . recurse_object_assignment_target ( o, & mut restids) ;
503+
504+ if restids. len ( ) > 0 {
505+ self . jschanges
506+ . add ( rewrite ! ( it. span, WrapObjectAssignment { restids } ) ) ;
507+ }
491508 return ;
492509 }
493510 _ => { }
0 commit comments