rpetrich / babel-plugin-transform-async-to-promises

Transform async/await to somewhat idiomatic JavaScript promise chains
MIT License
246 stars 17 forks source link

break inside a try block does not work correctly #46

Closed redneb closed 4 years ago

redneb commented 5 years ago

Consider the following snippet where we are breaking out of loop from inside a try block:

async function foo() {
    while (true) {
        try {
            await null; // important
            console.log(1);
            break;
        }
        catch {}
        console.log(2);
    }
}

foo();

The second console.log should never run because we exit the while loop prior to that. But using babel-plugin-transform-async-to-promises and running the output of babel, it executes both console.log statements and then exits the loop:

$ ./node_modules/.bin/babel test.js | node
1
2

Contrast that to:

$ node test.js 
1
rpetrich commented 4 years ago

Thanks for the test case. This is now in resolved in 0.8.15