Skip to content

Commit b9bd478

Browse files
committed
fix(transformer/class-properties): transform delete chain expression in static prop initializers
1 parent 2080da3 commit b9bd478

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

crates/oxc_transformer/src/es2022/class_properties/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ impl<'a, 'ctx> Traverse<'a> for ClassProperties<'a, 'ctx> {
252252
// `#[inline]` because this is a hot path
253253
#[inline]
254254
fn enter_expression(&mut self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
255-
// Note: `delete this.#prop` is an early syntax error, so no need to handle transforming it
255+
// NOTE: If add any other visitors here to handle private fields, also need to add them
256+
// to visitor in `static_prop.rs`.
256257
match expr {
257258
// `class {}`
258259
Expression::ClassExpression(_) => {

crates/oxc_transformer/src/es2022/class_properties/private.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,8 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
13601360
}
13611361
}
13621362

1363-
fn transform_unary_expression_impl(
1363+
// Note: This is also called by visitor in `static_prop.rs`
1364+
pub(super) fn transform_unary_expression_impl(
13641365
&mut self,
13651366
expr: &mut Expression<'a>,
13661367
ctx: &mut TraverseCtx<'a>,

crates/oxc_transformer/src/es2022/class_properties/static_prop.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,20 @@ impl<'a, 'ctx, 'v> VisitMut<'a> for StaticInitializerVisitor<'a, 'ctx, 'v> {
163163
self.replace_this_with_temp_var(expr, span);
164164
return;
165165
}
166-
// `delete this`
166+
// `delete this` / `delete object?.#prop.xyz`
167167
Expression::UnaryExpression(unary_expr) => {
168-
if unary_expr.operator == UnaryOperator::Delete
169-
&& matches!(&unary_expr.argument, Expression::ThisExpression(_))
170-
{
171-
let span = unary_expr.span;
172-
self.replace_delete_this_with_true(expr, span);
173-
return;
168+
if unary_expr.operator == UnaryOperator::Delete {
169+
match &unary_expr.argument {
170+
Expression::ThisExpression(_) => {
171+
let span = unary_expr.span;
172+
self.replace_delete_this_with_true(expr, span);
173+
return;
174+
}
175+
Expression::ChainExpression(_) => {
176+
self.class_properties.transform_unary_expression_impl(expr, self.ctx);
177+
}
178+
_ => {}
179+
}
174180
}
175181
}
176182
// `object.#prop`

0 commit comments

Comments
 (0)