Skip to content

Commit

Permalink
refactor(transformer/class-properties): remove all *_if_super methods…
Browse files Browse the repository at this point in the history
… in static_block_and_prop_init
  • Loading branch information
Dunqing committed Dec 25, 2024
1 parent 58808bf commit 8ab86d0
Showing 1 changed file with 13 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,27 @@ impl<'a, 'ctx, 'v> VisitMut<'a> for StaticVisitor<'a, 'ctx, 'v> {
}
}
// `super.prop`
Expression::StaticMemberExpression(_) => {
self.transform_static_member_expression_if_super(expr);
Expression::StaticMemberExpression(_) if self.this_depth == 0 => {
self.super_converter.transform_static_member_expression(expr, self.ctx);
}
// `super[prop]`
Expression::ComputedMemberExpression(_) => {
self.transform_computed_member_expression_if_super(expr);
Expression::ComputedMemberExpression(_) if self.this_depth == 0 => {
self.super_converter.transform_computed_member_expression(expr, self.ctx);
}
// `super.prop()`
Expression::CallExpression(call_expr) => {
self.transform_call_expression_if_super_member_expression(call_expr);
Expression::CallExpression(call_expr) if self.this_depth == 0 => {
self.super_converter
.transform_call_expression_for_super_member_expr(call_expr, self.ctx);
}
// `super.prop = value`, `super.prop += value`, `super.prop ??= value`
Expression::AssignmentExpression(_) => {
self.transform_assignment_expression_if_super_member_assignment_target(expr);
Expression::AssignmentExpression(_) if self.this_depth == 0 => {
self.super_converter
.transform_assignment_expression_for_super_assignment_target(expr, self.ctx);
}
// `super.prop++`, `--super.prop`
Expression::UpdateExpression(_) => {
self.transform_update_expression_if_super_member_assignment_target(expr);
Expression::UpdateExpression(_) if self.this_depth == 0 => {
self.super_converter
.transform_update_expression_for_super_assignment_target(expr, self.ctx);
}
_ => {}
}
Expand Down Expand Up @@ -535,58 +538,4 @@ impl<'a, 'ctx, 'v> StaticVisitor<'a, 'ctx, 'v> {
self.ctx.scopes_mut().change_parent_id(scope_id, Some(current_scope_id));
}
}

// `#[inline]` into visitor to keep common path where member expression isn't `super.prop` fast
#[inline]
fn transform_static_member_expression_if_super(&mut self, expr: &mut Expression<'a>) {
if self.this_depth == 0 {
self.super_converter.transform_static_member_expression(expr, self.ctx);
}
}

// `#[inline]` into visitor to keep common path where member expression isn't `super.prop` fast
#[inline]
fn transform_computed_member_expression_if_super(&mut self, expr: &mut Expression<'a>) {
if self.this_depth == 0 {
self.super_converter.transform_computed_member_expression(expr, self.ctx);
}
}

// `#[inline]` into visitor to keep common path where call expression isn't `super.prop()` fast
#[inline]
fn transform_call_expression_if_super_member_expression(
&mut self,
call_expr: &mut CallExpression<'a>,
) {
if self.this_depth == 0 {
self.super_converter
.transform_call_expression_for_super_member_expr(call_expr, self.ctx);
}
}

// `#[inline]` into visitor to keep common path where assignment expression isn't
// `super.prop += 1` fast
#[inline]
fn transform_assignment_expression_if_super_member_assignment_target(
&mut self,
expr: &mut Expression<'a>,
) {
if self.this_depth == 0 {
self.super_converter
.transform_assignment_expression_for_super_assignment_target(expr, self.ctx);
}
}

// `#[inline]` into visitor to keep common path where assignment expression isn't
// `super.prop++` fast
#[inline]
fn transform_update_expression_if_super_member_assignment_target(
&mut self,
expr: &mut Expression<'a>,
) {
if self.this_depth == 0 {
self.super_converter
.transform_update_expression_for_super_assignment_target(expr, self.ctx);
}
}
}

0 comments on commit 8ab86d0

Please sign in to comment.