Skip to content

Commit

Permalink
Merge pull request #21794 from storybookjs/norbert/fix-jstag-deprecat…
Browse files Browse the repository at this point in the history
…ed-not-showing-up

Fix: missing deprecated tag from JSdoc
  • Loading branch information
ndelangen authored Mar 28, 2023
2 parents 7cc5e2e + 37caaae commit f2f280c
Show file tree
Hide file tree
Showing 8 changed files with 444 additions and 114 deletions.
23 changes: 10 additions & 13 deletions code/lib/docs-tools/src/argTypes/docgen/createPropDef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,17 @@ function applyJsDocResult(propDef: PropDef, jsDocParsingResult: JsDocParsingResu
propDef.description = jsDocParsingResult.description;
}

const hasParams = extractedTags.params != null;
const hasReturns = extractedTags.returns != null && extractedTags.returns.type != null;

if (hasParams || hasReturns) {
const value = {
...extractedTags,
params: extractedTags?.params?.map((x) => ({
name: x.getPrettyName(),
description: x.description,
})),
};

if (Object.values(value).filter(Boolean).length > 0) {
// eslint-disable-next-line no-param-reassign
propDef.jsDocTags = {
params:
hasParams &&
extractedTags.params.map((x) => ({
name: x.getPrettyName(),
description: x.description,
})),
returns: hasReturns && { description: extractedTags.returns.description },
};
propDef.jsDocTags = value;
}
}

Expand Down
4 changes: 2 additions & 2 deletions code/lib/docs-tools/src/argTypes/jsdocParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ describe('parseJsDoc', () => {
const { extractedTags } = parseJsDoc('@deprecated string');

expect(extractedTags.deprecated).not.toBeNull();
expect(extractedTags.deprecated.name).not.toBeNull();
expect(extractedTags.deprecated.name).toBe('string');
expect(extractedTags.deprecated).not.toBeNull();
expect(extractedTags.deprecated).toBe('string');
});
});

Expand Down
12 changes: 3 additions & 9 deletions code/lib/docs-tools/src/argTypes/jsdocParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ export interface ExtractedJsDocParam {
getTypeName: () => string;
}

export interface ExtractedJsDocDeprecated {
name: string;
}

export interface ExtractedJsDocReturns {
type?: any;
description?: string;
Expand All @@ -21,7 +17,7 @@ export interface ExtractedJsDocReturns {

export interface ExtractedJsDoc {
params?: ExtractedJsDocParam[];
deprecated?: ExtractedJsDocDeprecated;
deprecated?: string;
returns?: ExtractedJsDocReturns;
ignore: boolean;
}
Expand Down Expand Up @@ -178,11 +174,9 @@ function extractParam(tag: doctrine.Tag): ExtractedJsDocParam {
return null;
}

function extractDeprecated(tag: doctrine.Tag): ExtractedJsDocDeprecated {
function extractDeprecated(tag: doctrine.Tag): string {
if (tag.title != null) {
return {
name: tag.description,
};
return tag.description;
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ Object {
"name": "width",
"table": Object {
"defaultValue": null,
"jsDocTags": undefined,
"jsDocTags": Object {
"deprecated": "Do not use! Use \`size\` instead!

Width of foo",
"ignore": false,
"params": undefined,
"returns": null,
},
"type": Object {
"detail": undefined,
"summary": "number",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Object {
Object {
"defaultValue": null,
"description": "",
"jsDocTags": Object {
"deprecated": "Do not use! Use \`size\` instead!

Width of foo",
"ignore": false,
"params": undefined,
"returns": null,
},
"name": "width",
"required": true,
"sbType": Object {
Expand Down
Loading

0 comments on commit f2f280c

Please sign in to comment.