File tree Expand file tree Collapse file tree 4 files changed +110
-4
lines changed Expand file tree Collapse file tree 4 files changed +110
-4
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,52 @@ Array [
30
30
` ;
31
31
32
32
exports [` inferParams 2` ] = `
33
+ Array [
34
+ Object {
35
+ " anonymous" : true ,
36
+ " name" : " $0" ,
37
+ " properties" : Array [
38
+ Object {
39
+ " lineNumber" : 1 ,
40
+ " name" : " $0.0" ,
41
+ " title" : " param" ,
42
+ " type" : Object {
43
+ " name" : " string" ,
44
+ " type" : " NameExpression" ,
45
+ },
46
+ },
47
+ Object {
48
+ " lineNumber" : 1 ,
49
+ " name" : " $0.1" ,
50
+ " title" : " param" ,
51
+ },
52
+ Object {
53
+ " anonymous" : true ,
54
+ " name" : " $0.2" ,
55
+ " properties" : Array [
56
+ Object {
57
+ " lineNumber" : 1 ,
58
+ " name" : " $0.2.c" ,
59
+ " title" : " param" ,
60
+ },
61
+ ],
62
+ " title" : " param" ,
63
+ " type" : Object {
64
+ " name" : " Object" ,
65
+ " type" : " NameExpression" ,
66
+ },
67
+ },
68
+ ],
69
+ " title" : " param" ,
70
+ " type" : Object {
71
+ " name" : " Array" ,
72
+ " type" : " NameExpression" ,
73
+ },
74
+ } ,
75
+ ]
76
+ ` ;
77
+
78
+ exports [` inferParams 3` ] = `
33
79
Array [
34
80
Object {
35
81
" description" : Object {
@@ -102,7 +148,7 @@ Array [
102
148
]
103
149
` ;
104
150
105
- exports [` inferParams 3 ` ] = `
151
+ exports [` inferParams 4 ` ] = `
106
152
Array [
107
153
Object {
108
154
" default" : " 4" ,
@@ -114,7 +160,7 @@ Array [
114
160
]
115
161
` ;
116
162
117
- exports [` inferParams 4 ` ] = `
163
+ exports [` inferParams 5 ` ] = `
118
164
Array [
119
165
Object {
120
166
" default" : " 4" ,
@@ -129,7 +175,7 @@ Array [
129
175
]
130
176
` ;
131
177
132
- exports [` inferParams 5 ` ] = `
178
+ exports [` inferParams 6 ` ] = `
133
179
Array [
134
180
Object {
135
181
" anonymous" : true ,
@@ -150,7 +196,7 @@ Array [
150
196
]
151
197
` ;
152
198
153
- exports [` inferParams 6 ` ] = `
199
+ exports [` inferParams 7 ` ] = `
154
200
Array [
155
201
Object {
156
202
" anonymous" : true ,
Original file line number Diff line number Diff line change @@ -62,6 +62,18 @@ test('inferName', function() {
62
62
} ) . name
63
63
) . toBe ( 'name' ) ;
64
64
65
+ expect (
66
+ evaluate ( function ( ) {
67
+ exports = {
68
+ // Property
69
+ // Identifier (comment attached here)
70
+ // FunctionExpression
71
+ /** Test */
72
+ name ( ) { }
73
+ } ;
74
+ } ) . name
75
+ ) . toBe ( 'name' ) ;
76
+
65
77
expect (
66
78
evaluate ( function ( ) {
67
79
/** Test */
Original file line number Diff line number Diff line change @@ -93,6 +93,10 @@ test('inferParams', function() {
93
93
evaluate ( `/** Test */function f({ x, ...xs }) {};` ) . params
94
94
) . toMatchSnapshot ( ) ;
95
95
96
+ expect (
97
+ evaluate ( `/** Test */function f([a: string, b, {c}]) {};` ) . params
98
+ ) . toMatchSnapshot ( ) ;
99
+
96
100
expect (
97
101
evaluate (
98
102
`
Original file line number Diff line number Diff line change
1
+ /*eslint-disable no-unused-vars*/
2
+ var inferReturn = require ( '../../../src/infer/return' ) ,
3
+ parse = require ( '../../../src/parsers/javascript' ) ;
4
+
5
+ function toComment ( fn , filename ) {
6
+ return parse (
7
+ {
8
+ file : filename ,
9
+ source : fn instanceof Function ? '(' + fn . toString ( ) + ')' : fn
10
+ } ,
11
+ { }
12
+ ) [ 0 ] ;
13
+ }
14
+
15
+ function evaluate ( code ) {
16
+ return inferReturn ( toComment ( code ) ) ;
17
+ }
18
+
19
+ test ( 'inferReturn' , function ( ) {
20
+ expect ( evaluate ( '/** */function a(): number {}' ) . returns ) . toEqual ( [
21
+ {
22
+ title : 'returns' ,
23
+ type : {
24
+ name : 'number' ,
25
+ type : 'NameExpression'
26
+ }
27
+ }
28
+ ] ) ;
29
+ expect ( evaluate ( '/** */var a = function(): number {}' ) . returns ) . toEqual ( [
30
+ {
31
+ title : 'returns' ,
32
+ type : {
33
+ name : 'number' ,
34
+ type : 'NameExpression'
35
+ }
36
+ }
37
+ ] ) ;
38
+ expect (
39
+ evaluate ( '/** @returns {string} */function a(): number {}' ) . returns [ 0 ] . type
40
+ ) . toEqual ( {
41
+ name : 'string' ,
42
+ type : 'NameExpression'
43
+ } ) ;
44
+ } ) ;
You can’t perform that action at this time.
0 commit comments