Disallow <T>(a => b) when parsing Flow (#13645)
This commit is contained in:
parent
b15ec33146
commit
9d0aa1ec9d
@ -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);
|
||||
|
||||
|
||||
1
packages/babel-parser/test/fixtures/flow/type-generics/wrong-arrow-parens-no-jsx/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/flow/type-generics/wrong-arrow-parens-no-jsx/input.js
vendored
Normal file
@ -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)"
|
||||
}
|
||||
1
packages/babel-parser/test/fixtures/flow/type-generics/wrong-arrow-parens/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/flow/type-generics/wrong-arrow-parens/input.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
<T>(a => b);
|
||||
3
packages/babel-parser/test/fixtures/flow/type-generics/wrong-arrow-parens/options.json
vendored
Normal file
3
packages/babel-parser/test/fixtures/flow/type-generics/wrong-arrow-parens/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Unterminated JSX contents. (1:3)"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user