@@ -36,9 +36,10 @@ function leftPad(str, width) {
36
36
*/
37
37
function parseJavaScript ( data : Object , config : DocumentationConfig ) {
38
38
var visited = new Set ( ) ;
39
+ const commentsByNode = new Map ( ) ;
39
40
40
41
var ast = parseToAst ( data . source ) ;
41
- var addComment = _addComment . bind ( null , visited ) ;
42
+ var addComment = _addComment . bind ( null , visited , commentsByNode ) ;
42
43
43
44
return _ . flatMap (
44
45
config . documentExported
@@ -54,6 +55,7 @@ function parseJavaScript(data: Object, config: DocumentationConfig) {
54
55
55
56
function _addComment (
56
57
visited ,
58
+ commentsByNode ,
57
59
data ,
58
60
commentValue ,
59
61
commentLoc ,
@@ -89,19 +91,33 @@ function _addComment(
89
91
value : path
90
92
} ) ;
91
93
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
-
99
94
if ( path . parentPath && path . parentPath . node ) {
100
95
var parentNode = path . parentPath . node ;
101
96
context . code = data . source . substring ( parentNode . start , parentNode . end ) ;
102
97
}
103
98
}
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 ;
105
121
}
106
122
}
107
123
0 commit comments