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:
Vedant Roy
2020-03-21 14:38:36 -04:00
committed by GitHub
parent a9b430b464
commit 0e5c1da659
8 changed files with 20 additions and 4 deletions

View File

@@ -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(