@@ -36,9 +36,10 @@ function leftPad(str, width) {
3636 */
3737function parseJavaScript ( data : Object , config : DocumentationConfig ) {
3838 var visited = new Set ( ) ;
39+ const commentsByNode = new Map ( ) ;
3940
4041 var ast = parseToAst ( data . source ) ;
41- var addComment = _addComment . bind ( null , visited ) ;
42+ var addComment = _addComment . bind ( null , visited , commentsByNode ) ;
4243
4344 return _ . flatMap (
4445 config . documentExported
@@ -54,6 +55,7 @@ function parseJavaScript(data: Object, config: DocumentationConfig) {
5455
5556function _addComment (
5657 visited ,
58+ commentsByNode ,
5759 data ,
5860 commentValue ,
5961 commentLoc ,
@@ -89,19 +91,33 @@ function _addComment(
8991 value : path
9092 } ) ;
9193
92- // #689
93- if ( t . isClassMethod ( path ) && path . node . kind === 'constructor' ) {
94- debuglog (
95- 'A constructor was documented explicitly: document along with the class instead'
96- ) ;
97- }
98-
9994 if ( path . parentPath && path . parentPath . node ) {
10095 var parentNode = path . parentPath . node ;
10196 context . code = data . source . substring ( parentNode . start , parentNode . end ) ;
10297 }
10398 }
104- return parse ( commentValue , commentLoc , context ) ;
99+ const comment = parse ( commentValue , commentLoc , context ) ;
100+ if ( includeContext ) {
101+ commentsByNode . set ( path . node , comment ) ;
102+
103+ if ( t . isClassMethod ( path ) && path . node . kind === 'constructor' ) {
104+ // #689
105+ if ( ! comment . hideconstructor ) {
106+ debuglog (
107+ 'A constructor was documented explicitly: document along with the class instead'
108+ ) ;
109+ }
110+
111+ const parentComment = commentsByNode . get (
112+ path . parentPath . parentPath . node
113+ ) ;
114+ if ( parentComment ) {
115+ parentComment . constructorComment = comment ;
116+ return ;
117+ }
118+ }
119+ }
120+ return comment ;
105121 }
106122}
107123
0 commit comments