Skip to content

Commit

Permalink
feat(transformer): add async_generator_functions plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Oct 15, 2024
1 parent 77ddab8 commit 4a65e1b
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 4 deletions.
20 changes: 20 additions & 0 deletions crates/oxc_transformer/src/es2018/async_generator_functions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Async Generator Function
//!

use oxc_traverse::Traverse;

use crate::context::TransformCtx;

pub struct AsyncGeneratorFunctions<'a, 'ctx> {
ctx: &'ctx TransformCtx<'a>,
}

impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> {
pub fn new(ctx: &'ctx TransformCtx<'a>) -> Self {
Self { ctx }
}
}

impl<'a, 'ctx> Traverse<'a> for AsyncGeneratorFunctions<'a, 'ctx> {}

impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> {}
4 changes: 4 additions & 0 deletions crates/oxc_transformer/src/es2018/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
mod async_generator_functions;
mod object_rest_spread;
mod options;

use async_generator_functions::AsyncGeneratorFunctions;
pub use object_rest_spread::{ObjectRestSpread, ObjectRestSpreadOptions};
pub use options::ES2018Options;
use oxc_ast::ast::*;
Expand All @@ -13,6 +15,7 @@ pub struct ES2018<'a, 'ctx> {

// Plugins
object_rest_spread: ObjectRestSpread<'a, 'ctx>,
async_generator_functions: AsyncGeneratorFunctions<'a, 'ctx>,
}

impl<'a, 'ctx> ES2018<'a, 'ctx> {
Expand All @@ -22,6 +25,7 @@ impl<'a, 'ctx> ES2018<'a, 'ctx> {
options.object_rest_spread.unwrap_or_default(),
ctx,
),
async_generator_functions: AsyncGeneratorFunctions::new(ctx),
options,
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_transformer/src/es2018/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use crate::env::{can_enable_plugin, Versions};
pub struct ES2018Options {
#[serde(skip)]
pub object_rest_spread: Option<ObjectRestSpreadOptions>,
#[serde(skip)]
pub async_generator_functions: bool,
}

impl ES2018Options {
Expand All @@ -28,6 +30,11 @@ impl ES2018Options {
bugfixes,
)
.then(Default::default),
async_generator_functions: can_enable_plugin(
"transform-async-generator-functions",
targets,
bugfixes,
),
}
}
}
14 changes: 13 additions & 1 deletion crates/oxc_transformer/src/options/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ impl TransformOptions {
arrow_function: None,
},
es2016: ES2016Options { exponentiation_operator: true },
es2018: ES2018Options { object_rest_spread: Some(ObjectRestSpreadOptions::default()) },
es2018: ES2018Options {
object_rest_spread: Some(ObjectRestSpreadOptions::default()),
// Turned off because it is not ready.
async_generator_functions: false,
},
es2017: ES2017Options {
// Turned off because it is not ready.
async_to_generator: false,
Expand Down Expand Up @@ -238,6 +242,14 @@ impl TransformOptions {
)
});

let has_enabled_async_generator_functions = {
let plugin_name = "transform-async-generator-functions";
get_enabled_plugin_options(plugin_name, options, targets.as_ref(), bugfixes).is_some()
};
if has_enabled_async_generator_functions {
transformer_options.es2018.async_generator_functions = true;
}

transformer_options.es2019.with_optional_catch_binding({
let plugin_name = "transform-optional-catch-binding";
get_enabled_plugin_options(plugin_name, options, targets.as_ref(), bugfixes).is_some()
Expand Down
61 changes: 60 additions & 1 deletion tasks/transform_conformance/snapshots/babel.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 3bcfee23

Passed: 339/1039
Passed: 339/1058

# All Passed:
* babel-plugin-transform-logical-assignment-operators
Expand Down Expand Up @@ -1464,6 +1464,65 @@ x Output mismatch
x Output mismatch


# babel-plugin-transform-async-generator-functions (0/19)
* async-generators/class-method/input.js
x Output mismatch

* async-generators/declaration/input.js
x Output mismatch

* async-generators/expression/input.js
x Output mismatch

* async-generators/object-method/input.js
x Output mismatch

* async-generators/static-method/input.js
x Output mismatch

* async-generators/transform-class-keys/input.js
x Output mismatch

* async-generators/yield-star/input.js
x Output mismatch

* for-await/async-arrow/input.js
x Output mismatch

* for-await/async-function/input.js
x Output mismatch

* for-await/async-function-no-transform/input.js
x Output mismatch

* for-await/async-generator/input.js
x Output mismatch

* for-await/create-async-from-sync-iterator/input.js
x Output mismatch

* for-await/destructuring/input.js
x Output mismatch

* for-await/lhs-member-expression/input.js
x Output mismatch

* for-await/re-declare-var-in-init-body/input.js
x Output mismatch

* nested/arrows-in-declaration/input.js
x Output mismatch

* nested/async-in-params/input.js
x Output mismatch

* nested/generator-in-async/input.js
x Output mismatch

* yield-star/create-async-from-sync-iterator/input.js
x Output mismatch


# babel-plugin-transform-object-rest-spread (5/59)
* assumption-ignoreFunctionLength/parameters-object-rest-used-in-default/input.js
x Output mismatch
Expand Down
70 changes: 69 additions & 1 deletion tasks/transform_conformance/snapshots/babel_exec.snap.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
commit: 3bcfee23

Passed: 34/60
Passed: 38/86

# All Passed:
* babel-plugin-transform-logical-assignment-operators
Expand All @@ -24,6 +24,74 @@ exec failed
exec failed


# babel-plugin-transform-async-generator-functions (4/26)
* async-generators/declaration-exec/exec.js
exec failed

* async-generators/yield-exec/exec.js
exec failed

* for-await/lhs-member-expression/exec.js
exec failed

* for-await/re-declare-var-in-init-body/exec.js
exec failed

* for-await/step-single-tick/exec.js
exec failed

* for-await/step-value-is-promise/exec.js
exec failed

* for-await/step-value-not-accessed-when-done/exec.js
exec failed

* yield-star/ecma262-pr-2819/exec.js
exec failed

* yield-star/issue-9905/exec.js
exec failed

* yield-star/return-method/exec.js
exec failed

* yield-star/return-method-with-finally/exec.js
exec failed

* yield-star/return-method-with-finally-multiple-parallel/exec.js
exec failed

* yield-star/return-method-with-finally-multiple-serial/exec.js
exec failed

* yield-star/throw-method-with-catch/exec.js
exec failed

* yield-star/throw-method-with-finally/exec.js
exec failed

* yield-star-polyfill-corejs3/issue-9905/exec.js
exec failed

* yield-star-polyfill-corejs3/return-method/exec.js
exec failed

* yield-star-polyfill-corejs3/return-method-with-finally/exec.js
exec failed

* yield-star-polyfill-corejs3/return-method-with-finally-multiple-parallel/exec.js
exec failed

* yield-star-polyfill-corejs3/return-method-with-finally-multiple-serial/exec.js
exec failed

* yield-star-polyfill-corejs3/throw-method-with-catch/exec.js
exec failed

* yield-star-polyfill-corejs3/throw-method-with-finally/exec.js
exec failed


# babel-plugin-transform-object-rest-spread (15/31)
* assumption-objectRestNoSymbols/rest-ignore-symbols/exec.js
exec failed
Expand Down
2 changes: 1 addition & 1 deletion tasks/transform_conformance/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub(crate) const PLUGINS: &[&str] = &[
"babel-plugin-transform-optional-catch-binding",
// "babel-plugin-transform-json-strings",
// // ES2018
// "babel-plugin-transform-async-generator-functions",
"babel-plugin-transform-async-generator-functions",
"babel-plugin-transform-object-rest-spread",
// // [Regex] "babel-plugin-transform-unicode-property-regex",
// "babel-plugin-transform-dotall-regex",
Expand Down

0 comments on commit 4a65e1b

Please sign in to comment.