Prevent ForOfStatement from printing the forbidden sequence "for ( async of" (#13208)
This commit is contained in:
parent
504d22d29b
commit
026e7f5a95
@ -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
|
// Walk up the print stack to determine if our node can come first
|
||||||
// in statement.
|
// in statement.
|
||||||
function isFirstInStatement(
|
function isFirstInStatement(
|
||||||
|
|||||||
7
packages/babel-generator/test/fixtures/edgecase/for-async-of/input.js
vendored
Normal file
7
packages/babel-generator/test/fixtures/edgecase/for-async-of/input.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
for ((async) of []);
|
||||||
|
|
||||||
|
for ((async) of async) async;
|
||||||
|
|
||||||
|
for (\u0061sync of []);
|
||||||
|
|
||||||
|
for (async in []);
|
||||||
7
packages/babel-generator/test/fixtures/edgecase/for-async-of/output.js
vendored
Normal file
7
packages/babel-generator/test/fixtures/edgecase/for-async-of/output.js
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
for ((async) of []);
|
||||||
|
|
||||||
|
for ((async) of async) async;
|
||||||
|
|
||||||
|
for ((async) of []);
|
||||||
|
|
||||||
|
for (async in []);
|
||||||
Loading…
x
Reference in New Issue
Block a user