Skip to content

Commit

Permalink
Fix @returns rendering (milesj#52)
Browse files Browse the repository at this point in the history
Prior to this, @returns would be emitted literally and it was duplicated. This PR, subsets the
comment objects so that comments for the return type render properly
  • Loading branch information
chadhietala committed Jul 13, 2022
1 parent 99b9e71 commit 428c509
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
9 changes: 9 additions & 0 deletions fixtures/monorepo/standard/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
export type Type = 'standard';

/**
* a thing for a thing
* @param a id
* @returns returns the param
*/
export function bizz(a: string): string {
return a;
}
28 changes: 26 additions & 2 deletions packages/plugin/src/components/MemberSignatureBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,30 @@ export interface MemberSignatureBodyProps {
sig: JSONOutput.SignatureReflection;
}

function excludeBlockTags(comment?: JSONOutput.Comment): JSONOutput.Comment | undefined {
if (comment) {
const { blockTags, ...rest } = comment;
return rest;
}
return undefined;
}

function intoReturnComment(comment?: JSONOutput.Comment): JSONOutput.Comment | undefined {
if (comment?.blockTags) {
const tags = comment.blockTags.map((tag) => tag.tag);

if (tags.includes('@returns')) {
const index = tags.indexOf('@returns');

return {
summary: comment.blockTags[index].content
}
}
}

return undefined;
}

// eslint-disable-next-line complexity
export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyProps) {
const minimal = useMinimalLayout();
Expand All @@ -45,7 +69,7 @@ export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyPro
<>
{!hideSources && <MemberSources reflection={sig} />}

<Comment comment={sig.comment} />
<Comment comment={excludeBlockTags(sig.comment)} />

{hasComment(sig.comment) && (showTypes || showParams || showReturn) && (
<hr className="tsd-divider" />
Expand Down Expand Up @@ -86,7 +110,7 @@ export function MemberSignatureBody({ hideSources, sig }: MemberSignatureBodyPro
Returns <Type type={sig.type} />
</h4>

<Comment comment={sig.comment} />
<Comment comment={intoReturnComment(sig.comment)} />

<Parameter param={sig.type?.declaration} />
</>
Expand Down

0 comments on commit 428c509

Please sign in to comment.