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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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(

View File

@ -0,0 +1,7 @@
for ((async) of []);
for ((async) of async) async;
for (\u0061sync of []);
for (async in []);

View File

@ -0,0 +1,7 @@
for ((async) of []);
for ((async) of async) async;
for ((async) of []);
for (async in []);