refactor(transformer): use Expression::is_super (#7852)

Shorten code by using `Expression::is_super`, which was introduced in #7831.
This commit is contained in:
overlookmotel 2024-12-13 15:05:12 +00:00
parent d660d8d12d
commit 34091b2e7a
3 changed files with 7 additions and 9 deletions

View file

@ -630,16 +630,17 @@ impl<'a> ArrowFunctionConverter<'a> {
let mut property = "";
let init = match expr.to_member_expression_mut() {
MemberExpression::ComputedMemberExpression(computed_member) => {
if !matches!(computed_member.object, Expression::Super(_)) {
if !computed_member.object.is_super() {
return None;
}
// The property will as a parameter to pass to the new arrow function.
// `super[property]` to `_superprop_get(property)`
argument = Some(ctx.ast.move_expression(&mut computed_member.expression));
ctx.ast.move_expression(&mut computed_member.object)
}
MemberExpression::StaticMemberExpression(static_member) => {
if !matches!(static_member.object, Expression::Super(_)) {
if !static_member.object.is_super() {
return None;
}
@ -741,10 +742,7 @@ impl<'a> ArrowFunctionConverter<'a> {
) -> Option<Expression<'a>> {
// Check if the left of the assignment is a `super` member expression.
if self.super_methods.is_none()
|| !assignment
.left
.as_member_expression()
.is_some_and(|m| matches!(m.object(), Expression::Super(_)))
|| !assignment.left.as_member_expression().is_some_and(|m| m.object().is_super())
{
return None;
}

View file

@ -595,7 +595,7 @@ impl<'a, 'ctx> OptionalChaining<'a, 'ctx> {
binding.to_maybe_bound_identifier()
});
self.set_binding_context(binding);
} else if matches!(object, Expression::Super(_)) {
} else if object.is_super() {
self.set_this_context();
}
}

View file

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