Skip to content

Commit 38d1c37

Browse files
authored
fix: Correctly and recursively parse jsdoc types (#286)
BREAKING CHANGE: The type of method params and return is now aligned with flow types.
1 parent 6b9168b commit 38d1c37

File tree

4 files changed

+264
-162
lines changed

4 files changed

+264
-162
lines changed

src/handlers/__tests__/componentMethodsJsDocHandler-test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Documentation from '../../Documentation';
1414
import componentMethodsJsDocHandler from '../componentMethodsJsDocHandler';
1515

16-
describe('componentMethodsHandler', () => {
16+
describe('componentMethodsJsDocHandler', () => {
1717
let documentation;
1818

1919
beforeEach(() => {
@@ -76,6 +76,7 @@ describe('componentMethodsHandler', () => {
7676
{
7777
name: 'test',
7878
description: null,
79+
optional: false,
7980
type: { name: 'string' },
8081
},
8182
],
@@ -121,6 +122,7 @@ describe('componentMethodsHandler', () => {
121122
{
122123
name: 'test',
123124
description: null,
125+
optional: false,
124126
type: { name: 'number' },
125127
},
126128
],
@@ -166,6 +168,7 @@ describe('componentMethodsHandler', () => {
166168
{
167169
name: 'test',
168170
description: 'The test',
171+
optional: false,
169172
type: null,
170173
},
171174
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`parseJsDoc @param extracts jsdoc description 1`] = `
4+
Object {
5+
"description": null,
6+
"params": Array [
7+
Object {
8+
"description": "test",
9+
"name": "bar",
10+
"optional": false,
11+
"type": null,
12+
},
13+
],
14+
"returns": null,
15+
}
16+
`;
17+
18+
exports[`parseJsDoc @param extracts jsdoc empty description 1`] = `
19+
Object {
20+
"description": null,
21+
"params": Array [
22+
Object {
23+
"description": null,
24+
"name": "bar",
25+
"optional": false,
26+
"type": Object {
27+
"name": "string",
28+
},
29+
},
30+
],
31+
"returns": null,
32+
}
33+
`;
34+
35+
exports[`parseJsDoc @param extracts jsdoc optional 1`] = `
36+
Object {
37+
"description": null,
38+
"params": Array [
39+
Object {
40+
"description": null,
41+
"name": "bar",
42+
"optional": true,
43+
"type": Object {
44+
"name": "string",
45+
},
46+
},
47+
],
48+
"returns": null,
49+
}
50+
`;
51+
52+
exports[`parseJsDoc @param extracts jsdoc typed array 1`] = `
53+
Object {
54+
"description": null,
55+
"params": Array [
56+
Object {
57+
"description": null,
58+
"name": "bar",
59+
"optional": false,
60+
"type": Object {
61+
"elements": Array [
62+
Object {
63+
"name": "string",
64+
},
65+
Object {
66+
"name": "number",
67+
},
68+
],
69+
"name": "tuple",
70+
},
71+
},
72+
],
73+
"returns": null,
74+
}
75+
`;
76+
77+
exports[`parseJsDoc @param extracts jsdoc union type param 1`] = `
78+
Object {
79+
"description": null,
80+
"params": Array [
81+
Object {
82+
"description": null,
83+
"name": "bar",
84+
"optional": false,
85+
"type": Object {
86+
"elements": Array [
87+
Object {
88+
"name": "string",
89+
},
90+
Object {
91+
"name": "Object",
92+
},
93+
Object {
94+
"elements": Array [
95+
Object {
96+
"name": "some",
97+
},
98+
],
99+
"name": "Array",
100+
},
101+
],
102+
"name": "union",
103+
},
104+
},
105+
],
106+
"returns": null,
107+
}
108+
`;
109+
110+
exports[`parseJsDoc @returns extracts description from jsdoc 1`] = `
111+
Object {
112+
"description": null,
113+
"params": Array [],
114+
"returns": Object {
115+
"description": "The number",
116+
"type": null,
117+
},
118+
}
119+
`;
120+
121+
exports[`parseJsDoc @returns extracts jsdoc mixed types 1`] = `
122+
Object {
123+
"description": null,
124+
"params": Array [],
125+
"returns": Object {
126+
"description": null,
127+
"type": Object {
128+
"name": "mixed",
129+
},
130+
},
131+
}
132+
`;
133+
134+
exports[`parseJsDoc @returns extracts jsdoc typed array 1`] = `
135+
Object {
136+
"description": null,
137+
"params": Array [
138+
Object {
139+
"description": null,
140+
"name": "bar",
141+
"optional": false,
142+
"type": Object {
143+
"elements": Array [
144+
Object {
145+
"name": "string",
146+
},
147+
Object {
148+
"name": "number",
149+
},
150+
],
151+
"name": "tuple",
152+
},
153+
},
154+
],
155+
"returns": null,
156+
}
157+
`;
158+
159+
exports[`parseJsDoc @returns extracts jsdoc types 1`] = `
160+
Object {
161+
"description": null,
162+
"params": Array [],
163+
"returns": Object {
164+
"description": null,
165+
"type": Object {
166+
"name": "string",
167+
},
168+
},
169+
}
170+
`;
171+
172+
exports[`parseJsDoc @returns works with @return 1`] = `
173+
Object {
174+
"description": null,
175+
"params": Array [],
176+
"returns": Object {
177+
"description": "The number",
178+
"type": null,
179+
},
180+
}
181+
`;
182+
183+
exports[`parseJsDoc description extracts the method description in jsdoc 1`] = `
184+
Object {
185+
"description": "Don't use this!",
186+
"params": Array [],
187+
"returns": null,
188+
}
189+
`;

0 commit comments

Comments
 (0)