Skip to content

Commit 44777a9

Browse files
committed
Consider leadingComments property first (fixes #49)
Works around a potential bug in recast v0.10.42
1 parent 2ec66f8 commit 44777a9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/utils/docblock.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ let DOCBLOCK_HEADER = /^\*\s/;
3131
*/
3232
export function getDocblock(path: NodePath): ?string {
3333
var comments = [];
34-
if (path.node.comments) {
34+
if (path.node.leadingComments) {
35+
comments = path.node.leadingComments.filter(
36+
comment => comment.type === 'CommentBlock' &&
37+
DOCBLOCK_HEADER.test(comment.value)
38+
);
39+
} else if (path.node.comments) {
3540
comments = path.node.comments.filter(
3641
comment => comment.leading &&
3742
comment.type === 'CommentBlock' &&
3843
DOCBLOCK_HEADER.test(comment.value)
3944
);
40-
} else if (path.node.leadingComments) {
41-
comments = path.node.leadingComments.filter(
42-
comment => comment.type === 'CommentBlock' &&
43-
DOCBLOCK_HEADER.test(comment.value)
44-
);
4545
}
4646

4747
if (comments.length > 0) {

0 commit comments

Comments
 (0)