diff --git a/crates/oxc_transformer/src/common/arrow_function_converter.rs b/crates/oxc_transformer/src/common/arrow_function_converter.rs index e078c3429f2a2..7b9336c88a14e 100644 --- a/crates/oxc_transformer/src/common/arrow_function_converter.rs +++ b/crates/oxc_transformer/src/common/arrow_function_converter.rs @@ -649,7 +649,7 @@ impl<'a> ArrowFunctionConverter<'a> { body.statements.push(return_statement); } - Expression::FunctionExpression(ctx.ast.alloc_function_with_scope_id( + ctx.ast.expression_function_with_scope_id_and_pure( arrow_function_expr.span, FunctionType::FunctionExpression, None, @@ -662,7 +662,8 @@ impl<'a> ArrowFunctionConverter<'a> { arrow_function_expr.return_type, Some(body), scope_id, - )) + false, + ) } /// Check whether the given [`Ancestor`] is a class method-like node. @@ -953,14 +954,14 @@ impl<'a> ArrowFunctionConverter<'a> { ); let statements = ctx.ast.vec1(ctx.ast.statement_expression(SPAN, init)); let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), statements); - let init = ctx.ast.alloc_arrow_function_expression_with_scope_id_and_pure( + let init = ctx.ast.expression_arrow_function_with_scope_id_and_pure( SPAN, true, false, NONE, params, NONE, body, scope_id, false, ); ctx.ast.variable_declarator( SPAN, VariableDeclarationKind::Var, binding.create_binding_pattern(ctx), - Some(Expression::ArrowFunctionExpression(init)), + Some(init), false, ) } diff --git a/crates/oxc_transformer/src/decorator/legacy/mod.rs b/crates/oxc_transformer/src/decorator/legacy/mod.rs index df972f332e663..c652258db72df 100644 --- a/crates/oxc_transformer/src/decorator/legacy/mod.rs +++ b/crates/oxc_transformer/src/decorator/legacy/mod.rs @@ -631,8 +631,7 @@ impl<'a> LegacyDecorator<'a, '_> { ctx: &mut TraverseCtx<'a>, ) { let scope_id = ctx.create_child_scope(class.scope_id(), ScopeFlags::ClassStaticBlock); - let static_block = ctx.ast.alloc_static_block_with_scope_id(SPAN, decorations, scope_id); - let element = ClassElement::StaticBlock(static_block); + let element = ctx.ast.class_element_static_block_with_scope_id(SPAN, decorations, scope_id); class.body.body.push(element); } diff --git a/crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs b/crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs index 1e94ddbc8e57d..8a6b24673f2a6 100644 --- a/crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs +++ b/crates/oxc_transformer/src/es2018/async_generator_functions/for_await.rs @@ -79,11 +79,11 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> { // with a block statement, this way we can ensure can insert statement correctly. // e.g. `if (true) statement` to `if (true) { statement }` if !allow_multiple_statements { - new_stmt = Statement::BlockStatement(ctx.ast.alloc_block_statement_with_scope_id( + new_stmt = ctx.ast.statement_block_with_scope_id( SPAN, ctx.ast.vec1(new_stmt), parent_scope_id, - )); + ); } *stmt = new_stmt; } @@ -253,7 +253,7 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> { let for_statement_scope_id = ctx.create_child_scope(block_scope_id, ScopeFlags::empty()); - let for_statement = Statement::ForStatement(ctx.ast.alloc_for_statement_with_scope_id( + let for_statement = ctx.ast.statement_for_with_scope_id( SPAN, Some(ctx.ast.for_statement_init_variable_declaration( SPAN, @@ -329,14 +329,10 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> { ); } - Statement::BlockStatement(ctx.ast.alloc_block_statement_with_scope_id( - SPAN, - body, - for_of_scope_id, - )) + ctx.ast.statement_block_with_scope_id(SPAN, body, for_of_scope_id) }, for_statement_scope_id, - )); + ); ctx.ast.block_statement_with_scope_id(SPAN, ctx.ast.vec1(for_statement), block_scope_id) }; @@ -408,7 +404,7 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> { ctx.ast.expression_null_literal(SPAN), ), ), - Statement::BlockStatement(ctx.ast.alloc_block_statement_with_scope_id( + ctx.ast.statement_block_with_scope_id( SPAN, ctx.ast.vec1(ctx.ast.statement_expression( SPAN, @@ -429,7 +425,7 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> { ), )), if_block_scope_id, - )), + ), None, ) }; @@ -447,14 +443,14 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> { ctx.ast.statement_if( SPAN, iterator_had_error_key.create_read_expression(ctx), - Statement::BlockStatement(ctx.ast.alloc_block_statement_with_scope_id( + ctx.ast.statement_block_with_scope_id( SPAN, ctx.ast.vec1(ctx.ast.statement_throw( SPAN, iterator_error_key.create_read_expression(ctx), )), if_block_scope_id, - )), + ), None, ) }; diff --git a/crates/oxc_transformer/src/es2018/object_rest_spread.rs b/crates/oxc_transformer/src/es2018/object_rest_spread.rs index ed3f55f32e4df..6e02498df4d1f 100644 --- a/crates/oxc_transformer/src/es2018/object_rest_spread.rs +++ b/crates/oxc_transformer/src/es2018/object_rest_spread.rs @@ -671,9 +671,7 @@ impl<'a> ObjectRestSpread<'a, '_> { let span = stmt.span(); (span, ctx.ast.vec1(ctx.ast.move_statement(stmt))) }; - *stmt = Statement::BlockStatement( - ctx.ast.alloc_block_statement_with_scope_id(span, stmts, scope_id), - ); + *stmt = ctx.ast.statement_block_with_scope_id(span, stmts, scope_id); scope_id } diff --git a/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs b/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs index 71d32c2e77a9e..c2f3fdeb4c20e 100644 --- a/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs +++ b/crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs @@ -157,18 +157,16 @@ impl<'a> NullishCoalescingOperator<'a, '_> { ctx.ast.vec(), ctx.ast.vec1(ctx.ast.statement_expression(SPAN, new_expr)), ); - let arrow_function = Expression::ArrowFunctionExpression( - ctx.ast.alloc_arrow_function_expression_with_scope_id_and_pure( - SPAN, - true, - false, - NONE, - params, - NONE, - body, - current_scope_id, - false, - ), + let arrow_function = ctx.ast.expression_arrow_function_with_scope_id_and_pure( + SPAN, + true, + false, + NONE, + params, + NONE, + body, + current_scope_id, + false, ); // `(x) => x;` -> `((x) => x)();` new_expr = ctx.ast.expression_call(SPAN, arrow_function, NONE, ctx.ast.vec(), false); diff --git a/crates/oxc_transformer/src/es2022/class_properties/constructor.rs b/crates/oxc_transformer/src/es2022/class_properties/constructor.rs index 85dc9b64e860b..9128ff093d333 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/constructor.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/constructor.rs @@ -324,26 +324,24 @@ impl<'a> ClassProperties<'a, '_> { let body = ctx.ast.vec1(ctx.ast.statement_expression(SPAN, body_exprs)); // `(..._args) => (super(..._args), , this)` - let super_func = Expression::ArrowFunctionExpression( - ctx.ast.alloc_arrow_function_expression_with_scope_id_and_pure( + let super_func = ctx.ast.expression_arrow_function_with_scope_id_and_pure( + SPAN, + true, + false, + NONE, + ctx.ast.alloc_formal_parameters( SPAN, - true, - false, - NONE, - ctx.ast.alloc_formal_parameters( - SPAN, - FormalParameterKind::ArrowFormalParameters, - ctx.ast.vec(), - Some(ctx.ast.alloc_binding_rest_element( - SPAN, - args_binding.create_binding_pattern(ctx), - )), + FormalParameterKind::ArrowFormalParameters, + ctx.ast.vec(), + Some( + ctx.ast + .alloc_binding_rest_element(SPAN, args_binding.create_binding_pattern(ctx)), ), - NONE, - ctx.ast.alloc_function_body(SPAN, ctx.ast.vec(), body), - super_func_scope_id, - false, ), + NONE, + ctx.ast.alloc_function_body(SPAN, ctx.ast.vec(), body), + super_func_scope_id, + false, ); // `var _super = (..._args) => ( ... );` @@ -389,7 +387,7 @@ impl<'a> ClassProperties<'a, '_> { let body_stmts = ctx.ast.vec_from_iter(exprs_into_stmts(inits, ctx).chain([return_stmt])); // `function() { ; return this; }` let super_func_scope_id = self.instance_inits_scope_id; - let super_func = Expression::FunctionExpression(ctx.ast.alloc_function_with_scope_id( + let super_func = ctx.ast.expression_function_with_scope_id_and_pure( SPAN, FunctionType::FunctionExpression, None, @@ -407,7 +405,8 @@ impl<'a> ClassProperties<'a, '_> { NONE, Some(ctx.ast.alloc_function_body(SPAN, directives, body_stmts)), super_func_scope_id, - )); + false, + ); // Insert `_super` function after class. // TODO: Need to add `_super` function to class as a static method, and then remove it again diff --git a/crates/oxc_transformer/src/jsx/refresh.rs b/crates/oxc_transformer/src/jsx/refresh.rs index 89ab7fa91ae2a..284084bd8dc3f 100644 --- a/crates/oxc_transformer/src/jsx/refresh.rs +++ b/crates/oxc_transformer/src/jsx/refresh.rs @@ -593,7 +593,7 @@ impl<'a> ReactRefresh<'a, '_> { )), ); let scope_id = ctx.create_child_scope_of_current(ScopeFlags::Function); - let function = Argument::FunctionExpression(ctx.ast.alloc_function_with_scope_id( + let function = Argument::from(ctx.ast.expression_function_with_scope_id_and_pure( SPAN, FunctionType::FunctionExpression, None, @@ -606,6 +606,7 @@ impl<'a> ReactRefresh<'a, '_> { NONE, Some(function_body), scope_id, + false, )); arguments.push(function); } diff --git a/crates/oxc_transformer/src/plugins/module_runner_transform.rs b/crates/oxc_transformer/src/plugins/module_runner_transform.rs index ce369cebee2aa..5bc86951f6338 100644 --- a/crates/oxc_transformer/src/plugins/module_runner_transform.rs +++ b/crates/oxc_transformer/src/plugins/module_runner_transform.rs @@ -722,7 +722,7 @@ impl<'a> ModuleRunnerTransform<'a> { let body = ctx.ast.function_body(SPAN, ctx.ast.vec(), ctx.ast.vec1(statement)); let r#type = FunctionType::FunctionExpression; let scope_id = ctx.create_child_scope(ctx.scopes().root_scope_id(), ScopeFlags::Function); - let function = ctx.ast.alloc_function_with_scope_id( + ctx.ast.expression_function_with_scope_id_and_pure( SPAN, r#type, None, @@ -735,8 +735,8 @@ impl<'a> ModuleRunnerTransform<'a> { NONE, Some(body), scope_id, - ); - Expression::FunctionExpression(function) + false, + ) } // `Object.defineProperty(__vite_ssr_exports__, 'foo', {enumerable: true, configurable: true, get(){ return foo }});` diff --git a/crates/oxc_transformer/src/typescript/annotations.rs b/crates/oxc_transformer/src/typescript/annotations.rs index 6fa4d6378ff3a..e8e9270c03969 100644 --- a/crates/oxc_transformer/src/typescript/annotations.rs +++ b/crates/oxc_transformer/src/typescript/annotations.rs @@ -575,8 +575,7 @@ impl<'a> TypeScriptAnnotations<'a, '_> { ctx: &mut TraverseCtx<'a>, ) -> Statement<'a> { let scope_id = ctx.insert_scope_below_statement(&stmt, ScopeFlags::empty()); - let block = ctx.ast.alloc_block_statement_with_scope_id(span, ctx.ast.vec1(stmt), scope_id); - Statement::BlockStatement(block) + ctx.ast.statement_block_with_scope_id(span, ctx.ast.vec1(stmt), scope_id) } fn replace_for_statement_body_with_empty_block_if_ts( @@ -594,9 +593,7 @@ impl<'a> TypeScriptAnnotations<'a, '_> { ) { if stmt.is_typescript_syntax() { let scope_id = ctx.create_child_scope(parent_scope_id, ScopeFlags::empty()); - let block = - ctx.ast.alloc_block_statement_with_scope_id(stmt.span(), ctx.ast.vec(), scope_id); - *stmt = Statement::BlockStatement(block); + *stmt = ctx.ast.statement_block_with_scope_id(stmt.span(), ctx.ast.vec(), scope_id); } } diff --git a/crates/oxc_transformer/src/typescript/enum.rs b/crates/oxc_transformer/src/typescript/enum.rs index 07278b350d3a5..677c5ccf02e3c 100644 --- a/crates/oxc_transformer/src/typescript/enum.rs +++ b/crates/oxc_transformer/src/typescript/enum.rs @@ -111,7 +111,7 @@ impl<'a> TypeScriptEnum<'a> { let statements = self.transform_ts_enum_members(decl.scope_id(), &mut decl.members, ¶m_binding, ctx); let body = ast.alloc_function_body(decl.span, ast.vec(), statements); - let callee = Expression::FunctionExpression(ctx.ast.alloc_function_with_scope_id( + let callee = ctx.ast.expression_function_with_scope_id_and_pure( SPAN, FunctionType::FunctionExpression, None, @@ -124,7 +124,8 @@ impl<'a> TypeScriptEnum<'a> { NONE, Some(body), func_scope_id, - )); + false, + ); let var_symbol_id = decl.id.symbol_id(); let arguments = if (is_export || is_not_top_scope) && !is_already_declared { diff --git a/crates/oxc_transformer/src/utils/ast_builder.rs b/crates/oxc_transformer/src/utils/ast_builder.rs index 1dcfd7da1cb79..688ac3ecd36b4 100644 --- a/crates/oxc_transformer/src/utils/ast_builder.rs +++ b/crates/oxc_transformer/src/utils/ast_builder.rs @@ -65,10 +65,8 @@ pub fn wrap_statements_in_arrow_function_iife<'a>( let kind = FormalParameterKind::ArrowFormalParameters; let params = ctx.ast.alloc_formal_parameters(SPAN, kind, ctx.ast.vec(), NONE); let body = ctx.ast.alloc_function_body(SPAN, ctx.ast.vec(), stmts); - let arrow = Expression::ArrowFunctionExpression( - ctx.ast.alloc_arrow_function_expression_with_scope_id_and_pure( - SPAN, false, false, NONE, params, NONE, body, scope_id, false, - ), + let arrow = ctx.ast.expression_arrow_function_with_scope_id_and_pure( + SPAN, false, false, NONE, params, NONE, body, scope_id, false, ); ctx.ast.expression_call(span, arrow, NONE, ctx.ast.vec(), false) }