You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c10223e
Browse filesBrowse the repository at this point in the historyBrowse files
Reject await in a function that an async function returns directly (#9169)
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.
Diagnostic added (await in a returned function):
Example:
let f = async x => y => await y + x
Before (js): a SyntaxError when the module loads
async function f(x) {
return y => await y + x | 0;
}
After (diagnostic):
A.res:1:25-31
Await on expression not in an async context
Review: Does a working program stop compiling? Only one whose `await` in
such a function was removed by the optimizer, as in an unused
definition or a branch under a constant `false`; 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.
Signed-off-by: mununki <woonki.moon@gmail.com>
- Reject `await` in a function that an async function returns directly, as in `async x => y => await y`, which produced JavaScript with `await` outside an async function.
0 commit comments