diff --git a/crates/oxc_transformer/src/common/arrow_function_converter.rs b/crates/oxc_transformer/src/common/arrow_function_converter.rs index e0836c8292cff..dc8006e6f5bfa 100644 --- a/crates/oxc_transformer/src/common/arrow_function_converter.rs +++ b/crates/oxc_transformer/src/common/arrow_function_converter.rs @@ -102,7 +102,7 @@ use oxc_syntax::{ }; use oxc_traverse::{Ancestor, BoundIdentifier, Traverse, TraverseCtx}; -use crate::EnvOptions; +use crate::{utils::ast_builder::wrap_arrow_function_iife, EnvOptions}; type FxIndexMap = IndexMap; @@ -419,12 +419,7 @@ impl<'a> Traverse<'a> for ArrowFunctionConverter<'a> { // prop = (() => { return async () => {} })(); // } // ``` - Some(Self::wrap_arrow_function_with_iife( - arrow.span, - arrow.scope_id(), - expr, - ctx, - )) + Some(wrap_arrow_function_iife(expr, ctx)) } else { return; } @@ -1207,43 +1202,6 @@ impl<'a> ArrowFunctionConverter<'a> { statements.insert(0, stmt); } - - /// Wrap an arrow function with IIFE - /// - /// `() => {}` -> `(() => { return () => {}; })()` - fn wrap_arrow_function_with_iife( - span: Span, - scope_id: ScopeId, - expr: &mut Expression<'a>, - ctx: &mut TraverseCtx<'a>, - ) -> Expression<'a> { - let kind = FormalParameterKind::ArrowFormalParameters; - let params = ctx.ast.formal_parameters(SPAN, kind, ctx.ast.vec(), NONE); - let statement = ctx.ast.statement_return(SPAN, Some(ctx.ast.move_expression(expr))); - let statements = ctx.ast.vec1(statement); - let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), statements); - let parent_scope_id = ctx - .create_child_scope(ctx.current_scope_id(), ScopeFlags::Arrow | ScopeFlags::Function); - ctx.scopes_mut().change_parent_id(scope_id, Some(parent_scope_id)); - let arrow = ctx.ast.alloc_arrow_function_expression_with_scope_id( - SPAN, - false, - false, - NONE, - params, - NONE, - body, - parent_scope_id, - ); - // IIFE - ctx.ast.expression_call( - span, - Expression::ArrowFunctionExpression(arrow), - NONE, - ctx.ast.vec(), - false, - ) - } } /// Visitor for inserting `this` after `super` in constructor body.