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
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/45581/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 6faed7b:
|
After writing this I remembered that there's a whole subsystem dedicated to “does this node need parentheses in light of its parent”. Not sure if it makes more sense to to use that instead, or to stick with this ad-hoc code. |
The alternative would be something like this in export function Identifier(node: t.Identifier, parent: t.Node): boolean {
return (
node.name === "async" && t.isForOfStatement(parent) && node === parent.left
);
}
|
👍 from me |
@existentialism Oops I mentally think of your 👍 as ✅. |
All good, looks great thanks @Zalathar! |
Looks like this PR doesn't take into account that in |
Ah, nice catch. Thankfully the output still happens to be correct, so it's not a disaster, but this was an oversight and at least deserves explicit tests and comments. That said, some quick testing reveals that Babel itself doesn't know how to parse (TODO: File and fix the parser bug!) So once the parser bug is fixed, I'm inclined to leave the unnecessary parens as-is, or maybe remove them in compact mode only. |
If we detect that a
ForOfStatement
's left-hand-side is an identifier namedasync
, print extra parentheses around the identifier to avoid this edge-case in the ECMAScript grammar.