@@ -4143,50 +4143,6 @@ module ts {
4143
4143
return isCorrect ;
4144
4144
}
4145
4145
4146
- // The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
4147
- // A nit here is that we reorder only signatures that belong to the same symbol,
4148
- // so order how inherited signatures are processed is still preserved.
4149
- // interface A { (x: string): void }
4150
- // interface B extends A { (x: 'foo'): string }
4151
- // var b: B;
4152
- // b('foo') // <- here overloads should be processed as [(x:'foo'): string, (x: string): void]
4153
- function collectCandidates ( node : CallExpression , signatures : Signature [ ] , candidatesOutArray : Signature [ ] ) : Signature [ ] {
4154
- var result : Signature [ ] = candidatesOutArray || [ ] ;
4155
- var lastParent : Node ;
4156
- var lastSymbol : Symbol ;
4157
- var cutoffPos : number = 0 ;
4158
- var pos : number ;
4159
- for ( var i = 0 ; i < signatures . length ; i ++ ) {
4160
- var signature = signatures [ i ] ;
4161
- if ( true ) {
4162
- var symbol = signature . declaration && getSymbolOfNode ( signature . declaration ) ;
4163
- var parent = signature . declaration && signature . declaration . parent ;
4164
- if ( ! lastSymbol || symbol === lastSymbol ) {
4165
- if ( lastParent && parent === lastParent ) {
4166
- pos ++ ;
4167
- }
4168
- else {
4169
- lastParent = parent ;
4170
- pos = cutoffPos ;
4171
- }
4172
- }
4173
- else {
4174
- // current declaration belongs to a different symbol
4175
- // set cutoffPos so re-orderings in the future won't change result set from 0 to cutoffPos
4176
- pos = cutoffPos = result . length ;
4177
- lastParent = parent ;
4178
- }
4179
- lastSymbol = symbol ;
4180
-
4181
- for ( var j = result . length ; j > pos ; j -- ) {
4182
- result [ j ] = result [ j - 1 ] ;
4183
- }
4184
- result [ pos ] = signature ;
4185
- }
4186
- }
4187
- return result ;
4188
- }
4189
-
4190
4146
// If type has a single call signature and no other members, return that signature. Otherwise, return undefined.
4191
4147
function getSingleCallSignature ( type : Type ) : Signature {
4192
4148
if ( type . flags & TypeFlags . ObjectType ) {
@@ -4280,7 +4236,9 @@ module ts {
4280
4236
4281
4237
function resolveCall ( node : CallExpression , signatures : Signature [ ] , candidatesOutArray : Signature [ ] ) : Signature {
4282
4238
forEach ( node . typeArguments , checkSourceElement ) ;
4283
- var candidates = collectCandidates ( node , signatures , candidatesOutArray ) ;
4239
+ var candidates = candidatesOutArray || [ ] ;
4240
+ // collectCandidates fills up the candidates array directly
4241
+ collectCandidates ( ) ;
4284
4242
if ( ! candidates . length ) {
4285
4243
error ( node , Diagnostics . Supplied_parameters_do_not_match_any_signature_of_call_target ) ;
4286
4244
return resolveErrorCall ( node ) ;
@@ -4336,6 +4294,50 @@ module ts {
4336
4294
return resolveErrorCall ( node ) ;
4337
4295
}
4338
4296
return resolveErrorCall ( node ) ;
4297
+
4298
+ // The candidate list orders groups in reverse, but within a group signatures are kept in declaration order
4299
+ // A nit here is that we reorder only signatures that belong to the same symbol,
4300
+ // so order how inherited signatures are processed is still preserved.
4301
+ // interface A { (x: string): void }
4302
+ // interface B extends A { (x: 'foo'): string }
4303
+ // var b: B;
4304
+ // b('foo') // <- here overloads should be processed as [(x:'foo'): string, (x: string): void]
4305
+ function collectCandidates ( ) : void {
4306
+ var result = candidates ;
4307
+ var lastParent : Node ;
4308
+ var lastSymbol : Symbol ;
4309
+ var cutoffPos : number = 0 ;
4310
+ var pos : number ;
4311
+ Debug . assert ( ! result . length ) ;
4312
+ for ( var i = 0 ; i < signatures . length ; i ++ ) {
4313
+ var signature = signatures [ i ] ;
4314
+ if ( true ) {
4315
+ var symbol = signature . declaration && getSymbolOfNode ( signature . declaration ) ;
4316
+ var parent = signature . declaration && signature . declaration . parent ;
4317
+ if ( ! lastSymbol || symbol === lastSymbol ) {
4318
+ if ( lastParent && parent === lastParent ) {
4319
+ pos ++ ;
4320
+ }
4321
+ else {
4322
+ lastParent = parent ;
4323
+ pos = cutoffPos ;
4324
+ }
4325
+ }
4326
+ else {
4327
+ // current declaration belongs to a different symbol
4328
+ // set cutoffPos so re-orderings in the future won't change result set from 0 to cutoffPos
4329
+ pos = cutoffPos = result . length ;
4330
+ lastParent = parent ;
4331
+ }
4332
+ lastSymbol = symbol ;
4333
+
4334
+ for ( var j = result . length ; j > pos ; j -- ) {
4335
+ result [ j ] = result [ j - 1 ] ;
4336
+ }
4337
+ result [ pos ] = signature ;
4338
+ }
4339
+ }
4340
+ }
4339
4341
}
4340
4342
4341
4343
function resolveCallExpression ( node : CallExpression , candidatesOutArray : Signature [ ] ) : Signature {
0 commit comments