Skip to content

Commit

Permalink
Fix: Fixes a crash when using a defaultProp that is not listed in pro…
Browse files Browse the repository at this point in the history
…ps (#437)
  • Loading branch information
ankri authored and sapegin committed May 10, 2017
1 parent f5c5d82 commit f237003
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
16 changes: 16 additions & 0 deletions loaders/utils/__tests__/__snapshots__/getProps.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ Object {
}
`;
exports[`should not crash when using doctrine to parse a default prop that isn't in the props list 1`] = `
Object {
"description": "The only true button.
",
"doclets": Object {},
"methods": Array [],
"props": Object {
"crash": Object {
"description": "",
"tags": Object {},
},
},
"tags": Object {},
}
`;
exports[`should remove non-public methods 1`] = `
Object {
"doclets": Object {},
Expand Down
14 changes: 14 additions & 0 deletions loaders/utils/__tests__/getProps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,17 @@ alert('Hello world');

expect(result).toMatchSnapshot();
});

it('should not crash when using doctrine to parse a default prop that isn\'t in the props list', () => {
const result = getProps({
description: 'The only true button.',
methods: [],
props: {
crash: {
description: undefined,
},
},
});

expect(result).toMatchSnapshot();
});
3 changes: 2 additions & 1 deletion loaders/utils/getProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ module.exports = function getProps(doc) {
Object.keys(doc.props).forEach(propName => {
const prop = doc.props[propName];
const doclets = getDocletsObject(prop.description);
const documentation = doctrine.parse(prop.description);
// when a prop is listed in defaultProps but not in props the prop.description is undefined
const documentation = doctrine.parse(prop.description || '');

// documentation.description is the description without tags
doc.props[propName].description = documentation.description;
Expand Down

0 comments on commit f237003

Please sign in to comment.