Reject await in a function that an async function returns directly
Why
The built-in PPX let a function in the body of an async function inherit its async context, so await in a plain arrow returned by an async function passed the check, and the JavaScript had await in a function that is not async (#9168). The inheritance comes from the curried parsetree, where async (x, y) => ... was nested functions; in the n-ary parsetree a function in a function's body is a function of its own, so each function is now in an async context exactly when it is async.
addedDiagnostic await in a returned function
let f = async x => y => await y + xjs
async function f(x) { return y => await y + x | 0;}
diagnostic
A.res:1:25-31Await on expression not in an async context
Review
- Does a working program stop compiling? Only one whose
awaitin such a function was removed by the optimizer, as in an unused definition or a branch under a constantfalse; the same code in any other plain function is already rejected. Programs that still compile give the same JavaScript, since only the await check reads the async context.