diff --git a/packages/babel-generator/src/generators/flow.ts b/packages/babel-generator/src/generators/flow.ts index 5c399dc4afee..5b3e1e8e01ee 100644 --- a/packages/babel-generator/src/generators/flow.ts +++ b/packages/babel-generator/src/generators/flow.ts @@ -290,7 +290,7 @@ export function ExistsTypeAnnotation(this: Printer) { export function FunctionTypeAnnotation( this: Printer, node: t.FunctionTypeAnnotation, - parent: any, + parent: t.Node | void, ) { this.print(node.typeParameters, node); this.token("("); @@ -321,9 +321,10 @@ export function FunctionTypeAnnotation( // this node type is overloaded, not sure why but it makes it EXTREMELY annoying if ( - parent.type === "ObjectTypeCallProperty" || - parent.type === "DeclareFunction" || - (parent.type === "ObjectTypeProperty" && parent.method) + parent && + (parent.type === "ObjectTypeCallProperty" || + parent.type === "DeclareFunction" || + (parent.type === "ObjectTypeProperty" && parent.method)) ) { this.token(":"); } else { diff --git a/packages/babel-generator/test/index.js b/packages/babel-generator/test/index.js index be3fc424b154..c1bcdfeaae0d 100644 --- a/packages/babel-generator/test/index.js +++ b/packages/babel-generator/test/index.js @@ -497,6 +497,17 @@ describe("programmatic generation", function () { expect(output).toBe("interface A {}"); }); + it("flow function type annotation with no parent", () => { + const functionTypeAnnotation = t.functionTypeAnnotation( + null, + [], + null, + t.voidTypeAnnotation(), + ); + const output = generate(functionTypeAnnotation).code; + expect(output).toBe("() => void"); + }); + describe("directives", function () { it("preserves escapes", function () { const directive = t.directive(