Skip to content

Commit

Permalink
Recognize docblocks on shape fields (fixes #21)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkling committed Sep 1, 2015
1 parent d3a3f3f commit f5415ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
26 changes: 26 additions & 0 deletions src/utils/__tests__/getPropType-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
});
});

});
9 changes: 7 additions & 2 deletions src/utils/getPropType.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
});
}

Expand Down

0 comments on commit f5415ce

Please sign in to comment.