fix: async arrow functions should not be allowed after binary… (#11284)
* Forbid async arrow functions after binary operator. This commit makes Babel throw an error when parsing code like "3 + async() => 2". * Make atPossibleAsync more accurate * Change atPossibleAsync to atPossibleAsyncArrow Add an extra test to atPossibleAsync and refactor it to atPossibleAsyncArrow. This also fixes a bug in the Typescript plugin, so a new test has been added. * Add test for async arrow after unary operator
This commit is contained in:
@@ -1738,7 +1738,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
|
||||
// There are number of things we are going to "maybe" parse, like type arguments on
|
||||
// tagged template expressions. If any of them fail, walk it back and continue.
|
||||
const result = this.tsTryParseAndCatch(() => {
|
||||
if (!noCalls && this.atPossibleAsync(base)) {
|
||||
if (!noCalls && this.atPossibleAsyncArrow(base)) {
|
||||
// Almost certainly this is a generic async function `async <T>() => ...
|
||||
// But it might be a call with a type argument `async<T>();`
|
||||
const asyncArrowFn = this.tsTryParseGenericAsyncArrowFunction(
|
||||
|
||||
Reference in New Issue
Block a user