Fix generator missing parens around an arrow returning function type (#10519)

This commit is contained in:
Brian Ng 2019-10-11 20:22:42 -05:00 committed by Huáng Jùnliàng
parent 99035ca96e
commit e28c8ac612
3 changed files with 14 additions and 3 deletions

View File

@ -35,14 +35,22 @@ export function NullableTypeAnnotation(node: Object, parent: Object): boolean {
return t.isArrayTypeAnnotation(parent);
}
export function FunctionTypeAnnotation(node: Object, parent: Object): boolean {
export function FunctionTypeAnnotation(
node: Object,
parent: Object,
printStack: Array<Object>,
): boolean {
return (
// (() => A) | (() => B)
t.isUnionTypeAnnotation(parent) ||
// (() => A) & (() => B)
t.isIntersectionTypeAnnotation(parent) ||
// (() => A)[]
t.isArrayTypeAnnotation(parent)
t.isArrayTypeAnnotation(parent) ||
// <T>(A: T): (T => T[]) => B => [A, B]
(t.isTypeAnnotation(parent) &&
// Check grandparent
t.isArrowFunctionExpression(printStack[printStack.length - 3]))
);
}

View File

@ -5,3 +5,4 @@ const bar4 = x => {};
const bar5 = (x): string => {};
const bar6 = (x: number) => {};
const bar7 = <T>(x) => {};
const bar8 = <T>(x: T): (T => T[]) => y => [x, y];

View File

@ -11,3 +11,5 @@ const bar5 = (x): string => {};
const bar6 = (x: number) => {};
const bar7 = <T>(x) => {};
const bar8 = <T>(x: T): ((T) => T[]) => y => [x, y];