@@ -504,28 +504,31 @@ module ts {
504
504
if ( ! this . namedDeclarations ) {
505
505
var sourceFile = this ;
506
506
var namedDeclarations : Declaration [ ] = [ ] ;
507
-
508
- // This keeps track of the last encountered function/method/method signature
509
- // so that we may ignore all but the first overload.
510
- var overloadDeclaration : FunctionDeclaration ;
511
507
512
- forEachChild ( sourceFile , function visit ( node : Node ) : boolean {
508
+ forEachChild ( sourceFile , function visit ( node : Node ) : void {
513
509
switch ( node . kind ) {
514
510
case SyntaxKind . FunctionDeclaration :
515
511
case SyntaxKind . Method :
516
512
var functionDeclaration = < FunctionDeclaration > node ;
517
513
518
- // We can assume that overloadDeclaration will never be "trampled"
519
- // between consecutive overloads because we never dive into parameter initializers.
520
- if ( functionDeclaration . name ) {
521
- if ( overloadDeclaration &&
522
- functionDeclaration . name . text === overloadDeclaration . name . text &&
523
- node . parent === overloadDeclaration . parent ) {
524
- break ;
514
+ if ( functionDeclaration . name && functionDeclaration . name . kind !== SyntaxKind . Missing ) {
515
+ var lastDeclaration = namedDeclarations . length > 0 ?
516
+ namedDeclarations [ namedDeclarations . length - 1 ] :
517
+ undefined ;
518
+
519
+ // Check whether this declaration belongs to an "overload group".
520
+ if ( lastDeclaration && functionDeclaration . symbol === lastDeclaration . symbol ) {
521
+ // Overwrite the last declaration if it was an overload
522
+ // and this one is an implementation.
523
+ if ( functionDeclaration . body && ! ( < FunctionDeclaration > lastDeclaration ) . body ) {
524
+ namedDeclarations [ namedDeclarations . length - 1 ] = functionDeclaration ;
525
+ }
526
+ }
527
+ else {
528
+ namedDeclarations . push ( node ) ;
525
529
}
526
530
527
- namedDeclarations . push ( functionDeclaration ) ;
528
- overloadDeclaration = functionDeclaration ;
531
+ forEachChild ( node , visit ) ;
529
532
}
530
533
break ;
531
534
@@ -534,14 +537,14 @@ module ts {
534
537
case SyntaxKind . EnumDeclaration :
535
538
case SyntaxKind . ModuleDeclaration :
536
539
case SyntaxKind . ImportDeclaration :
537
- case SyntaxKind . Constructor :
538
540
case SyntaxKind . GetAccessor :
539
541
case SyntaxKind . SetAccessor :
540
542
case SyntaxKind . TypeLiteral :
541
543
if ( ( < Declaration > node ) . name ) {
542
544
namedDeclarations . push ( < Declaration > node ) ;
543
545
}
544
546
// fall through
547
+ case SyntaxKind . Constructor :
545
548
case SyntaxKind . VariableStatement :
546
549
case SyntaxKind . ModuleBlock :
547
550
case SyntaxKind . FunctionBlock :
@@ -560,9 +563,6 @@ module ts {
560
563
namedDeclarations . push ( < Declaration > node ) ;
561
564
break ;
562
565
}
563
-
564
- // do not go any deeper
565
- return undefined ;
566
566
} ) ;
567
567
568
568
this . namedDeclarations = namedDeclarations ;
0 commit comments