-
-
Notifications
You must be signed in to change notification settings - Fork 485
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(transformer/async-to-generator): failing test for async arrow function in class static block #8387
base: main
Are you sure you want to change the base?
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Just found that Babel's output is incorrect, |
Even if the async arrow function is not in the class static block, it also needs to transform But there is a troublesome example Input: class C { static f = async () => super.prop; } Babel's Output: var _superprop_getProp = () => super.prop;
class C {
static f = babelHelpers.asyncToGenerator(function* () {
return _superprop_getProp();
});
} Babel's implementation is wrong because it inserts |
…nction in class static block
46d2acc
to
5a81005
Compare
Oh bollocks sorry my fault. I posted the Babel REPL link meaning to say "look Babel is wrong again!" but I forgot to actually write that. The test in this PR shows what I think the correct output is for static blocks. For static blocks, I don't expect it's too hard because there's already a block for the |
For properties (instance prop or static prop), it's much more annoying. Babel's solution for instance props looks correct, but for some reason it gets it wrong for static props: Babel REPL But I'm not sure we should attempt to cover async arrow functions in class properties. It's maybe not worth the work. I only suggested that we might want to deal with static blocks because I thought it'd be quite easy. We also have this problem with other transforms. e.g. We have other weird cases where we need to create temp vars as part of a transform inside:
I put class property initializers in the same category. Rather than tackling this in individual transforms, I think we should probably try to figure out a way to handle these problems universally with helpers that create temp vars, and handle these edge cases for us. |
It may also be easier to deal with when we have our own helper library. e.g. something like: class C {
static f = async (x, y) => super.prop;
} -> class C {
static f = oxcHelpers.asyncToGenerator(
function*(x, y, _superprop_getProp) {
return _superprop_getProp();
},
() => super.prop
);
} |
I just came up with a way by var _superprop_getProp;
class C {
static f =
((_superprop_getProp = () => super.prop),
/*#__PURE__*/ (function () {
var _ref = babelHelpers.asyncToGenerator(function* (x, y) {
return _superprop_getProp();
});
return function (_x, _x2) {
return _ref.apply(this, arguments);
};
})());
} It doesn't rely on our own helper, so we can support it soon. |
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:
TransformOptions
.this
in async arrow functions in class static blocks, so it makes sense to complete that support.Babel REPL