Skip to content

Commit

Permalink
Disallow <T>(a => b) when parsing Flow (#13645)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Aug 10, 2021
1 parent b15ec33 commit 9d0aa1e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/babel-parser/src/plugins/flow/index.js
Expand Up @@ -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);

Expand Down
@@ -0,0 +1 @@
<T>(a => b);
@@ -0,0 +1,5 @@
{
"sourceType": "module",
"plugins": ["flow"],
"throws": "Expected an arrow function after this type parameter declaration. (1:0)"
}
@@ -0,0 +1 @@
<T>(a => b);
@@ -0,0 +1,3 @@
{
"throws": "Unterminated JSX contents. (1:3)"
}

0 comments on commit 9d0aa1e

Please sign in to comment.