@@ -320,19 +320,37 @@ function generateNameDefault(member, name, t, parent) {
320
320
let enumName = generateEnumNameIfApplicable ( member , name , t , parent ) ;
321
321
if ( ! enumName && member ) {
322
322
if ( member . kind === 'method' || member . kind === 'property' ) {
323
- // this should be easy to name... let's call it the same as the argument (eternal optimist)
324
- let probableName = `${ parent . name } ${ translateMemberName ( `` , name , null ) } ` ;
325
- let probableType = additionalTypes . get ( probableName ) ;
326
- if ( probableType ) {
327
- // compare it with what?
328
- if ( probableType . expression != t . expression ) {
329
- throw new Error ( `Non-matching types with the same name. Panic.` ) ;
323
+ let names = [
324
+ parent . alias || parent . name ,
325
+ translateMemberName ( `` , member . alias || member . name , null ) ,
326
+ translateMemberName ( `` , name , null ) ,
327
+ ] ;
328
+ if ( names [ 2 ] === names [ 1 ] )
329
+ names . pop ( ) ; // get rid of duplicates, cheaply
330
+ let attemptedName = names . pop ( ) ;
331
+ let typesDiffer = function ( left , right ) {
332
+ if ( left . expression && right . expression )
333
+ return left . expression !== right . expression ;
334
+ return JSON . stringify ( right . properties ) !== JSON . stringify ( left . properties ) ;
335
+ }
336
+ while ( true ) {
337
+ // crude attempt at removing plurality
338
+ if ( attemptedName . endsWith ( 's' )
339
+ && ! [ "properties" , "httpcredentials" ] . includes ( attemptedName . toLowerCase ( ) ) )
340
+ attemptedName = attemptedName . substring ( 0 , attemptedName . length - 1 ) ;
341
+ let probableType = additionalTypes . get ( attemptedName ) ;
342
+ if ( ( probableType && typesDiffer ( t , probableType ) )
343
+ || ( [ "Value" ] . includes ( attemptedName ) ) ) {
344
+ if ( ! names . length )
345
+ throw new Error ( `Ran out of possible names: ${ attemptedName } ` ) ;
346
+ attemptedName = `${ names . pop ( ) } ${ attemptedName } ` ;
347
+ continue ;
348
+ } else {
349
+ additionalTypes . set ( attemptedName , t ) ;
330
350
}
331
- } else {
332
- additionalTypes . set ( probableName , t ) ;
351
+ break ;
333
352
}
334
-
335
- return probableName ;
353
+ return attemptedName ;
336
354
}
337
355
338
356
if ( member . kind === 'event' ) {
@@ -528,7 +546,7 @@ function renderMethod(member, parent, output, name) {
528
546
} ;
529
547
530
548
member . argsArray
531
- . sort ( ( a , b ) => b . alias === 'options' ? - 1 : 0 ) //move options to the back to the arguments list
549
+ . sort ( ( a , b ) => b . alias === 'options' ? - 1 : 0 ) //move options to the back to the arguments list
532
550
. forEach ( parseArg ) ;
533
551
534
552
output ( XmlDoc . renderXmlDoc ( member . spec , maxDocumentationColumnWidth ) ) ;
0 commit comments