File tree Expand file tree Collapse file tree 5 files changed +182
-2
lines changed Expand file tree Collapse file tree 5 files changed +182
-2
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- var finders = require ( './finders' ) ,
3
+ var findTarget = require ( './finders' ) . findTarget ,
4
4
t = require ( 'babel-types' ) ,
5
5
shouldSkipInference = require ( './should_skip_inference' ) ,
6
6
flowDoctrine = require ( '../flow_doctrine' ) ;
@@ -17,8 +17,15 @@ module.exports = function () {
17
17
if ( comment . returns ) {
18
18
return comment ;
19
19
}
20
- var path = finders . findTarget ( comment . context . ast ) ;
20
+ var path = findTarget ( comment . context . ast ) ;
21
21
var fn = path && path . node ;
22
+
23
+ // In case of `/** */ var x = function () {}` findTarget returns
24
+ // the declarator.
25
+ if ( t . isVariableDeclarator ( fn ) ) {
26
+ fn = fn . init ;
27
+ }
28
+
22
29
if ( t . isFunction ( fn ) &&
23
30
fn . returnType &&
24
31
fn . returnType . typeAnnotation ) {
Original file line number Diff line number Diff line change
1
+ /** */
2
+ var f = function ( x : number ) : boolean { }
Original file line number Diff line number Diff line change
1
+ [
2
+ {
3
+ "description" : " " ,
4
+ "tags" : [],
5
+ "loc" : {
6
+ "start" : {
7
+ "line" : 1 ,
8
+ "column" : 0
9
+ },
10
+ "end" : {
11
+ "line" : 1 ,
12
+ "column" : 6
13
+ }
14
+ },
15
+ "context" : {
16
+ "loc" : {
17
+ "start" : {
18
+ "line" : 2 ,
19
+ "column" : 0
20
+ },
21
+ "end" : {
22
+ "line" : 2 ,
23
+ "column" : 39
24
+ }
25
+ }
26
+ },
27
+ "errors" : [],
28
+ "name" : " f" ,
29
+ "kind" : " function" ,
30
+ "params" : [
31
+ {
32
+ "title" : " param" ,
33
+ "name" : " x" ,
34
+ "lineNumber" : 2 ,
35
+ "type" : {
36
+ "type" : " NameExpression" ,
37
+ "name" : " number"
38
+ }
39
+ }
40
+ ],
41
+ "returns" : [
42
+ {
43
+ "type" : {
44
+ "type" : " NameExpression" ,
45
+ "name" : " boolean"
46
+ }
47
+ }
48
+ ],
49
+ "members" : {
50
+ "instance" : [],
51
+ "static" : []
52
+ },
53
+ "path" : [
54
+ {
55
+ "name" : " f" ,
56
+ "kind" : " function"
57
+ }
58
+ ],
59
+ "namespace" : " f"
60
+ }
61
+ ]
Original file line number Diff line number Diff line change
1
+ <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
2
+
3
+ # f
4
+
5
+ ** Parameters**
6
+
7
+ - ` x ` ** [ number] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number ) **
8
+
9
+ Returns ** [ boolean] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean ) **
Original file line number Diff line number Diff line change
1
+ {
2
+ "type" : " root" ,
3
+ "children" : [
4
+ {
5
+ "type" : " html" ,
6
+ "value" : " <!-- Generated by documentation.js. Update this documentation by updating the source code. -->"
7
+ },
8
+ {
9
+ "depth" : 1 ,
10
+ "type" : " heading" ,
11
+ "children" : [
12
+ {
13
+ "type" : " text" ,
14
+ "value" : " f"
15
+ }
16
+ ]
17
+ },
18
+ {
19
+ "type" : " strong" ,
20
+ "children" : [
21
+ {
22
+ "type" : " text" ,
23
+ "value" : " Parameters"
24
+ }
25
+ ]
26
+ },
27
+ {
28
+ "ordered" : false ,
29
+ "type" : " list" ,
30
+ "children" : [
31
+ {
32
+ "type" : " listItem" ,
33
+ "children" : [
34
+ {
35
+ "type" : " paragraph" ,
36
+ "children" : [
37
+ {
38
+ "type" : " inlineCode" ,
39
+ "value" : " x"
40
+ },
41
+ {
42
+ "type" : " text" ,
43
+ "value" : " "
44
+ },
45
+ {
46
+ "type" : " strong" ,
47
+ "children" : [
48
+ {
49
+ "href" : " https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number" ,
50
+ "url" : " https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number" ,
51
+ "type" : " link" ,
52
+ "children" : [
53
+ {
54
+ "type" : " text" ,
55
+ "value" : " number"
56
+ }
57
+ ]
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ "type" : " text" ,
63
+ "value" : " "
64
+ }
65
+ ]
66
+ }
67
+ ]
68
+ }
69
+ ]
70
+ },
71
+ {
72
+ "type" : " paragraph" ,
73
+ "children" : [
74
+ {
75
+ "type" : " text" ,
76
+ "value" : " Returns "
77
+ },
78
+ {
79
+ "type" : " strong" ,
80
+ "children" : [
81
+ {
82
+ "href" : " https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean" ,
83
+ "url" : " https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean" ,
84
+ "type" : " link" ,
85
+ "children" : [
86
+ {
87
+ "type" : " text" ,
88
+ "value" : " boolean"
89
+ }
90
+ ]
91
+ }
92
+ ]
93
+ },
94
+ {
95
+ "type" : " text" ,
96
+ "value" : " "
97
+ }
98
+ ]
99
+ }
100
+ ]
101
+ }
You can’t perform that action at this time.
0 commit comments