Skip to content

Commit 4115c03

Browse files
committed
[core][rewriter] dpsc: implement WrapSetComputed
1 parent 237bf13 commit 4115c03

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

rewriter/js/src/changes.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub enum JsChangeType<'alloc: 'data, 'data> {
4949
ident: Atom<'data>,
5050
propspan: Span
5151
},
52+
WrapSetComputed,
5253

5354
/// insert `${cfg.setrealmfn}({}).`
5455
SetRealmFn,
@@ -142,6 +143,10 @@ impl<'alloc: 'data, 'data> Transform<'data> for JsChange<'alloc, 'data> {
142143
ident,
143144
"("
144145
]),
146+
Ty::WrapSetComputed => LL::insert(transforms![
147+
&cfg.wrapcomputedsetfn,
148+
"("
149+
]),
145150
Ty::SetRealmFn => LL::insert(transforms![&cfg.setrealmfn, "({})."]),
146151
Ty::ScramErrFn { ident } => LL::insert(transforms!["$scramerr(", ident, ");"]),
147152
Ty::ScramitizeFn => LL::insert(transforms![" $scramitize("]),

rewriter/js/src/rewrite.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,20 @@ impl<'alloc: 'data, 'data> RewriteType<'alloc, 'data> {
162162
}
163163
)
164164
],
165-
RewriteType::WrapSetComputed { .. } => todo!(),
165+
RewriteType::WrapSetComputed { leftspan, rightspan, propspan } => smallvec![
166+
change!(span!(start), WrapSetComputed),
167+
// replace the bracket with ,
168+
change!(Span::new(leftspan.end, propspan.start), Replace { text: "," }),
169+
// replace the other bracket with another ,
170+
change!(Span::new(propspan.end, rightspan.start), Replace { text: "," }),
171+
change!(
172+
span!(end),
173+
ClosingParen {
174+
semi: false,
175+
replace: true
176+
}
177+
)
178+
],
166179
Self::SetRealmFn => smallvec![change!(span, SetRealmFn)],
167180
Self::ImportFn => smallvec![change!(span, ImportFn)],
168181
Self::MetaFn => smallvec![change!(span, MetaFn)],

rewriter/js/src/visitor.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,15 @@ where
338338

339339
// more to walk
340340
walk::walk_expression(self, &s.object);
341+
}
342+
AssignmentTarget::ComputedMemberExpression(s)=> {
343+
self.jschanges.add(rewrite!(it.span, WrapSetComputed {
344+
propspan: s.expression.span(),
345+
leftspan: s.object.span(),
346+
rightspan: it.right.span(),
347+
}));
348+
walk::walk_expression(self, &s.object);
349+
walk::walk_expression(self, &s.expression);
341350
}
342351
AssignmentTarget::ArrayAssignmentTarget(_) => {
343352
// [location] = ["https://example.com"]

0 commit comments

Comments
 (0)