const a = async () => await (a||b)
becomes
const a=async()=>await a||b;
should be
const a=async()=>await(a||b);
Why should it be? await has very low precedence; although I like the parens for readability, I don't think they're required for the code to do the right thing.
It behaves different in Chrome (56.0.2924.87, macOS 64-bit), as far as I can tell:
const a = Promise.resolve(false)
const b = Promise.resolve('hi')
(async () => {
console.log('await (a||b)', await (a||b))
console.log('await a||b', await a||b)
})()
outputs:
await (a||b) false
await a||b Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: "hi"}
We found the bug because our electron app stopped behaving correctly after removing the babel async/await regenerator. The workaround we're using is to break it apart:
const temp = a || b
… await temp …
Interesting - we should figure out what the spec says, just in case it's a chrome bug.
I'm not really sure how to read the ecmascript spec—it's pretty opaque to me. I can't even find the word "precedence," and "await" shows up almost everywhere.
One other data point: the babel regenerator seems to have the same behavior as Chrome.
I'll check out Firefox Developer once I'm on a faster connection.
Does this section mean anything to you? https://tc39.github.io/ecmascript-asyncawait/#UnaryExpression
Firefox Developer edition 53.0a2 (2017-03-06) (64-bit) has the same result:
await (a||b) false
await a||b Promise { <state>: "fulfilled", <value>: "hi" }
K, looks like it's confirmed as a bug :-)
Seems like a babel-generator bug, it happens even without any plugins:
➜ /tmp cat .babelrc
cat: .babelrc: No such file or directory
➜ /tmp cat test.js
const a = async () => await (a||b)
➜ /tmp babel test.js
const a = async () => await a || b;
@babel-bot move to babel/babel
Hey @marcello3d! I've moved your issue to the correct repository. Please make sure to keep an eye on the new issue for the latest information.
^ this is so cool 😍
Fixed https://github.com/babel/babel/issues/5428 via https://github.com/babel/babel/issues/5433, will be in next 7.0 release
Most helpful comment
Hey @marcello3d! I've moved your issue to the correct repository. Please make sure to keep an eye on the new issue for the latest information.