11'use strict'
22var o = require ( 'object-tools' )
33var a = require ( 'array-tools' )
4+ const testValue = require ( 'test-value' )
45
56var data
67exports . createConstructor = createConstructor
@@ -109,22 +110,23 @@ function insertConstructors (data) {
109110 var toDelete = [ ]
110111
111112 data . forEach ( function ( identifier , index ) {
112- if ( identifier . kind === 'class' && identifier . scope !== 'static' ) {
113- const es6constructor = a . findWhere ( data , { kind : 'class' , scope : 'static' , memberof : identifier . longname } )
113+ if ( isES5Class ( identifier ) ) {
114+ replacements . push ( { index : index , items : createConstructor ( identifier ) } )
115+ } else if ( isES6Class ( identifier ) ) {
116+ const es6constructor = getEs6Constructor ( data , identifier )
114117 if ( es6constructor ) {
115118 if ( ! ( es6constructor . description || ( es6constructor . params && es6constructor . params . length ) ) ) {
116119 toDelete . push ( es6constructor )
117120 }
118121 es6constructor . kind = 'constructor'
122+ es6constructor . memberof = identifier . longname
119123 const constructorChildren = a . where ( data , { memberof : es6constructor . longname } )
120124 constructorChildren . forEach ( i => {
121125 i . memberof = identifier . longname
122126 } )
123127 identifier . description = identifier . classdesc
124128 delete identifier . classdesc
125129 delete identifier . params
126- } else {
127- replacements . push ( { index : index , items : createConstructor ( identifier ) } )
128130 }
129131 }
130132 } )
@@ -141,6 +143,29 @@ function insertConstructors (data) {
141143 return data
142144}
143145
146+ /* unfortunately the jsdoc data structure differs between es5 and es6 classes, hence the need for these four functions */
147+ function getEs6Constructor ( data , identifier ) {
148+ return data . find ( isES6Constructor )
149+ }
150+ function isES5Class ( identifier ) {
151+ return testValue ( identifier , {
152+ kind : 'class' ,
153+ meta : { code : { type : 'FunctionDeclaration' } }
154+ } )
155+ }
156+ function isES6Class ( identifier ) {
157+ return testValue ( identifier , {
158+ kind : 'class' ,
159+ meta : { code : { type : 'ClassDeclaration' } }
160+ } )
161+ }
162+ function isES6Constructor ( identifier ) {
163+ return testValue ( identifier , {
164+ kind : 'class' ,
165+ meta : { code : { type : 'MethodDefinition' } }
166+ } )
167+ }
168+
144169function updateIDReferences ( identifier , newID ) {
145170 var oldID = newID . split ( '--' ) [ 0 ]
146171 if ( oldID && ! identifier . isExported ) {
0 commit comments