Skip to content

Commit f5415ce

Browse files
committed
Recognize docblocks on shape fields (fixes #21)
1 parent d3a3f3f commit f5415ce

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/utils/__tests__/getPropType-test.js

+26
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,30 @@ describe('getPropType', () => {
145145
});
146146
});
147147

148+
it('detects descriptions on nested types in shapes', () => {
149+
expect(getPropType(expression(`shape({
150+
/**
151+
* test1
152+
*/
153+
foo: string,
154+
/**
155+
* test2
156+
*/
157+
bar: bool
158+
})`)))
159+
.toEqual({
160+
name: 'shape',
161+
value: {
162+
foo: {
163+
name: 'string',
164+
description: 'test1',
165+
},
166+
bar: {
167+
name: 'bool',
168+
description: 'test2',
169+
},
170+
},
171+
});
172+
});
173+
148174
});

src/utils/getPropType.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/*eslint no-use-before-define: 0*/
1414

1515

16+
import {getDocblock} from '../utils/docblock';
1617
import getMembers from './getMembers';
1718
import getPropertyName from './getPropertyName';
1819
import printValue from './printValue';
@@ -74,8 +75,12 @@ function getPropTypeShape(argumentPath) {
7475
if (types.ObjectExpression.check(argumentPath.node)) {
7576
type.value = {};
7677
argumentPath.get('properties').each(function(propertyPath) {
77-
type.value[getPropertyName(propertyPath)] =
78-
getPropType(propertyPath.get('value'));
78+
var descriptor = getPropType(propertyPath.get('value'), true);
79+
var docs = getDocblock(propertyPath);
80+
if (docs) {
81+
descriptor.description = docs;
82+
}
83+
type.value[getPropertyName(propertyPath)] = descriptor;
7984
});
8085
}
8186

0 commit comments

Comments
 (0)