diff --git a/src/utils/__tests__/getPropType-test.js b/src/utils/__tests__/getPropType-test.js index 09ef1fac7df..d3887621010 100644 --- a/src/utils/__tests__/getPropType-test.js +++ b/src/utils/__tests__/getPropType-test.js @@ -145,4 +145,30 @@ describe('getPropType', () => { }); }); + it('detects descriptions on nested types in shapes', () => { + expect(getPropType(expression(`shape({ + /** + * test1 + */ + foo: string, + /** + * test2 + */ + bar: bool + })`))) + .toEqual({ + name: 'shape', + value: { + foo: { + name: 'string', + description: 'test1', + }, + bar: { + name: 'bool', + description: 'test2', + }, + }, + }); + }); + }); diff --git a/src/utils/getPropType.js b/src/utils/getPropType.js index bad436f72ee..f3e418b3ec5 100644 --- a/src/utils/getPropType.js +++ b/src/utils/getPropType.js @@ -13,6 +13,7 @@ /*eslint no-use-before-define: 0*/ +import {getDocblock} from '../utils/docblock'; import getMembers from './getMembers'; import getPropertyName from './getPropertyName'; import printValue from './printValue'; @@ -74,8 +75,12 @@ function getPropTypeShape(argumentPath) { if (types.ObjectExpression.check(argumentPath.node)) { type.value = {}; argumentPath.get('properties').each(function(propertyPath) { - type.value[getPropertyName(propertyPath)] = - getPropType(propertyPath.get('value')); + var descriptor = getPropType(propertyPath.get('value'), true); + var docs = getDocblock(propertyPath); + if (docs) { + descriptor.description = docs; + } + type.value[getPropertyName(propertyPath)] = descriptor; }); }