Prevent ForOfStatement from printing the forbidden sequence "for ( async of" (#13208)

This commit is contained in:
Stuart Cook
2021-04-27 01:34:10 +10:00
committed by GitHub
parent 504d22d29b
commit 026e7f5a95
3 changed files with 23 additions and 0 deletions

View File

@@ -276,6 +276,15 @@ 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.
return (
node.name === "async" && t.isForOfStatement(parent) && node === parent.left
);
}
// Walk up the print stack to determine if our node can come first
// in statement.
function isFirstInStatement(