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 1 commit
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
2 changes: 1 addition & 1 deletion src/loaders/utils/getProps.ts
Expand Up @@ -94,7 +94,7 @@ 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 || returnTags[0]) && { ...method.returns, ...returnTags[0] };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this isn't different from the previous version, unless I'm missing something (in this case we should make it more clear).

We're returning method.returns if it's truthy, or returnTags[0].

Copy link
Contributor Author

@mitsuruog mitsuruog Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm... we need to make it more clear. in my case, method.returns have this object:

{ 
  description: 'return a Boolean Value', 
  type: { name: 'boolean' } 
}

and returnTags[0] have this object:

{
  title: 'returns',
  description: 'return a Boolean Value',
  type: { type: 'NameExpression', name: 'boolean' }
}

method.returns will have occurred DoctrineError when it does not have { type: 'NameExpression' }.
so I figured that merging both results would result in the intended object shape.
But I'm also sure I don't understand enough about this logic.

What should the correct object shape of results be?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm even more confused. So now we're overwriting anything in method.returns with returnTags[0] but previously method.returns had higher priority.

If method.returns is missing the type, why not add it there? Something like this:

const getReturns = ({method, tags}) => {
                 if (method.returns) {
                       return {
                           ...method.returns,
                           type: { type: 'NameExpression', ...method.returns.type } 
                       }
                 }

		const returnTags = getMergedTag(
			tags as TagProps,
			JS_DOC_METHOD_RETURN_TAG_SYNONYMS
		) as TagParamObject[];

                 return returnTags[0];
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously method.returns had higher priority.

I got it. I’ll add a change on the method.returns side.


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