preset-modules icon indicating copy to clipboard operation
preset-modules copied to clipboard

Bug: super method call within async arrow within class method fails

Open developit opened this issue 4 years ago • 1 comments

The async-arrows-in-class transform uses Babel's arrowFunctionToExpression() helper, which doesn't patch calls to super methods:

Input:Output:
class A extends B {
  a() {
    (async () => {
      super.b();
    })();
  }
}
class A extends B {
  a() {
    (async function () {
      super.b();  // this is invalid
    })();
  }
}

Here's the bug reproduced in the Babel repl.

developit avatar May 27 '21 01:05 developit

I'd consider this a bug in arrowFunctionToExpression itself rather than in this plugin.

EDIT: Ok no, the fix relies on injecting new sync arrow functions so if cannot be done in arrowFunctionToExpression. I think we have something like hoistFunctionEnvironment somewhere that will help.

nicolo-ribaudo avatar May 27 '21 06:05 nicolo-ribaudo