NodeJS 5.x + Babel 6 async/await debugging
Asked Answered
P

1

10

I'm having spotty debugging experiences when I try to debug code with async/await using transform-async-to-generator babel plugin ( although I've tried almost every other combination ).

Essentially code with a await will skip to the end of the method and then go into the compiled code. 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 )
    }
}

If you take a look at the generated code for that function:

meow() {
    var _this = this;

    return _asyncToGenerator(function* () {
        let p = yield _this.bat();
        _this.fart();
        return p;
    })();
}

its no wonder regarding the results but source maps should handle this, right?

I've tried this with a variety of setups ( require hook / babel-node / babel cli / gulp babel ) and get same issue. I'm using: Node 5.3.0 and Babel 6.3

I've created a demo project on github. I've also posted the question on the babel thread.

EDIT: The question was posed to source-maps project as I do not feel this is a babel issue. The team acknowledged the issue as a debugger issue. For more details see: github issue

Peruzzi answered 5/1, 2016 at 15:55 Comment(1)
By "skip" you mean that you cannot place a breakpoint on that line or skip through it with your debugger, but fart() does get called, right?Epicalyx
P
0

With the introduction of async/await natively in Node 4+, this is no longer an issue.

Peruzzi answered 5/1, 2017 at 13:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.