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
- Add a temporary workaround for a Babel's bug that forbids the usage of super() calls in async methods See https://github.com/babel/babel/issues/3930 — committed to metapensiero/metapensiero.pj by azazel75 7 years ago
- upgrade - 新增BaseClass类,所有Controller和Service都必须直接或间接继承此类 - 实例化Controller或Service时,第一个参数永远为app实例 - App新增mountControllers和mountServices方法,以便一次性挂载多个Controller或Service - App提供interceptor方法,以便在router之前执行某些m... — committed to eeve/microweb by eeve 7 years ago
- bug: babel6 doesn't support `super.[method]` inside of async function - https://github.com/babel/babel/issues/3930 — committed to tokamak-network/tokyo-solidity-template by 4000D 6 years ago
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.