diff --git a/loaders/utils/__tests__/__snapshots__/getProps.spec.js.snap b/loaders/utils/__tests__/__snapshots__/getProps.spec.js.snap index 5c9e14388..3bb567635 100644 --- a/loaders/utils/__tests__/__snapshots__/getProps.spec.js.snap +++ b/loaders/utils/__tests__/__snapshots__/getProps.spec.js.snap @@ -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 {}, diff --git a/loaders/utils/__tests__/getProps.spec.js b/loaders/utils/__tests__/getProps.spec.js index 3683ff149..c7231d820 100644 --- a/loaders/utils/__tests__/getProps.spec.js +++ b/loaders/utils/__tests__/getProps.spec.js @@ -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(); +}); diff --git a/loaders/utils/getProps.js b/loaders/utils/getProps.js index c8f8b9d55..5e3f4dbc1 100644 --- a/loaders/utils/getProps.js +++ b/loaders/utils/getProps.js @@ -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;