@@ -45,37 +45,47 @@ function inferReturn(comment) {
45
45
46
46
if ( ( t . isFunction ( fn ) || t . isTSDeclareFunction ( fn ) || t . isTSDeclareMethod ( fn ) ) && fn . returnType ) {
47
47
let returnType = typeAnnotation ( fn . returnType ) ;
48
- if ( comment . returns && comment . returns . length > 0 ) {
49
- comment . returns [ 0 ] . type = returnType ;
50
- } else {
51
- if ( fn . generator && returnType . type === 'TypeApplication' ) {
52
- comment . generator = true ;
53
- let numArgs ;
48
+ let yieldsType = null ;
49
+
50
+ if ( fn . generator && returnType . type === 'TypeApplication' ) {
51
+ comment . generator = true ;
52
+ let numArgs ;
53
+
54
+ if ( t . isFlow ( fn . returnType ) ) {
55
+ numArgs = FLOW_GENERATORS [ returnType . expression . name ] ;
56
+ } else if ( t . isTSTypeAnnotation ( fn . returnType ) ) {
57
+ numArgs = TS_GENERATORS [ returnType . expression . name ] ;
58
+ }
59
+
60
+ if ( returnType . applications . length === numArgs ) {
61
+ yieldsType = returnType . applications [ 0 ] ;
54
62
55
- if ( t . isFlow ( fn . returnType ) ) {
56
- numArgs = FLOW_GENERATORS [ returnType . expression . name ] ;
57
- } else if ( t . isTSTypeAnnotation ( fn . returnType ) ) {
58
- numArgs = TS_GENERATORS [ returnType . expression . name ] ;
63
+ if ( numArgs > 1 ) {
64
+ returnType = returnType . applications [ 1 ] ;
65
+ } else {
66
+ returnType = {
67
+ type : 'VoidLiteral'
68
+ } ;
59
69
}
70
+ }
71
+ }
60
72
61
- if ( returnType . applications . length === numArgs ) {
62
- comment . yields = [
63
- {
64
- title : 'yields' ,
65
- type : returnType . applications [ 0 ]
66
- }
67
- ] ;
68
-
69
- if ( numArgs > 1 ) {
70
- returnType = returnType . applications [ 1 ] ;
71
- } else {
72
- returnType = {
73
- type : 'VoidLiteral'
74
- } ;
73
+ if ( yieldsType ) {
74
+ if ( comment . yields && comment . yields . length > 0 ) {
75
+ comment . yields [ 0 ] . type = yieldsType ;
76
+ } else {
77
+ comment . yields = [
78
+ {
79
+ title : 'yields' ,
80
+ type : yieldsType
75
81
}
76
- }
82
+ ] ;
77
83
}
84
+ }
78
85
86
+ if ( comment . returns && comment . returns . length > 0 ) {
87
+ comment . returns [ 0 ] . type = returnType ;
88
+ } else {
79
89
comment . returns = [
80
90
{
81
91
title : 'returns' ,
0 commit comments