@@ -117,21 +117,52 @@ function argNameForType(type) {
117
117
return type [ 0 ] . toLowerCase ( ) + type . slice ( 1 ) ;
118
118
}
119
119
120
+ /**
121
+ * @param {Documentation.Class } classDesc
122
+ */
123
+ function hasUniqueEvents ( classDesc ) {
124
+ if ( ! classDesc . events . size )
125
+ return false ;
126
+ const parent = parentClass ( classDesc ) ;
127
+ if ( ! parent )
128
+ return true ;
129
+ return Array . from ( classDesc . events . keys ( ) ) . some ( eventName => ! parent . events . has ( eventName ) ) ;
130
+ }
131
+
132
+ /**
133
+ * @param {Documentation.Class } classDesc
134
+ */
135
+ function createEventDescriptions ( classDesc ) {
136
+ if ( ! hasUniqueEvents ( classDesc ) )
137
+ return [ ] ;
138
+ const descriptions = [ ] ;
139
+ for ( const [ eventName , value ] of classDesc . events ) {
140
+ const type = typeToString ( value && value . type , classDesc . name , eventName , 'payload' ) ;
141
+ const argName = argNameForType ( type ) ;
142
+ const params = argName ? `${ argName } : ${ type } ` : '' ;
143
+ descriptions . push ( {
144
+ params,
145
+ eventName,
146
+ comment : value . comment
147
+ } ) ;
148
+ }
149
+ return descriptions ;
150
+ }
151
+
120
152
/**
121
153
* @param {Documentation.Class } classDesc
122
154
*/
123
155
function classBody ( classDesc ) {
124
156
const parts = [ ] ;
157
+ const eventDescriptions = createEventDescriptions ( classDesc ) ;
125
158
for ( const method of [ 'on' , 'once' , 'addListener' ] ) {
126
- for ( const [ eventName , value ] of classDesc . events ) {
127
- if ( value . comment )
128
- parts . push ( writeComment ( value . comment , ' ' ) ) ;
129
- const type = typeToString ( value && value . type , classDesc . name , eventName , 'payload' ) ;
130
- const argName = argNameForType ( type ) ;
131
- const params = argName ? `${ argName } : ${ type } ` : '' ;
132
- parts . push ( ` ${ method } (event: '${ eventName } ', listener: (${ params } ) => void): this;\n` ) ;
159
+ for ( const { eventName, params, comment} of eventDescriptions ) {
160
+ if ( comment )
161
+ parts . push ( writeComment ( comment , ' ' ) ) ;
162
+ parts . push ( ` ${ method } (event: '${ eventName } ', listener: (${ params } ) => void): this;\n` ) ;
133
163
}
134
164
}
165
+
135
166
const members = classDesc . membersArray . filter ( member => member . kind !== 'event' ) ;
136
167
parts . push ( members . map ( member => {
137
168
if ( member . kind === 'event' )
@@ -312,7 +343,7 @@ function matchingBracket(str, open, close) {
312
343
function argsFromMember ( member , ...namespace ) {
313
344
if ( member . kind === 'property' )
314
345
return '' ;
315
- return '(' + member . argsArray . map ( arg => `${ nameForProperty ( arg ) } : ${ typeToString ( arg . type , ...namespace , member . name , 'options' ) } ` ) . join ( ', ' ) + ')' ;
346
+ return '(' + member . argsArray . map ( arg => `${ nameForProperty ( arg ) } : ${ typeToString ( arg . type , ...namespace , member . name , arg . name ) } ` ) . join ( ', ' ) + ')' ;
316
347
}
317
348
/**
318
349
* @param {Documentation.Member } member
0 commit comments