@@ -3,9 +3,14 @@ use std::error::Error;
33use oxc:: {
44 allocator:: { Allocator , StringBuilder } ,
55 ast:: ast:: {
6- AssignmentExpression , AssignmentTarget , BindingPattern , CallExpression , ComputedMemberExpression , DebuggerStatement , ExportAllDeclaration , ExportNamedDeclaration , Expression , FunctionBody , IdentifierReference , ImportDeclaration , ImportExpression , MemberExpression , MetaProperty , NewExpression , ObjectExpression , ObjectPattern , ObjectPropertyKind , ReturnStatement , SimpleAssignmentTarget , StringLiteral , ThisExpression , UnaryExpression , UnaryOperator , UpdateExpression
6+ AssignmentExpression , AssignmentTarget , BindingPattern , CallExpression ,
7+ ComputedMemberExpression , DebuggerStatement , ExportAllDeclaration , ExportNamedDeclaration ,
8+ Expression , FunctionBody , IdentifierReference , ImportDeclaration , ImportExpression ,
9+ MemberExpression , MetaProperty , NewExpression , ObjectExpression , ObjectPattern ,
10+ ObjectPropertyKind , ReturnStatement , SimpleAssignmentTarget , StringLiteral , ThisExpression ,
11+ UnaryExpression , UnaryOperator , UpdateExpression ,
712 } ,
8- ast_visit:: { walk , Visit } ,
13+ ast_visit:: { Visit , walk } ,
914 span:: { Atom , GetSpan , Span } ,
1015} ;
1116
@@ -78,24 +83,24 @@ where
7883 // }
7984 // }
8085 fn walk_computed_member_expression ( & mut self , it : & ComputedMemberExpression < ' data > ) {
81- match & it. expression {
82- Expression :: NullLiteral ( _) | Expression :: BigIntLiteral ( _ ) | Expression :: NumericLiteral ( _ ) | Expression :: RegExpLiteral ( _ ) | Expression :: BooleanLiteral ( _ ) => { } ,
83- Expression :: StringLiteral ( lit ) => {
84- if UNSAFE_GLOBALS . contains ( & lit . value . as_str ( ) ) {
85- self . jschanges . add ( rewrite ! (
86- it . expression . span ( ) ,
87- WrapProperty ,
88- ) ) ;
89- }
90- } ,
91- _=> {
92- self . jschanges . add ( rewrite ! (
93- it . expression . span ( ) ,
94- WrapProperty ,
95- ) ) ;
96- }
97- }
98- }
86+ match & it. expression {
87+ Expression :: NullLiteral ( _)
88+ | Expression :: BigIntLiteral ( _ )
89+ | Expression :: NumericLiteral ( _ )
90+ | Expression :: RegExpLiteral ( _ )
91+ | Expression :: BooleanLiteral ( _ ) => { }
92+ Expression :: StringLiteral ( lit ) => {
93+ if UNSAFE_GLOBALS . contains ( & lit . value . as_str ( ) ) {
94+ self . jschanges
95+ . add ( rewrite ! ( it . expression . span ( ) , WrapProperty , ) ) ;
96+ }
97+ }
98+ _ => {
99+ self . jschanges
100+ . add ( rewrite ! ( it . expression . span ( ) , WrapProperty , ) ) ;
101+ }
102+ }
103+ }
99104
100105 fn scramitize ( & mut self , span : Span ) {
101106 self . jschanges . add ( rewrite ! ( span, Scramitize ) ) ;
@@ -125,7 +130,7 @@ where
125130 }
126131
127132 fn visit_new_expression ( & mut self , it : & NewExpression < ' data > ) {
128- // ??
133+ // ??
129134 // self.walk_member_expression(&it.callee);
130135 walk:: walk_arguments ( self , & it. arguments ) ;
131136 }
@@ -147,7 +152,9 @@ where
147152 if UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) ) {
148153 self . jschanges . add ( rewrite ! (
149154 s. property. span( ) ,
150- RewriteProperty { ident: s. property. name }
155+ RewriteProperty {
156+ ident: s. property. name
157+ }
151158 ) ) ;
152159 }
153160 }
@@ -203,9 +210,13 @@ where
203210 }
204211
205212 fn visit_import_declaration ( & mut self , it : & ImportDeclaration < ' data > ) {
206- let str = it. source . to_string ( ) ;
207- if str. contains ( ":" ) || str. starts_with ( "/" ) || str. starts_with ( "." ) || str. starts_with ( ".." ) {
208- self . rewrite_url ( & it. source , true ) ;
213+ let str = it. source . to_string ( ) ;
214+ if str. contains ( ":" )
215+ || str. starts_with ( "/" )
216+ || str. starts_with ( "." )
217+ || str. starts_with ( ".." )
218+ {
219+ self . rewrite_url ( & it. source , true ) ;
209220 }
210221 walk:: walk_import_declaration ( self , it) ;
211222 }
@@ -294,16 +305,16 @@ where
294305 fn visit_update_expression ( & mut self , it : & UpdateExpression < ' data > ) {
295306 // this is like a ++ or -- operator
296307 match it. argument {
297- SimpleAssignmentTarget :: AssignmentTargetIdentifier ( _) => {
298- // if it's an identifier we cannot rewrite it
299- // $wrap(location)++ is invalid syntax
300-
301- // so it's safer to assume that this "location" is a local
302- // even if it's real location you can't escape with it anyway
303- // unless you consider navigating to "https://proxy.com/NaN" escaping
304- return ;
305- }
306- _=> { }
308+ SimpleAssignmentTarget :: AssignmentTargetIdentifier ( _) => {
309+ // if it's an identifier we cannot rewrite it
310+ // $wrap(location)++ is invalid syntax
311+
312+ // so it's safer to assume that this "location" is a local
313+ // even if it's real location you can't escape with it anyway
314+ // unless you consider navigating to "https://proxy.com/NaN" escaping
315+ return ;
316+ }
317+ _ => { }
307318 }
308319
309320 // if it's not a simple identifier it's probably a member expression which is safe
@@ -338,15 +349,17 @@ where
338349 if UNSAFE_GLOBALS . contains ( & s. property . name . as_str ( ) ) {
339350 self . jschanges . add ( rewrite ! (
340351 s. property. span( ) ,
341- RewriteProperty { ident: s. property. name }
352+ RewriteProperty {
353+ ident: s. property. name
354+ }
342355 ) ) ;
343356 }
344357
345358 // more to walk
346359 walk:: walk_expression ( self , & s. object ) ;
347360 }
348361 AssignmentTarget :: ComputedMemberExpression ( s) => {
349- self . walk_computed_member_expression ( s) ;
362+ self . walk_computed_member_expression ( s) ;
350363 walk:: walk_expression ( self , & s. object ) ;
351364 walk:: walk_expression ( self , & s. expression ) ;
352365 }
0 commit comments