【问题标题】:NodeJS 5.x + Babel 6 async/await debuggingNodeJS 5.x + Babel 6 异步/等待调试
【发布时间】:2016-04-09 12:36:15
【问题描述】:

当我尝试使用 transform-async-to-generator babel 插件(尽管我尝试过几乎所有其他组合)使用 async/await 调试代码时,我的调试体验参差不齐。

基本上,带有 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;
    })();
}

结果并不奇怪,但源地图应该处理这个,对吧?

我已经尝试了各种设置(需要钩子/babel-node/babel cli/gulp babel)并遇到同样的问题。我正在使用:Node 5.3.0 和 Babel 6.3

我在github 上创建了一个演示项目。我也在babel thread上发布了这个问题。

编辑: 这个问题是针对 source-maps 项目提出的,因为我不认为这是一个 babel 问题。团队承认该问题是调试器问题。更多详情见:github issue

【问题讨论】:

  • “跳过”是指不能在该行放置断点或使用调试器跳过该行,但确实会调用 fart(),对吗?

标签: node.js babeljs source-maps ecmascript-2016


【解决方案1】:

随着在 Node 4+ 中原生引入 async/await,这不再是问题。

【讨论】:

    猜你喜欢
    • 2021-01-31
    • 1970-01-01
    • 1970-01-01
    • 2016-08-15
    • 2019-12-18
    • 2019-07-20
    • 1970-01-01
    • 1970-01-01
    • 2018-02-08
    相关资源
    最近更新 更多