File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,22 @@ describe('parseJsDoc', () => {
64
64
} ) ;
65
65
} ) ;
66
66
67
+ it ( 'extracts jsdoc optional' , ( ) => {
68
+ const docblock = `
69
+ @param {string=} bar
70
+ ` ;
71
+ expect ( parseJsDoc ( docblock ) ) . toEqual ( {
72
+ description : null ,
73
+ returns : null ,
74
+ params : [ {
75
+ name : 'bar' ,
76
+ type : { name : 'string' } ,
77
+ description : null ,
78
+ optional : true ,
79
+ } ] ,
80
+ } ) ;
81
+ } ) ;
82
+
67
83
describe ( 'returns' , ( ) => {
68
84
69
85
it ( 'returns null if return is not documented' , ( ) => {
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ type JsDoc = {
17
17
name : string ;
18
18
description: ?string ;
19
19
type: ?{ name : string } ;
20
+ optional ? : boolean ;
20
21
} ] ;
21
22
returns: ?{
22
23
description: ?string ;
@@ -28,7 +29,14 @@ function getType(tag) {
28
29
if ( ! tag . type ) {
29
30
return null ;
30
31
}
31
- return { name : tag . type . name } ;
32
+ return { name : tag . type . name ? tag . type . name : tag . type . expression . name } ;
33
+ }
34
+
35
+ function getOptional ( tag ) {
36
+ if ( tag . type && tag . type . type && tag . type . type === 'OptionalType' ) {
37
+ return true ;
38
+ }
39
+ return ;
32
40
}
33
41
34
42
// Add jsdoc @return description.
@@ -57,6 +65,7 @@ function getParamsJsDoc(jsDoc) {
57
65
name : tag . name ,
58
66
description : tag . description ,
59
67
type : getType ( tag ) ,
68
+ optional : getOptional ( tag ) ,
60
69
} ;
61
70
} ) ;
62
71
}
You can’t perform that action at this time.
0 commit comments