Skip to content

Commit be9ad62

Browse files
fabioeliapvasek
authored andcommitted
Expose name and description from component even when no props are found
1 parent 613b004 commit be9ad62

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/parser.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,26 +215,34 @@ export class Parser {
215215
this.extractPropsFromTypeIfStatelessComponent(type) ||
216216
this.extractPropsFromTypeIfStatefulComponent(type);
217217

218+
const resolvedComponentName = componentNameResolver(exp, source);
219+
const displayName =
220+
resolvedComponentName || computeComponentName(exp, source);
221+
const description = this.findDocComment(commentSource).fullComment;
222+
218223
if (propsType) {
219-
const resolvedComponentName = componentNameResolver(exp, source);
220-
const componentName =
221-
resolvedComponentName || computeComponentName(exp, source);
222224
const defaultProps = this.extractDefaultPropsFromComponent(exp, source);
223225
const props = this.getPropsInfo(propsType, defaultProps);
224226

225227
for (const propName of Object.keys(props)) {
226228
const prop = props[propName];
227-
const component: Component = { name: componentName };
229+
const component: Component = { name: displayName };
228230
if (!this.propFilter(prop, component)) {
229231
delete props[propName];
230232
}
231233
}
232234

233235
return {
234-
description: this.findDocComment(commentSource).fullComment,
235-
displayName: componentName,
236+
description,
237+
displayName,
236238
props
237239
};
240+
} else if (description && displayName) {
241+
return {
242+
description,
243+
displayName,
244+
props: {}
245+
};
238246
}
239247

240248
return null;
@@ -375,7 +383,7 @@ export class Parser {
375383
let mainComment = ts.displayPartsToString(
376384
symbol.getDocumentationComment(this.checker)
377385
);
378-
386+
379387
if (mainComment) {
380388
mainComment = mainComment.replace('\r\n', '\n');
381389
}

0 commit comments

Comments
 (0)