Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuruog committed Sep 6, 2020
1 parent 6bd3c01 commit fa3fcc7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/loaders/utils/__tests__/getProps.spec.ts
Expand Up @@ -225,6 +225,37 @@ it("should not crash when using doctrine to parse a default prop that isn't in t
expect(result).toMatchSnapshot();
});

it('should not crash when using doctrine to parse a return method that does not have type in it', () => {
const result = getProps(
{
displayName: 'Button',
methods: [
{
docblock: `
Public Method
@public
@returns {Boolean} return a Boolean Value
`,
},
] as any,
},
__filename
);

// @ts-ignore
expect(result.methods[0].returns).toEqual(
expect.objectContaining({
description: 'return a Boolean Value',
title: 'returns',
type: {
name: 'Boolean',
type: 'NameExpression',
},
})
);
});

it('should guess a displayName for components that react-docgen was not able to recognize', () => {
const result = getProps(
{
Expand Down
10 changes: 9 additions & 1 deletion src/loaders/utils/getProps.ts
Expand Up @@ -94,7 +94,15 @@ export default function getProps(doc: DocumentationObject, filepath?: string): R
allTags as TagProps,
JS_DOC_METHOD_RETURN_TAG_SYNONYMS
) as TagParamObject[];
const returns = (method.returns || returnTags[0]) && { ...method.returns, ...returnTags[0] };
const returns = method.returns
? {
...method.returns,
type: {
type: 'NameExpression',
...method.returns.type,
},
}
: returnTags[0];

if (returns) {
method.returns = returns;
Expand Down

0 comments on commit fa3fcc7

Please sign in to comment.