Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions crates/oxc_transformer/src/common/arrow_function_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/es2020/optional_chaining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading