Skip to content

Commit f2f280c

Browse files
authored
Merge pull request #21794 from storybookjs/norbert/fix-jstag-deprecated-not-showing-up
Fix: missing deprecated tag from JSdoc
2 parents 7cc5e2e + 37caaae commit f2f280c

File tree

8 files changed

+444
-114
lines changed

8 files changed

+444
-114
lines changed

code/lib/docs-tools/src/argTypes/docgen/createPropDef.ts

+10-13
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,17 @@ function applyJsDocResult(propDef: PropDef, jsDocParsingResult: JsDocParsingResu
9090
propDef.description = jsDocParsingResult.description;
9191
}
9292

93-
const hasParams = extractedTags.params != null;
94-
const hasReturns = extractedTags.returns != null && extractedTags.returns.type != null;
95-
96-
if (hasParams || hasReturns) {
93+
const value = {
94+
...extractedTags,
95+
params: extractedTags?.params?.map((x) => ({
96+
name: x.getPrettyName(),
97+
description: x.description,
98+
})),
99+
};
100+
101+
if (Object.values(value).filter(Boolean).length > 0) {
97102
// eslint-disable-next-line no-param-reassign
98-
propDef.jsDocTags = {
99-
params:
100-
hasParams &&
101-
extractedTags.params.map((x) => ({
102-
name: x.getPrettyName(),
103-
description: x.description,
104-
})),
105-
returns: hasReturns && { description: extractedTags.returns.description },
106-
};
103+
propDef.jsDocTags = value;
107104
}
108105
}
109106

code/lib/docs-tools/src/argTypes/jsdocParser.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ describe('parseJsDoc', () => {
233233
const { extractedTags } = parseJsDoc('@deprecated string');
234234

235235
expect(extractedTags.deprecated).not.toBeNull();
236-
expect(extractedTags.deprecated.name).not.toBeNull();
237-
expect(extractedTags.deprecated.name).toBe('string');
236+
expect(extractedTags.deprecated).not.toBeNull();
237+
expect(extractedTags.deprecated).toBe('string');
238238
});
239239
});
240240

code/lib/docs-tools/src/argTypes/jsdocParser.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ export interface ExtractedJsDocParam {
99
getTypeName: () => string;
1010
}
1111

12-
export interface ExtractedJsDocDeprecated {
13-
name: string;
14-
}
15-
1612
export interface ExtractedJsDocReturns {
1713
type?: any;
1814
description?: string;
@@ -21,7 +17,7 @@ export interface ExtractedJsDocReturns {
2117

2218
export interface ExtractedJsDoc {
2319
params?: ExtractedJsDocParam[];
24-
deprecated?: ExtractedJsDocDeprecated;
20+
deprecated?: string;
2521
returns?: ExtractedJsDocReturns;
2622
ignore: boolean;
2723
}
@@ -178,11 +174,9 @@ function extractParam(tag: doctrine.Tag): ExtractedJsDocParam {
178174
return null;
179175
}
180176

181-
function extractDeprecated(tag: doctrine.Tag): ExtractedJsDocDeprecated {
177+
function extractDeprecated(tag: doctrine.Tag): string {
182178
if (tag.title != null) {
183-
return {
184-
name: tag.description,
185-
};
179+
return tag.description;
186180
}
187181

188182
return null;

code/renderers/react/template/stories/docgen-components/9721-ts-deprecated-jsdoc/argTypes.snapshot

+8-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ Object {
3838
"name": "width",
3939
"table": Object {
4040
"defaultValue": null,
41-
"jsDocTags": undefined,
41+
"jsDocTags": Object {
42+
"deprecated": "Do not use! Use \`size\` instead!
43+
44+
Width of foo",
45+
"ignore": false,
46+
"params": undefined,
47+
"returns": null,
48+
},
4249
"type": Object {
4350
"detail": undefined,
4451
"summary": "number",

code/renderers/react/template/stories/docgen-components/9721-ts-deprecated-jsdoc/properties.snapshot

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ Object {
66
Object {
77
"defaultValue": null,
88
"description": "",
9+
"jsDocTags": Object {
10+
"deprecated": "Do not use! Use \`size\` instead!
11+
12+
Width of foo",
13+
"ignore": false,
14+
"params": undefined,
15+
"returns": null,
16+
},
917
"name": "width",
1018
"required": true,
1119
"sbType": Object {

0 commit comments

Comments
 (0)