Skip to content

Commit

Permalink
fix: cover more hideconstructor cases
Browse files Browse the repository at this point in the history
  • Loading branch information
rhendric committed Sep 4, 2017
1 parent 0307dba commit 5bdbf1f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
21 changes: 21 additions & 0 deletions __tests__/lib/parsers/javascript.js
Expand Up @@ -84,3 +84,24 @@ test('parse - document exported', function() {
).length
).toBe(2);
});

test('parse - constructor comments', function() {
expect(
toComments(`
class Test {
/** @hideconstructor */
constructor() {}
}
`).length
).toBe(0);

expect(
toComments(`
/** Test */
export class Test {
/** @hideconstructor */
constructor() {}
}
`)[0].constructorComment
).toBeDefined();
});
8 changes: 6 additions & 2 deletions src/parsers/javascript.js
Expand Up @@ -6,7 +6,8 @@ var _ = require('lodash'),
walkComments = require('../extractors/comments'),
walkExported = require('../extractors/exported'),
util = require('util'),
debuglog = util.debuglog('documentation');
debuglog = util.debuglog('documentation'),
findTarget = require('../infer/finders').findTarget;

import { parseToAst } from './parse_to_ast';

Expand Down Expand Up @@ -98,7 +99,7 @@ function _addComment(
}
const comment = parse(commentValue, commentLoc, context);
if (includeContext) {
commentsByNode.set(path.node, comment);
commentsByNode.set((findTarget(path) || path).node, comment);

if (t.isClassMethod(path) && path.node.kind === 'constructor') {
// #689
Expand All @@ -115,6 +116,9 @@ function _addComment(
parentComment.constructorComment = comment;
return;
}
if (comment.hideconstructor) {
return;
}
}
}
return comment;
Expand Down

0 comments on commit 5bdbf1f

Please sign in to comment.