Disallow <T>(a => b) when parsing Flow (#13645)

This commit is contained in:
Nicolò Ribaudo 2021-08-10 19:09:23 +02:00 committed by GitHub
parent b15ec33146
commit 9d0aa1ec9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 6 deletions

View File

@ -2842,17 +2842,17 @@ export default (superClass: Class<Parser>): Class<Parser> =>
},
);
// <T>(() => {});
// <T>(() => {}: any);
if (
arrowExpression.type !== "ArrowFunctionExpression" &&
arrowExpression.extra?.parenthesized
) {
abort();
}
if (arrowExpression.extra?.parenthesized) abort();
// The above can return a TypeCastExpression when the arrow
// expression is not wrapped in parens. See also `this.parseParenItem`.
// (<T>() => {}: any);
const expr = this.maybeUnwrapTypeCastExpression(arrowExpression);
if (expr.type !== "ArrowFunctionExpression") abort();
expr.typeParameters = typeParameters;
this.resetStartLocationFromNode(expr, typeParameters);

View File

@ -0,0 +1 @@
<T>(a => b);

View File

@ -0,0 +1,5 @@
{
"sourceType": "module",
"plugins": ["flow"],
"throws": "Expected an arrow function after this type parameter declaration. (1:0)"
}

View File

@ -0,0 +1 @@
<T>(a => b);

View File

@ -0,0 +1,3 @@
{
"throws": "Unterminated JSX contents. (1:3)"
}