Skip to content

Commit 34091b2

Browse files
committed
refactor(transformer): use Expression::is_super (#7852)
Shorten code by using `Expression::is_super`, which was introduced in #7831.
1 parent d660d8d commit 34091b2

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

crates/oxc_transformer/src/common/arrow_function_converter.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -630,16 +630,17 @@ impl<'a> ArrowFunctionConverter<'a> {
630630
let mut property = "";
631631
let init = match expr.to_member_expression_mut() {
632632
MemberExpression::ComputedMemberExpression(computed_member) => {
633-
if !matches!(computed_member.object, Expression::Super(_)) {
633+
if !computed_member.object.is_super() {
634634
return None;
635635
}
636+
636637
// The property will as a parameter to pass to the new arrow function.
637638
// `super[property]` to `_superprop_get(property)`
638639
argument = Some(ctx.ast.move_expression(&mut computed_member.expression));
639640
ctx.ast.move_expression(&mut computed_member.object)
640641
}
641642
MemberExpression::StaticMemberExpression(static_member) => {
642-
if !matches!(static_member.object, Expression::Super(_)) {
643+
if !static_member.object.is_super() {
643644
return None;
644645
}
645646

@@ -741,10 +742,7 @@ impl<'a> ArrowFunctionConverter<'a> {
741742
) -> Option<Expression<'a>> {
742743
// Check if the left of the assignment is a `super` member expression.
743744
if self.super_methods.is_none()
744-
|| !assignment
745-
.left
746-
.as_member_expression()
747-
.is_some_and(|m| matches!(m.object(), Expression::Super(_)))
745+
|| !assignment.left.as_member_expression().is_some_and(|m| m.object().is_super())
748746
{
749747
return None;
750748
}

crates/oxc_transformer/src/es2020/optional_chaining.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ impl<'a, 'ctx> OptionalChaining<'a, 'ctx> {
595595
binding.to_maybe_bound_identifier()
596596
});
597597
self.set_binding_context(binding);
598-
} else if matches!(object, Expression::Super(_)) {
598+
} else if object.is_super() {
599599
self.set_this_context();
600600
}
601601
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a, 'c> VisitMut<'a> for ConstructorParamsSuperReplacer<'a, 'c> {
495495
#[inline]
496496
fn visit_expression(&mut self, expr: &mut Expression<'a>) {
497497
if let Expression::CallExpression(call_expr) = expr {
498-
if let Expression::Super(_) = &call_expr.callee {
498+
if call_expr.callee.is_super() {
499499
// Walk `CallExpression`'s arguments here rather than falling through to `walk_expression`
500500
// below to avoid infinite loop as `super()` gets visited over and over
501501
self.visit_arguments(&mut call_expr.arguments);
@@ -610,7 +610,7 @@ impl<'a, 'c> ConstructorBodySuperReplacer<'a, 'c> {
610610
// We can avoid a nested `_super` function for this common case.
611611
if let Statement::ExpressionStatement(expr_stmt) = &*stmt {
612612
if let Expression::CallExpression(call_expr) = &expr_stmt.expression {
613-
if let Expression::Super(_) = &call_expr.callee {
613+
if call_expr.callee.is_super() {
614614
let insert_location =
615615
InstanceInitsInsertLocation::ExistingConstructor(index + 1);
616616
return (self.constructor_scope_id, insert_location);

0 commit comments

Comments
 (0)