NodeJS 5.x + Babel 6asynchronous/等待debugging
当我尝试使用transform-async-to-generator
babel插件(尽pipe我已经尝试几乎所有其他组合)尝试使用async / awaitdebugging代码时,我遇到了一些棘手的debugging体验。
基本上,一个await的代码会跳到方法的末尾,然后进入编译的代码。 video
export class Cat { async meow(){ let p = await this.bat(); // <<<< this line runs this.fart(); // <<<< then skips this line return p; // <<<< and goes to this line ( always last line in fn ) } }
如果您查看该函数的生成代码:
meow() { var _this = this; return _asyncToGenerator(function* () { let p = yield _this.bat(); _this.fart(); return p; })(); }
对于结果来说也难怪,但是源地图应该可以处理这个问题吧?
我已经尝试了各种各样的设置(要求钩/巴贝尔节点/巴别克/ gulp巴贝尔),并得到同样的问题。 我正在使用:Node 5.3.0和Babel 6.3
我在github上创build了一个演示项目。 我也在babel线程上发布了这个问题。
编辑:问题是摆在源地图项目,因为我不觉得这是一个巴贝尔问题。 团队承认这个问题是一个debugging问题。 有关更多详细信息,请参阅: github问题
通过在Node 4+中本地引入async/await
,这不再是一个问题。