Parse for await (async of ...) (#13244)

This commit is contained in:
Stuart Cook
2021-05-02 02:00:21 +10:00
committed by GitHub
parent 2a3e35f026
commit fa01fbe052
31 changed files with 554 additions and 11 deletions

View File

@@ -283,8 +283,13 @@ export function LogicalExpression(node: any, parent: any): boolean {
export function Identifier(node: t.Identifier, parent: t.Node): boolean {
// ECMAScript specifically forbids a for-of loop from starting with the
// token sequence "for ( async of", because it would be ambiguous with
// "for (async of => {};;)", so we need to add extra parentheses.
// token sequence `for (async of`, because it would be ambiguous with
// `for (async of => {};;)`, so we need to add extra parentheses.
//
// If the parent is a for-await-of loop (i.e. parent.await === true), the
// parentheses aren't strictly needed, but we add them anyway because
// some tools (including earlier Babel versions) can't parse
// `for await (async of [])` without them.
return (
node.name === "async" && t.isForOfStatement(parent) && node === parent.left
);