Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(transformer): complete the async-to-generator plugin #6658

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
39 changes: 39 additions & 0 deletions crates/oxc_ast/src/ast_builder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,45 @@ impl<'a> AstBuilder<'a> {
mem::replace(decl, empty_decl)
}

/// Move a formal parameters out by replacing it with an empty [`FormalParameters`].
#[inline]
pub fn move_formal_parameters(self, params: &mut FormalParameters<'a>) -> FormalParameters<'a> {
let empty_params = self.formal_parameters(Span::default(), params.kind, self.vec(), NONE);
mem::replace(params, empty_params)
}

/// Move a function body out by replacing it with an empty [`FunctionBody`].
#[inline]
pub fn move_function_body(self, body: &mut FunctionBody<'a>) -> FunctionBody<'a> {
let empty_body = self.function_body(Span::default(), self.vec(), self.vec());
mem::replace(body, empty_body)
}

/// Move a function out by replacing it with an empty [`Function`]
#[inline]
pub fn move_function(self, function: &mut Function<'a>) -> Function<'a> {
let params = self.formal_parameters(
Span::default(),
FormalParameterKind::FormalParameter,
self.vec(),
NONE,
);
let empty_function = self.function(
FunctionType::FunctionDeclaration,
Span::default(),
None,
false,
false,
false,
NONE,
NONE,
params,
NONE,
NONE,
);
mem::replace(function, empty_function)
}

/// Move an array element out by replacing it with an
/// [elision](ArrayExpressionElement::Elision).
pub fn move_array_expression_element(
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_transformer/src/common/statement_injector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ impl<'a> StatementInjectorStore<'a> {
}

/// Add a statement to be inserted immediately after the target statement.
#[expect(dead_code)]
pub fn insert_after(&self, target: &Statement<'a>, stmt: Statement<'a>) {
let mut insertions = self.insertions.borrow_mut();
let adjacent_stmts = insertions.entry(target.address()).or_default();
Expand Down
Loading
Loading