From 0358c6f6c38f76fc557386f1ae92c9e06637afc4 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Tue, 14 Jan 2025 08:38:54 +0000 Subject: [PATCH] test(transformer/async-to-generator): failing test for async arrow function in class static block (#8387) It's arguable whether we should support this, because async functions is ES2018 and class static blocks is ES2022. So there should not be any browser which needs async-to-generator transform, and not the static block transform too. And when class-static-block transform is enabled, this works fine. But personally, I think we should support it, because: 1. We allow user to enable/disable arbitrary transforms via `TransformOptions`. 2. We support `this` in async arrow functions in class static blocks, so it makes sense to complete that support. 3. I don't think it should be too hard, as the framework for it is already there in the async-to-generator transform. [Babel REPL](https://babeljs.io/repl#?browsers=defaults%2C%20not%20ie%2011%2C%20not%20ie_mob%2011&build=&builtIns=false&corejs=3.21&spec=false&loose=false&code_lz=MYGwhgzhAEDC0FMAeAXBA7AJjAytA3gFDTQQpgoCWwBxJ0KAFpRAHQBm60AvNJAJ7oaACgCUPAHykArgAcEAJw4B7ZQG46AX0LagA&debug=false&forceAllTransforms=false&modules=false&shippedProposals=false&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=&prettier=true&targets=&version=7.26.4&externalPlugins=%40babel%2Fplugin-transform-async-to-generator%407.25.9%2C%40babel%2Fplugin-external-helpers%407.25.9&assumptions=%7B%7D) --- tasks/transform_conformance/snapshots/oxc.snap.md | 8 ++++++-- .../test/fixtures/class/static-block/input.js | 5 +++++ .../test/fixtures/class/static-block/output.js | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/class/static-block/input.js create mode 100644 tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/class/static-block/output.js diff --git a/tasks/transform_conformance/snapshots/oxc.snap.md b/tasks/transform_conformance/snapshots/oxc.snap.md index 44675a8c63426..ff954e232fadd 100644 --- a/tasks/transform_conformance/snapshots/oxc.snap.md +++ b/tasks/transform_conformance/snapshots/oxc.snap.md @@ -1,6 +1,6 @@ commit: 54a8389f -Passed: 126/147 +Passed: 126/148 # All Passed: * babel-plugin-transform-class-static-block @@ -10,7 +10,6 @@ Passed: 126/147 * babel-plugin-transform-optional-catch-binding * babel-plugin-transform-async-generator-functions * babel-plugin-transform-object-rest-spread -* babel-plugin-transform-async-to-generator * babel-plugin-transform-exponentiation-operator * babel-plugin-transform-arrow-functions * babel-preset-typescript @@ -47,6 +46,11 @@ after transform: SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), R rebuilt : SymbolId(0): [ReferenceId(0), ReferenceId(2), ReferenceId(6), ReferenceId(10)] +# babel-plugin-transform-async-to-generator (20/21) +* class/static-block/input.js +x Output mismatch + + # babel-plugin-transform-typescript (2/13) * class-property-definition/input.ts Unresolved references mismatch: diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/class/static-block/input.js b/tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/class/static-block/input.js new file mode 100644 index 0000000000000..2f3402957f874 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/class/static-block/input.js @@ -0,0 +1,5 @@ +class C extends S { + static { + this.fn = async () => super.foo; + } +} diff --git a/tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/class/static-block/output.js b/tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/class/static-block/output.js new file mode 100644 index 0000000000000..4092b9b3b5015 --- /dev/null +++ b/tasks/transform_conformance/tests/babel-plugin-transform-async-to-generator/test/fixtures/class/static-block/output.js @@ -0,0 +1,8 @@ +class C extends S { + static { + var _superprop_getFoo = () => super.foo; + this.fn = babelHelpers.asyncToGenerator(function* () { + return _superprop_getFoo(); + }); + } +}