Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Warning in ArgumentRenderer #1667 #1671

Merged
merged 2 commits into from Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/client/rsg-components/Argument/ArgumentRenderer.tsx
Expand Up @@ -15,7 +15,7 @@ export const styles = ({ space }: Rsg.Theme) => ({
});

export interface ArgumentProps {
name: string;
name?: string;
type?: any;
default?: string;
description?: string;
Expand Down Expand Up @@ -70,7 +70,7 @@ export const ArgumentRenderer: React.FunctionComponent<ArgumentPropsWithClasses>

ArgumentRenderer.propTypes = {
classes: PropTypes.objectOf(PropTypes.string.isRequired).isRequired,
name: PropTypes.string.isRequired,
name: PropTypes.string,
type: PropTypes.object,
default: PropTypes.string,
description: PropTypes.string,
Expand Down
34 changes: 34 additions & 0 deletions src/loaders/utils/__tests__/getProps.spec.ts
Expand Up @@ -225,6 +225,40 @@ 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
`,
returns: {
description: 'return a Boolean Value',
type: { name: 'boolean' },
},
},
] as any,
},
__filename
);

// @ts-ignore
expect(result.methods[0].returns).toEqual(
expect.objectContaining({
description: 'return a Boolean Value',
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];
const returns = method.returns
? {
...method.returns,
type: {
type: 'NameExpression',
...method.returns.type,
},
}
: returnTags[0];

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