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 @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -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,
)
}
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_transformer/src/decorator/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
};
Expand Down Expand Up @@ -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,
Expand All @@ -429,7 +425,7 @@ impl<'a> AsyncGeneratorFunctions<'a, '_> {
),
)),
if_block_scope_id,
)),
),
None,
)
};
Expand All @@ -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,
)
};
Expand Down
4 changes: 1 addition & 3 deletions crates/oxc_transformer/src/es2018/object_rest_spread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
22 changes: 10 additions & 12 deletions crates/oxc_transformer/src/es2020/nullish_coalescing_operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
37 changes: 18 additions & 19 deletions crates/oxc_transformer/src/es2022/class_properties/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,26 +324,24 @@ impl<'a> ClassProperties<'a, '_> {
let body = ctx.ast.vec1(ctx.ast.statement_expression(SPAN, body_exprs));

// `(..._args) => (super(..._args), <inits>, 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) => ( ... );`
Expand Down Expand Up @@ -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() { <inits>; 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,
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_transformer/src/jsx/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -606,6 +606,7 @@ impl<'a> ReactRefresh<'a, '_> {
NONE,
Some(function_body),
scope_id,
false,
));
arguments.push(function);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 }});`
Expand Down
7 changes: 2 additions & 5 deletions crates/oxc_transformer/src/typescript/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_transformer/src/typescript/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'a> TypeScriptEnum<'a> {
let statements =
self.transform_ts_enum_members(decl.scope_id(), &mut decl.members, &param_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,
Expand All @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions crates/oxc_transformer/src/utils/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading