Skip to content

Commit

Permalink
Refactor creating super(...args) call
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Oct 30, 2024
1 parent 71590c1 commit 65400df
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions crates/oxc_transformer/src/es2022/class_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
use serde::Deserialize;

use oxc_ast::{ast::*, AstBuilder, NONE};
use oxc_ast::{ast::*, NONE};
use oxc_span::SPAN;
use oxc_syntax::{node::NodeId, scope::ScopeFlags, symbol::SymbolFlags};
use oxc_traverse::{Ancestor, Traverse, TraverseCtx};
use oxc_traverse::{Ancestor, BoundIdentifier, Traverse, TraverseCtx};

use crate::{common::helper_loader::Helper, TransformCtx};

Expand Down Expand Up @@ -235,7 +235,7 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
);
params_rest =
Some(ctx.ast.alloc_binding_rest_element(SPAN, binding.create_binding_pattern(ctx)));
stmts.push(Self::create_super_call_stmt(binding.create_read_expression(ctx), ctx.ast));
stmts.push(Self::create_super_call_stmt(&binding, ctx));
}
// TODO: Should these have the span of the original `PropertyDefinition`s?
stmts.extend(inits.into_iter().map(|expr| ctx.ast.statement_expression(SPAN, expr)));
Expand Down Expand Up @@ -279,14 +279,18 @@ impl<'a, 'ctx> ClassProperties<'a, 'ctx> {
}

/// `super(...args);`
fn create_super_call_stmt(args_ident: Expression<'a>, ast: AstBuilder<'a>) -> Statement<'a> {
ast.statement_expression(
fn create_super_call_stmt(
binding: &BoundIdentifier<'a>,
ctx: &mut TraverseCtx<'a>,
) -> Statement<'a> {
let args_ident = binding.create_read_expression(ctx);
ctx.ast.statement_expression(
SPAN,
ast.expression_call(
ctx.ast.expression_call(
SPAN,
ast.expression_super(SPAN),
ctx.ast.expression_super(SPAN),
NONE,
ast.vec1(ast.argument_spread_element(SPAN, args_ident)),
ctx.ast.vec1(ctx.ast.argument_spread_element(SPAN, args_ident)),
false,
),
)
Expand Down

0 comments on commit 65400df

Please sign in to comment.