Skip to content

Commit 6960da8

Browse files
committed
[core] chore: cargo fmt
1 parent 91fbe92 commit 6960da8

File tree

4 files changed

+65
-55
lines changed

4 files changed

+65
-55
lines changed

rewriter/js/src/changes.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ pub enum JsChangeType<'alloc: 'data, 'data> {
3838
WrapPropertyLeft,
3939
WrapPropertyRight,
4040
RewriteProperty {
41-
ident: Atom<'data>,
42-
},
41+
ident: Atom<'data>,
42+
},
4343

4444
/// insert `${cfg.setrealmfn}({}).`
4545
SetRealmFn,
@@ -106,7 +106,7 @@ impl<'alloc: 'data, 'data> Transform<'data> for JsChange<'alloc, 'data> {
106106
(cfg, flags): &Self::ToLowLevelData,
107107
offset: i32,
108108
) -> TransformLL<'data> {
109-
dbg!(&&self);
109+
dbg!(&&self);
110110
use JsChangeType as Ty;
111111
use TransformLL as LL;
112112
match self.ty {
@@ -122,7 +122,7 @@ impl<'alloc: 'data, 'data> Transform<'data> for JsChange<'alloc, 'data> {
122122
}),
123123
Ty::WrapPropertyLeft => LL::insert(transforms![&cfg.wrappropertyfn, "(("]),
124124
Ty::WrapPropertyRight => LL::insert(transforms!["))"]),
125-
Ty::RewriteProperty { ident } => LL::replace(transforms![&cfg.wrappropertybase,ident]),
125+
Ty::RewriteProperty { ident } => LL::replace(transforms![&cfg.wrappropertybase, ident]),
126126

127127
Ty::SetRealmFn => LL::insert(transforms![&cfg.setrealmfn, "({})."]),
128128
Ty::ScramErrFn { ident } => LL::insert(transforms!["$scramerr(", ident, ");"]),
@@ -183,8 +183,8 @@ impl Ord for JsChange<'_, '_> {
183183
Ordering::Equal => match (&self.ty, &other.ty) {
184184
(Ty::ScramErrFn { .. }, _) => Ordering::Less,
185185
(_, Ty::ScramErrFn { .. }) => Ordering::Greater,
186-
(Ty::WrapFnRight { .. }, _) => Ordering::Less,
187-
(_, Ty::WrapFnRight { .. }) => Ordering::Greater,
186+
(Ty::WrapFnRight { .. }, _) => Ordering::Less,
187+
(_, Ty::WrapFnRight { .. }) => Ordering::Greater,
188188
_ => Ordering::Equal,
189189
},
190190
x => x,

rewriter/js/src/rewrite.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) enum RewriteType<'alloc: 'data, 'data> {
2828
MetaFn,
2929

3030
RewriteProperty {
31-
ident: Atom<'data>,
31+
ident: Atom<'data>,
3232
},
3333
WrapProperty,
3434

@@ -82,8 +82,7 @@ impl<'alloc: 'data, 'data> Rewrite<'alloc, 'data> {
8282

8383
impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
8484
fn into_inner(self, span: Span) -> SmallVec<[JsChange<'alloc, 'data>; 2]> {
85-
86-
dbg!(&self);
85+
dbg!(&self);
8786
macro_rules! span {
8887
(start) => {
8988
Span::new(span.start, span.start)
@@ -107,13 +106,11 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
107106
change!(span!(start), WrapFnLeft { enclose }),
108107
change!(span!(end), WrapFnRight { enclose }),
109108
],
110-
Self::RewriteProperty { ident } => smallvec![
111-
change!(span, RewriteProperty { ident }),
112-
],
113-
Self::WrapProperty => smallvec![
114-
change!(span!(start), WrapPropertyLeft),
115-
change!(span!(end), WrapPropertyRight),
116-
],
109+
Self::RewriteProperty { ident } => smallvec![change!(span, RewriteProperty { ident }),],
110+
Self::WrapProperty => smallvec![
111+
change!(span!(start), WrapPropertyLeft),
112+
change!(span!(end), WrapPropertyRight),
113+
],
117114
Self::SetRealmFn => smallvec![change!(span, SetRealmFn)],
118115
Self::ImportFn => smallvec![change!(span, ImportFn)],
119116
Self::MetaFn => smallvec![change!(span, MetaFn)],

rewriter/js/src/visitor.rs

Lines changed: 50 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ use std::error::Error;
33
use 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
}

rewriter/wasm/src/jsr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ fn get_config(scramjet: &Object) -> Result<Config> {
4949
Ok(Config {
5050
prefix: get_str(config, "prefix")?,
5151

52-
wrappropertybase: get_str(globals, "wrappropertybase")?,
53-
wrappropertyfn: get_str(globals, "wrappropertyfn")?,
52+
wrappropertybase: get_str(globals, "wrappropertybase")?,
53+
wrappropertyfn: get_str(globals, "wrappropertyfn")?,
5454
wrapfn: get_str(globals, "wrapfn")?,
5555
importfn: get_str(globals, "importfn")?,
5656
rewritefn: get_str(globals, "rewritefn")?,

0 commit comments

Comments
 (0)