Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ impl<'a> ArrowFunctionConverter<'a> {

/// Traverses upward through ancestor nodes to find the `ScopeId` of the block
/// that potential affects the `this` expression.
fn get_scope_id_from_this_affected_block(&self, ctx: &mut TraverseCtx<'a>) -> Option<ScopeId> {
fn get_scope_id_from_this_affected_block(&self, ctx: &TraverseCtx<'a>) -> Option<ScopeId> {
// `this` inside a class resolves to `this` *outside* the class in:
// * `extends` clause
// * Computed method key
Expand Down Expand Up @@ -678,7 +678,7 @@ impl<'a> ArrowFunctionConverter<'a> {

/// Check whether currently in a class property initializer.
/// e.g. `x` in `class C { prop = [foo(x)]; }`
fn in_class_property_definition_value(ctx: &mut TraverseCtx<'a>) -> bool {
fn in_class_property_definition_value(ctx: &TraverseCtx<'a>) -> bool {
for ancestor in ctx.ancestors() {
if ancestor.is_parent_of_statement() {
return false;
Expand Down Expand Up @@ -1131,7 +1131,7 @@ impl<'a> ArrowFunctionConverter<'a> {

/// Insert variable statement at the top of the statements.
fn insert_variable_statement_at_the_top_of_statements(
&mut self,
&self,
target_scope_id: ScopeId,
statements: &mut ArenaVec<'a, Statement<'a>>,
this_var: Option<BoundIdentifier<'a>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/common/helper_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'a> HelperLoaderStore<'a> {
}

// Construct string directly in arena without an intermediate temp allocation
fn get_runtime_source(&self, helper: Helper, ctx: &mut TraverseCtx<'a>) -> Atom<'a> {
fn get_runtime_source(&self, helper: Helper, ctx: &TraverseCtx<'a>) -> Atom<'a> {
let helper_name = helper.name();
let len = self.module_name.len() + "/helpers/".len() + helper_name.len();
let mut source = ArenaString::with_capacity_in(len, ctx.ast.allocator);
Expand Down
6 changes: 1 addition & 5 deletions crates/oxc_transformer/src/common/module_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,7 @@ impl<'a> ModuleImportsStore<'a> {
}
}

fn insert_import_statements(
&self,
transform_ctx: &TransformCtx<'a>,
ctx: &mut TraverseCtx<'a>,
) {
fn insert_import_statements(&self, transform_ctx: &TransformCtx<'a>, ctx: &TraverseCtx<'a>) {
let mut imports = self.imports.borrow_mut();
let stmts = imports.drain(..).map(|(source, names)| Self::get_import(source, names, ctx));
transform_ctx.top_level_statements.insert_statements(stmts);
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/common/statement_injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl<'a> StatementInjectorStore<'a> {
fn insert_into_statements(
&self,
statements: &mut ArenaVec<'a, Statement<'a>>,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) {
let mut insertions = self.insertions.borrow_mut();
if insertions.is_empty() {
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_transformer/src/common/var_declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl<'a> VarDeclarationsStore<'a> {
fn insert_into_statements(
&self,
stmts: &mut ArenaVec<'a, Statement<'a>>,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) {
if matches!(ctx.parent(), Ancestor::ProgramBody(_)) {
// Handle in `insert_into_program` instead
Expand All @@ -219,7 +219,7 @@ impl<'a> VarDeclarationsStore<'a> {
}
}

fn insert_into_program(&self, transform_ctx: &TransformCtx<'a>, ctx: &mut TraverseCtx<'a>) {
fn insert_into_program(&self, transform_ctx: &TransformCtx<'a>, ctx: &TraverseCtx<'a>) {
if let Some(insert_stmts) = self.get_var_statement(ctx) {
// Delegate to `TopLevelStatements`
transform_ctx.top_level_statements.insert_statements(insert_stmts);
Expand All @@ -231,7 +231,7 @@ impl<'a> VarDeclarationsStore<'a> {
debug_assert!(stack.last().is_none());
}

fn get_var_statement(&self, ctx: &mut TraverseCtx<'a>) -> Option<Vec<Statement<'a>>> {
fn get_var_statement(&self, ctx: &TraverseCtx<'a>) -> Option<Vec<Statement<'a>>> {
let mut stack = self.stack.borrow_mut();
let Declarators { var_declarators, let_declarators } = stack.pop()?;

Expand All @@ -256,7 +256,7 @@ impl<'a> VarDeclarationsStore<'a> {
fn create_declaration(
kind: VariableDeclarationKind,
declarators: ArenaVec<'a, VariableDeclarator<'a>>,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) -> Statement<'a> {
Statement::VariableDeclaration(ctx.ast.alloc_variable_declaration(
SPAN,
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_transformer/src/decorator/legacy/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ impl<'a> LegacyDecoratorMetadata<'a, '_> {
fn create_checked_value(
left: Expression<'a>,
right: Expression<'a>,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) -> Expression<'a> {
let operator = BinaryOperator::StrictEquality;
let undefined = ctx.ast.expression_string_literal(SPAN, "undefined", None);
Expand All @@ -570,7 +570,7 @@ impl<'a> LegacyDecoratorMetadata<'a, '_> {

// `_metadata(key, value)
fn create_metadata_decorate(
&mut self,
&self,
key: &str,
value: Expression<'a>,
ctx: &mut TraverseCtx<'a>,
Expand Down
26 changes: 9 additions & 17 deletions crates/oxc_transformer/src/decorator/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<'a> LegacyDecorator<'a, '_> {
/// ```
// `#[inline]` so that compiler sees that `stmt` is a `Statement::ClassDeclaration`.
#[inline]
fn transform_class(&mut self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
fn transform_class(&self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
let Statement::ClassDeclaration(class) = stmt else { unreachable!() };

let stmt_address = class.address();
Expand Down Expand Up @@ -200,11 +200,7 @@ impl<'a> LegacyDecorator<'a, '_> {
/// ```
// `#[inline]` so that compiler sees that `stmt` is a `Statement::ExportDefaultDeclaration`.
#[inline]
fn transform_export_default_class(
&mut self,
stmt: &mut Statement<'a>,
ctx: &mut TraverseCtx<'a>,
) {
fn transform_export_default_class(&self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
let Statement::ExportDefaultDeclaration(export) = stmt else { unreachable!() };
let stmt_address = export.address();
let ExportDefaultDeclarationKind::ClassDeclaration(class) = &mut export.declaration else {
Expand Down Expand Up @@ -251,11 +247,7 @@ impl<'a> LegacyDecorator<'a, '_> {
/// ```
// `#[inline]` so that compiler sees that `stmt` is a `Statement::ExportNamedDeclaration`.
#[inline]
fn transform_export_named_class(
&mut self,
stmt: &mut Statement<'a>,
ctx: &mut TraverseCtx<'a>,
) {
fn transform_export_named_class(&self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
let Statement::ExportNamedDeclaration(export) = stmt else { unreachable!() };
let stmt_address = export.address();
let Some(Declaration::ClassDeclaration(class)) = &mut export.declaration else { return };
Expand All @@ -272,7 +264,7 @@ impl<'a> LegacyDecorator<'a, '_> {
}

fn transform_class_impl(
&mut self,
&self,
class: &mut Class<'a>,
stmt_address: Address,
ctx: &mut TraverseCtx<'a>,
Expand Down Expand Up @@ -305,7 +297,7 @@ impl<'a> LegacyDecorator<'a, '_> {
/// Transforms a decorated class declaration and appends the resulting statements. If
/// the class requires an alias to avoid issues with double-binding, the alias is returned.
fn transform_class_declaration_with_class_decorators(
&mut self,
&self,
class: &mut Class<'a>,
has_private_in_expression_in_decorator: bool,
ctx: &mut TraverseCtx<'a>,
Expand Down Expand Up @@ -462,7 +454,7 @@ impl<'a> LegacyDecorator<'a, '_> {

/// Transforms a non-decorated class declaration.
fn transform_class_declaration_without_class_decorators(
&mut self,
&self,
class: &mut Class<'a>,
stmt_address: Address,
has_private_in_expression_in_decorator: bool,
Expand Down Expand Up @@ -490,7 +482,7 @@ impl<'a> LegacyDecorator<'a, '_> {
/// Transform decorators of [`ClassElement::MethodDefinition`],
/// [`ClassElement::PropertyDefinition`] and [`ClassElement::AccessorProperty`].
fn transform_decorators_of_class_elements(
&mut self,
&self,
class: &mut Class<'a>,
class_binding: &BoundIdentifier<'a>,
ctx: &mut TraverseCtx<'a>,
Expand Down Expand Up @@ -680,7 +672,7 @@ impl<'a> LegacyDecorator<'a, '_> {
/// Converts a vec of [`Decorator`] to [`Expression::ArrayExpression`].
fn convert_decorators_to_array_expression(
decorators_iter: impl Iterator<Item = Decorator<'a>>,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) -> Expression<'a> {
let decorations = ctx.ast.vec_from_iter(
decorators_iter.map(|decorator| ArrayExpressionElement::from(decorator.expression)),
Expand Down Expand Up @@ -841,7 +833,7 @@ impl<'a> LegacyDecorator<'a, '_> {
/// * Non-copiable key:
/// * `[a()] = 0;` mutates the key to `[_a = a()] = 0;` and returns `_a`
fn get_name_of_property_key(
&mut self,
&self,
key: &mut PropertyKey<'a>,
ctx: &mut TraverseCtx<'a>,
) -> Expression<'a> {
Expand Down
28 changes: 12 additions & 16 deletions crates/oxc_transformer/src/es2016/exponentiation_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
//
// `#[inline]` so compiler knows `expr` is an `AssignmentExpression` with `IdentifierReference` on left
#[inline]
fn convert_identifier_assignment(
&mut self,
expr: &mut Expression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
fn convert_identifier_assignment(&self, expr: &mut Expression<'a>, ctx: &mut TraverseCtx<'a>) {
let Expression::AssignmentExpression(assign_expr) = expr else { unreachable!() };
let AssignmentTarget::AssignmentTargetIdentifier(ident) = &mut assign_expr.left else {
unreachable!()
Expand All @@ -142,8 +138,8 @@ impl<'a> ExponentiationOperator<'a, '_> {

/// Get left side of `Math.pow(pow_left, ...)` for identifier
fn get_pow_left_identifier(
&mut self,
ident: &mut IdentifierReference<'a>,
&self,
ident: &IdentifierReference<'a>,
ctx: &mut TraverseCtx<'a>,
) -> (
// Left side of `Math.pow(pow_left, ...)`
Expand Down Expand Up @@ -196,7 +192,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
// `#[inline]` so compiler knows `expr` is an `AssignmentExpression` with `StaticMemberExpression` on left
#[inline]
fn convert_static_member_expression_assignment(
&mut self,
&self,
expr: &mut Expression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
Expand All @@ -215,7 +211,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
/// Get left side of `Math.pow(pow_left, ...)` for static member expression
/// and replacement for left side of assignment.
fn get_pow_left_static_member(
&mut self,
&self,
member_expr: &mut StaticMemberExpression<'a>,
ctx: &mut TraverseCtx<'a>,
) -> (
Expand Down Expand Up @@ -295,7 +291,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
// `#[inline]` so compiler knows `expr` is an `AssignmentExpression` with `ComputedMemberExpression` on left
#[inline]
fn convert_computed_member_expression_assignment(
&mut self,
&self,
expr: &mut Expression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
Expand All @@ -311,7 +307,7 @@ impl<'a> ExponentiationOperator<'a, '_> {

/// Get left side of `Math.pow(pow_left, ...)` for computed member expression
fn get_pow_left_computed_member(
&mut self,
&self,
member_expr: &mut ComputedMemberExpression<'a>,
ctx: &mut TraverseCtx<'a>,
) -> (
Expand Down Expand Up @@ -376,7 +372,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
// `#[inline]` so compiler knows `expr` is an `AssignmentExpression` with `PrivateFieldExpression` on left
#[inline]
fn convert_private_field_assignment(
&mut self,
&self,
expr: &mut Expression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
Expand All @@ -393,7 +389,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
/// Get left side of `Math.pow(pow_left, ...)` for static member expression
/// and replacement for left side of assignment.
fn get_pow_left_private_field(
&mut self,
&self,
field_expr: &mut PrivateFieldExpression<'a>,
ctx: &mut TraverseCtx<'a>,
) -> (
Expand Down Expand Up @@ -472,7 +468,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
/// ^^^^^^^^^^^^^^^^^^^^^^^^^^ added to `temp_var_inits`
/// ```
fn get_second_member_expression_object(
&mut self,
&self,
obj: &mut Expression<'a>,
temp_var_inits: &mut ArenaVec<'a, Expression<'a>>,
ctx: &mut TraverseCtx<'a>,
Expand Down Expand Up @@ -522,7 +518,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
fn revise_expression(
expr: &mut Expression<'a>,
mut temp_var_inits: ArenaVec<'a, Expression<'a>>,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) {
if !temp_var_inits.is_empty() {
temp_var_inits.reserve_exact(1);
Expand Down Expand Up @@ -552,7 +548,7 @@ impl<'a> ExponentiationOperator<'a, '_> {
/// Add initialization expression `_name = expr` to `temp_var_inits`.
/// Return `BoundIdentifier` for the temp var.
fn create_temp_var(
&mut self,
&self,
expr: Expression<'a>,
temp_var_inits: &mut ArenaVec<'a, Expression<'a>>,
ctx: &mut TraverseCtx<'a>,
Expand Down
10 changes: 5 additions & 5 deletions crates/oxc_transformer/src/es2017/async_to_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl<'a> Traverse<'a> for AsyncToGenerator<'a, '_> {

impl<'a> AsyncToGenerator<'a, '_> {
/// Check whether the current node is inside an async function.
fn is_inside_async_function(ctx: &mut TraverseCtx<'a>) -> bool {
fn is_inside_async_function(ctx: &TraverseCtx<'a>) -> bool {
// Early return if current scope is top because we don't need to transform top-level await expression.
if ctx.current_scope_flags().is_top() {
return false;
Expand All @@ -168,7 +168,7 @@ impl<'a> AsyncToGenerator<'a, '_> {
/// Ignores top-level await expressions.
fn transform_await_expression(
expr: &mut AwaitExpression<'a>,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) -> Option<Expression<'a>> {
// We don't need to handle top-level await.
if Self::is_inside_async_function(ctx) {
Expand Down Expand Up @@ -556,7 +556,7 @@ impl<'a, 'ctx> AsyncGeneratorExecutor<'a, 'ctx> {
}

/// Infers the function name from the [`TraverseCtx::parent`].
fn infer_function_name_from_parent_node(ctx: &mut TraverseCtx<'a>) -> Option<Atom<'a>> {
fn infer_function_name_from_parent_node(ctx: &TraverseCtx<'a>) -> Option<Atom<'a>> {
match ctx.parent() {
// infer `foo` from `const foo = async function() {}`
Ancestor::VariableDeclaratorInit(declarator) => {
Expand Down Expand Up @@ -628,7 +628,7 @@ impl<'a, 'ctx> AsyncGeneratorExecutor<'a, 'ctx> {
params: ArenaBox<'a, FormalParameters<'a>>,
body: ArenaBox<'a, FunctionBody<'a>>,
scope_id: ScopeId,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) -> ArenaBox<'a, Function<'a>> {
let r#type = if id.is_some() {
FunctionType::FunctionDeclaration
Expand Down Expand Up @@ -794,7 +794,7 @@ impl<'a, 'ctx> AsyncGeneratorExecutor<'a, 'ctx> {

/// Creates an empty [FormalParameters] with [FormalParameterKind::FormalParameter].
#[inline]
fn create_empty_params(ctx: &mut TraverseCtx<'a>) -> ArenaBox<'a, FormalParameters<'a>> {
fn create_empty_params(ctx: &TraverseCtx<'a>) -> ArenaBox<'a, FormalParameters<'a>> {
ctx.ast.alloc_formal_parameters(
SPAN,
FormalParameterKind::FormalParameter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> {
)
}

pub(crate) fn transform_statement(
&mut self,
stmt: &mut Statement<'a>,
ctx: &mut TraverseCtx<'a>,
) {
pub(crate) fn transform_statement(&self, stmt: &mut Statement<'a>, ctx: &mut TraverseCtx<'a>) {
let (for_of, label) = match stmt {
Statement::LabeledStatement(labeled) => {
let LabeledStatement { label, body, .. } = labeled.as_mut();
Expand Down Expand Up @@ -93,7 +89,7 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> {
}

pub(self) fn transform_for_of_statement(
&mut self,
&self,
stmt: &mut ForOfStatement<'a>,
parent_scope_id: ScopeId,
ctx: &mut TraverseCtx<'a>,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_transformer/src/es2018/object_rest_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl<'a> ObjectRestSpread<'a, '_> {
}

fn walk_and_replace_nested_object_target(
&mut self,
&self,
expr: &mut Expression<'a>,
ctx: &mut TraverseCtx<'a>,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'a> Traverse<'a> for NullishCoalescingOperator<'a, '_> {

impl<'a> NullishCoalescingOperator<'a, '_> {
fn transform_logical_expression(
&mut self,
&self,
logical_expr: ArenaBox<'a, LogicalExpression<'a>>,
ctx: &mut TraverseCtx<'a>,
) -> Expression<'a> {
Expand Down Expand Up @@ -205,7 +205,7 @@ impl<'a> NullishCoalescingOperator<'a, '_> {
reference2: Expression<'a>,
default: Expression<'a>,
span: Span,
ctx: &mut TraverseCtx<'a>,
ctx: &TraverseCtx<'a>,
) -> Expression<'a> {
let op = BinaryOperator::StrictInequality;
let null = ctx.ast.expression_null_literal(SPAN);
Expand Down
Loading
Loading