Skip to content

Commit f237003

Browse files
ankrisapegin
authored andcommitted
Fix: Fixes a crash when using a defaultProp that is not listed in props (#437)
1 parent f5c5d82 commit f237003

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

loaders/utils/__tests__/__snapshots__/getProps.spec.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ Object {
2424
}
2525
`;
2626
27+
exports[`should not crash when using doctrine to parse a default prop that isn't in the props list 1`] = `
28+
Object {
29+
"description": "The only true button.
30+
",
31+
"doclets": Object {},
32+
"methods": Array [],
33+
"props": Object {
34+
"crash": Object {
35+
"description": "",
36+
"tags": Object {},
37+
},
38+
},
39+
"tags": Object {},
40+
}
41+
`;
42+
2743
exports[`should remove non-public methods 1`] = `
2844
Object {
2945
"doclets": Object {},

loaders/utils/__tests__/getProps.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,17 @@ alert('Hello world');
107107

108108
expect(result).toMatchSnapshot();
109109
});
110+
111+
it('should not crash when using doctrine to parse a default prop that isn\'t in the props list', () => {
112+
const result = getProps({
113+
description: 'The only true button.',
114+
methods: [],
115+
props: {
116+
crash: {
117+
description: undefined,
118+
},
119+
},
120+
});
121+
122+
expect(result).toMatchSnapshot();
123+
});

loaders/utils/getProps.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ module.exports = function getProps(doc) {
6868
Object.keys(doc.props).forEach(propName => {
6969
const prop = doc.props[propName];
7070
const doclets = getDocletsObject(prop.description);
71-
const documentation = doctrine.parse(prop.description);
71+
// when a prop is listed in defaultProps but not in props the prop.description is undefined
72+
const documentation = doctrine.parse(prop.description || '');
7273

7374
// documentation.description is the description without tags
7475
doc.props[propName].description = documentation.description;

0 commit comments

Comments
 (0)