Skip to content

Commit

Permalink
feat(transformer): add async_generator_functions plugin (#6573)
Browse files Browse the repository at this point in the history
Passed 15/19 tests. The remaining 4 failed tests related to `this` expression, the problem same as I mentioned in #6658. I will fix them in follow-up PRs.
  • Loading branch information
Dunqing committed Oct 31, 2024
1 parent af5140f commit 934cb5e
Show file tree
Hide file tree
Showing 13 changed files with 870 additions and 11 deletions.
8 changes: 8 additions & 0 deletions crates/oxc_transformer/src/common/helper_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,23 @@ fn default_as_module_name() -> Cow<'static, str> {
/// Available helpers.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum Helper {
AwaitAsyncGenerator,
AsyncGeneratorDelegate,
AsyncIterator,
AsyncToGenerator,
ObjectSpread2,
WrapAsyncGenerator,
}

impl Helper {
const fn name(self) -> &'static str {
match self {
Self::AwaitAsyncGenerator => "awaitAsyncGenerator",
Self::AsyncGeneratorDelegate => "asyncGeneratorDelegate",
Self::AsyncIterator => "asyncIterator",
Self::AsyncToGenerator => "asyncToGenerator",
Self::ObjectSpread2 => "objectSpread2",
Self::WrapAsyncGenerator => "wrapAsyncGenerator",
}
}
}
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 @@ -104,7 +104,6 @@ impl<'a> StatementInjectorStore<'a> {
}

/// Add multiple statements to be inserted immediately before the target statement.
#[expect(dead_code)]
#[inline]
pub fn insert_many_before<A, S>(&self, target: &A, stmts: S)
where
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_transformer/src/es2017/async_to_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,15 @@ impl<'a, 'ctx> AsyncGeneratorExecutor<'a, 'ctx> {
) {
BindingMover::new(target_scope_id, ctx).visit_binding_identifier(ident);
}

#[inline]
pub fn move_bindings_to_target_scope_for_statement(
target_scope_id: ScopeId,
stmt: &Statement<'a>,
ctx: &mut TraverseCtx<'a>,
) {
BindingMover::new(target_scope_id, ctx).visit_statement(stmt);
}
}

/// Moves the bindings from original scope to target scope.
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_transformer/src/es2017/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use oxc_ast::ast::{Expression, Statement};
use oxc_traverse::{Traverse, TraverseCtx};

use crate::{es2017::async_to_generator::AsyncToGenerator, TransformCtx};
#[expect(unused_imports)]
pub use async_to_generator::AsyncGeneratorExecutor;

#[allow(dead_code)]
Expand Down
Loading

0 comments on commit 934cb5e

Please sign in to comment.