Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions packages/babel-generator/src/node/parentheses.ts
Expand Up @@ -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(
Expand Down
@@ -0,0 +1,7 @@
for ((async) of []);

for ((async) of async) async;

for (\u0061sync of []);

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

for ((async) of async) async;

for ((async) of []);

for (async in []);