File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -290,7 +290,7 @@ export function ExistsTypeAnnotation(this: Printer) {
290290export function FunctionTypeAnnotation (
291291 this : Printer ,
292292 node : t . FunctionTypeAnnotation ,
293- parent : any ,
293+ parent : t . Node | void ,
294294) {
295295 this . print ( node . typeParameters , node ) ;
296296 this . token ( "(" ) ;
@@ -321,9 +321,10 @@ export function FunctionTypeAnnotation(
321321
322322 // this node type is overloaded, not sure why but it makes it EXTREMELY annoying
323323 if (
324- parent . type === "ObjectTypeCallProperty" ||
325- parent . type === "DeclareFunction" ||
326- ( parent . type === "ObjectTypeProperty" && parent . method )
324+ parent &&
325+ ( parent . type === "ObjectTypeCallProperty" ||
326+ parent . type === "DeclareFunction" ||
327+ ( parent . type === "ObjectTypeProperty" && parent . method ) )
327328 ) {
328329 this . token ( ":" ) ;
329330 } else {
Original file line number Diff line number Diff line change @@ -497,6 +497,17 @@ describe("programmatic generation", function () {
497497 expect ( output ) . toBe ( "interface A {}" ) ;
498498 } ) ;
499499
500+ it ( "flow function type annotation with no parent" , ( ) => {
501+ const functionTypeAnnotation = t . functionTypeAnnotation (
502+ null ,
503+ [ ] ,
504+ null ,
505+ t . voidTypeAnnotation ( ) ,
506+ ) ;
507+ const output = generate ( functionTypeAnnotation ) . code ;
508+ expect ( output ) . toBe ( "() => void" ) ;
509+ } ) ;
510+
500511 describe ( "directives" , function ( ) {
501512 it ( "preserves escapes" , function ( ) {
502513 const directive = t . directive (
You can’t perform that action at this time.
0 commit comments