From cd1006fec13355b86e58eac1612fd2fd9c4e9bc6 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Wed, 6 Nov 2024 03:27:13 +0000 Subject: [PATCH] refactor(transformer/async-generator-functions): do not transform yield expression where inside generator function (#7134) --- .../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 2750083d74093..7654597e2cc31 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 86d5813639ceb..88c539f886454 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 0000000000000..fad58539e4720 --- /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 0000000000000..58e28993cffe6 --- /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 0000000000000..90fdb8d49d2ba --- /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" + ] +}