From fa3fcc7e005e14a62b6850298615cf58f176884f Mon Sep 17 00:00:00 2001 From: Mitsuru Ogawa Date: Sun, 6 Sep 2020 22:03:00 +0900 Subject: [PATCH] Fix --- src/loaders/utils/__tests__/getProps.spec.ts | 31 ++++++++++++++++++++ src/loaders/utils/getProps.ts | 10 ++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/loaders/utils/__tests__/getProps.spec.ts b/src/loaders/utils/__tests__/getProps.spec.ts index e08ecf736..c6f672944 100644 --- a/src/loaders/utils/__tests__/getProps.spec.ts +++ b/src/loaders/utils/__tests__/getProps.spec.ts @@ -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( { diff --git a/src/loaders/utils/getProps.ts b/src/loaders/utils/getProps.ts index f2f14622c..c83e915b2 100644 --- a/src/loaders/utils/getProps.ts +++ b/src/loaders/utils/getProps.ts @@ -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;