From 53bdbb454d73b937d21b2b9ff4cad00aea840ff5 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Tue, 5 Nov 2024 12:17:19 +0800 Subject: [PATCH] refactor(transformer/async-generator-functions): do not transform yield expression where inside generator function --- .../src/es2018/async_generator_functions/mod.rs | 2 +- tasks/transform_conformance/snapshots/oxc.snap.md | 3 ++- .../test/fixtures/generator-function/yield-regexp/input.js | 1 + .../test/fixtures/generator-function/yield-regexp/output.js | 3 +++ .../test/fixtures/options.json | 5 +++++ 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/generator-function/yield-regexp/input.js create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/generator-function/yield-regexp/output.js create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/options.json diff --git a/crates/oxc_transformer/src/es2018/async_generator_functions/mod.rs b/crates/oxc_transformer/src/es2018/async_generator_functions/mod.rs index d1740f2d6dec47..81f5a32c7e0e32 100644 --- a/crates/oxc_transformer/src/es2018/async_generator_functions/mod.rs +++ b/crates/oxc_transformer/src/es2018/async_generator_functions/mod.rs @@ -200,7 +200,7 @@ impl<'a, 'ctx> AsyncGeneratorFunctions<'a, 'ctx> { expr: &mut YieldExpression<'a>, ctx: &mut TraverseCtx<'a>, ) -> Option> { - if !expr.delegate { + if !expr.delegate || !Self::is_inside_async_generator_function(ctx) { return None; } diff --git a/tasks/transform_conformance/snapshots/oxc.snap.md b/tasks/transform_conformance/snapshots/oxc.snap.md index 86d5813639ceb6..88c539f886454b 100644 --- a/tasks/transform_conformance/snapshots/oxc.snap.md +++ b/tasks/transform_conformance/snapshots/oxc.snap.md @@ -1,11 +1,12 @@ commit: d20b314c -Passed: 75/84 +Passed: 76/85 # All Passed: * babel-plugin-transform-class-static-block * babel-plugin-transform-nullish-coalescing-operator * babel-plugin-transform-optional-catch-binding +* babel-plugin-transform-async-generator-functions * babel-plugin-transform-async-to-generator * babel-plugin-transform-exponentiation-operator * babel-plugin-transform-arrow-functions diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/generator-function/yield-regexp/input.js b/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/generator-function/yield-regexp/input.js new file mode 100644 index 00000000000000..fad58539e47203 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/generator-function/yield-regexp/input.js @@ -0,0 +1 @@ +function* x() { yield* /z/ } diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/generator-function/yield-regexp/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/generator-function/yield-regexp/output.js new file mode 100644 index 00000000000000..58e28993cffe61 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/generator-function/yield-regexp/output.js @@ -0,0 +1,3 @@ +function* x() { + yield* /z/; +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/options.json b/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/options.json new file mode 100644 index 00000000000000..90fdb8d49d2ba4 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-async-generator-functions/test/fixtures/options.json @@ -0,0 +1,5 @@ +{ + "plugins": [ + "transform-async-generator-functions" + ] +}