Skip to content

Commit b3271f9

Browse files
authored
Merge pull request #230 from squah-u/fix-default-only-jsdoc
Fix @default jsdoc annotation with no description being ignored
2 parents 21db57c + 96d06c2 commit b3271f9

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as React from 'react';
2+
3+
export interface StatelessWithDefaultOnlyJsDocProps {
4+
/** @default hello */
5+
myProp: string;
6+
}
7+
/** StatelessWithDefaultOnlyJsDoc description */
8+
export const StatelessWithDefaultOnlyJsDoc: React.StatelessComponent<
9+
StatelessWithDefaultOnlyJsDocProps
10+
> = props => <div>My Property = {props.myProp}</div>;

src/__tests__/parser.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,14 @@ describe('parser', () => {
468468
});
469469
});
470470

471+
it('should parse jsdocs with the @default tag and no description', () => {
472+
check('StatelessWithDefaultOnlyJsDoc', {
473+
StatelessWithDefaultOnlyJsDoc: {
474+
myProp: { defaultValue: 'hello', description: '', type: 'string' }
475+
}
476+
});
477+
});
478+
471479
it('should parse functional component component defined as function', () => {
472480
check('FunctionDeclaration', {
473481
Jumbotron: {

src/parser.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,15 @@ export class Parser {
540540

541541
public findDocComment(symbol: ts.Symbol): JSDoc {
542542
const comment = this.getFullJsDocComment(symbol);
543-
if (comment.fullComment) {
543+
if (comment.fullComment || comment.tags.default) {
544544
return comment;
545545
}
546546

547547
const rootSymbols = this.checker.getRootSymbols(symbol);
548548
const commentsOnRootSymbols = rootSymbols
549549
.filter(x => x !== symbol)
550550
.map(x => this.getFullJsDocComment(x))
551-
.filter(x => !!x.fullComment);
551+
.filter(x => !!x.fullComment || !!comment.tags.default);
552552

553553
if (commentsOnRootSymbols.length) {
554554
return commentsOnRootSymbols[0];

0 commit comments

Comments
 (0)