babel: super is not working inside methods marked async (T6895)

Issue originally made by Dmitriy Krasnikov (dmitriy.krasnikov)

Bug information

  • Babel version: 6.3.26
  • Node version: 5.3
  • npm version: 3.3.12

Options

{
  plugins:[
    "transform-async-to-generator",
  ]
}

Input code

export class BaseClass {
  async test(id){
    console.log(id);
  }
}
export class ChildClass extends BaseClass{
  async test(id){
    id=1;
    super.test(id);
  }
}

let cls = new ChildClass();
cls.test(5);

Description

Outputs:

export class BaseClass {
  test(id) {
    return _asyncToGenerator(function* () {
      console.log(id);
    })();
  }
}
export class ChildClass extends BaseClass {
  test(id) {
    return _asyncToGenerator(function* () {
      id = 1;
      super.test(id);
    })();
  }
}

let cls = new ChildClass();
cls.test(5);

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 15
  • Comments: 17 (4 by maintainers)

Commits related to this issue

Most upvoted comments

Any updates on this?

Workaround: SuperClass.prototype.method.call(this): http://madole.xyz/babel-plugin-transform-async-to-module-method-gotcha/

Just wrote a simple plugin for Babel 6 to work around this issue here: https://github.com/devongovett/babel-plugin-transform-async-super. It only compiles super expressions inside async functions, so you could use it when you aren’t already compiling classes to ES5 (e.g. Node 6).

If you want to make it part of preset-env as a temporary fix for users on Babel 6, I’d be happy to contribute it. It’s not ideal that preset-env fails to generate working code when targeting Node 6 at the moment, so I think it would be great to either back port the fix from Babel 7, or add something like the above plugin to preset-env when compiling async functions but not classes.

For those coming across this, my recommendation for now would be to manually enable transform-es2015-classes which obviously isn’t ideal, but does the job.