File tree 2 files changed +40
-1
lines changed
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -41,4 +41,26 @@ test('inferReturn', function() {
41
41
name : 'string' ,
42
42
type : 'NameExpression'
43
43
} ) ;
44
+ const generatorFn = evaluate (
45
+ '/** */function *a(): Generator<Foo, Bar, Baz> {}'
46
+ ) ;
47
+ expect ( generatorFn . generator ) . toBe ( true ) ;
48
+ expect ( generatorFn . yields ) . toEqual ( [
49
+ {
50
+ title : 'yields' ,
51
+ type : {
52
+ name : 'Foo' ,
53
+ type : 'NameExpression'
54
+ }
55
+ }
56
+ ] ) ;
57
+ expect ( generatorFn . returns ) . toEqual ( [
58
+ {
59
+ title : 'returns' ,
60
+ type : {
61
+ name : 'Bar' ,
62
+ type : 'NameExpression'
63
+ }
64
+ }
65
+ ] ) ;
44
66
} ) ;
Original file line number Diff line number Diff line change @@ -30,10 +30,27 @@ function inferReturn(comment) {
30
30
}
31
31
32
32
if ( t . isFunction ( fn ) && fn . returnType && fn . returnType . typeAnnotation ) {
33
- const returnType = flowDoctrine ( fn . returnType . typeAnnotation ) ;
33
+ let returnType = flowDoctrine ( fn . returnType . typeAnnotation ) ;
34
34
if ( comment . returns && comment . returns . length > 0 ) {
35
35
comment . returns [ 0 ] . type = returnType ;
36
36
} else {
37
+ if (
38
+ fn . generator &&
39
+ returnType . type === 'TypeApplication' &&
40
+ returnType . expression . name === 'Generator' &&
41
+ returnType . applications . length === 3
42
+ ) {
43
+ comment . generator = true ;
44
+ comment . yields = [
45
+ {
46
+ title : 'yields' ,
47
+ type : returnType . applications [ 0 ]
48
+ }
49
+ ] ;
50
+
51
+ returnType = returnType . applications [ 1 ] ;
52
+ }
53
+
37
54
comment . returns = [
38
55
{
39
56
title : 'returns' ,
You can’t perform that action at this time.
0 commit comments