Skip to content

Commit 5bdbf1f

Browse files
committed
fix: cover more hideconstructor cases
1 parent 0307dba commit 5bdbf1f

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

__tests__/lib/parsers/javascript.js

+21
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,24 @@ test('parse - document exported', function() {
8484
).length
8585
).toBe(2);
8686
});
87+
88+
test('parse - constructor comments', function() {
89+
expect(
90+
toComments(`
91+
class Test {
92+
/** @hideconstructor */
93+
constructor() {}
94+
}
95+
`).length
96+
).toBe(0);
97+
98+
expect(
99+
toComments(`
100+
/** Test */
101+
export class Test {
102+
/** @hideconstructor */
103+
constructor() {}
104+
}
105+
`)[0].constructorComment
106+
).toBeDefined();
107+
});

src/parsers/javascript.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ var _ = require('lodash'),
66
walkComments = require('../extractors/comments'),
77
walkExported = require('../extractors/exported'),
88
util = require('util'),
9-
debuglog = util.debuglog('documentation');
9+
debuglog = util.debuglog('documentation'),
10+
findTarget = require('../infer/finders').findTarget;
1011

1112
import { parseToAst } from './parse_to_ast';
1213

@@ -98,7 +99,7 @@ function _addComment(
9899
}
99100
const comment = parse(commentValue, commentLoc, context);
100101
if (includeContext) {
101-
commentsByNode.set(path.node, comment);
102+
commentsByNode.set((findTarget(path) || path).node, comment);
102103

103104
if (t.isClassMethod(path) && path.node.kind === 'constructor') {
104105
// #689
@@ -115,6 +116,9 @@ function _addComment(
115116
parentComment.constructorComment = comment;
116117
return;
117118
}
119+
if (comment.hideconstructor) {
120+
return;
121+
}
118122
}
119123
}
120124
return comment;

0 commit comments

Comments
 (0)