Skip to content

Commit d3a3f3f

Browse files
committed
Support "short" docblocks (fixes #20)
This adds support for one-line docblocks, i.e. ``` /** comment */ ```
1 parent ac9277a commit d3a3f3f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/utils/__tests__/docblock-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ describe('docblock', () => {
7474
expect(getDocblock(node)).toEqual(comment.join('\n'));
7575
});
7676
});
77+
78+
it('supports "short" docblocks', () => {
79+
let source = [ // eslint-disable-line no-shadow
80+
'/** bar */',
81+
'foo;',
82+
];
83+
let node = statement(source.join('\n'));
84+
expect(getDocblock(node)).toEqual('bar');
85+
});
7786
});
7887

7988
});

src/utils/docblock.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function parseDocblock(str) {
2323
return lines.join('\n').trim();
2424
}
2525

26+
let DOCBLOCK_HEADER = /^\*\s/;
27+
2628
/**
2729
* Given a path, this function returns the closest preceding docblock if it
2830
* exists.
@@ -32,7 +34,7 @@ export function getDocblock(path: NodePath): ?string {
3234
var comments = path.node.comments.filter(function(comment) {
3335
return comment.leading &&
3436
comment.type === 'CommentBlock' &&
35-
comment.value.indexOf('*\n') === 0;
37+
DOCBLOCK_HEADER.test(comment.value);
3638
});
3739
if (comments.length > 0) {
3840
return parseDocblock(comments[comments.length - 1].value);

0 commit comments

Comments
 (0)