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
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);