@@ -6408,20 +6408,31 @@ namespace ts {
6408
6408
if ( containingTypeReference ) {
6409
6409
const parent = containingTypeReference . parent ;
6410
6410
if ( isVariableLike ( parent ) && parent . type === containingTypeReference && parent . initializer && isImplementationExpression ( parent . initializer ) ) {
6411
- result . push ( getReferenceEntryFromNode ( parent . initializer ) ) ;
6411
+ maybeAdd ( getReferenceEntryFromNode ( parent . initializer ) ) ;
6412
6412
}
6413
6413
else if ( isFunctionLike ( parent ) && parent . type === containingTypeReference && parent . body && parent . body . kind === SyntaxKind . Block ) {
6414
6414
forEachReturnStatement ( < Block > parent . body , ( returnStatement ) => {
6415
6415
if ( returnStatement . expression && isImplementationExpression ( returnStatement . expression ) ) {
6416
- result . push ( getReferenceEntryFromNode ( returnStatement . expression ) ) ;
6416
+ maybeAdd ( getReferenceEntryFromNode ( returnStatement . expression ) ) ;
6417
6417
}
6418
6418
} ) ;
6419
6419
}
6420
6420
else if ( isTypeAssertionExpression ( parent ) && isImplementationExpression ( parent . expression ) ) {
6421
- result . push ( getReferenceEntryFromNode ( parent . expression ) ) ;
6421
+ maybeAdd ( getReferenceEntryFromNode ( parent . expression ) ) ;
6422
6422
}
6423
6423
}
6424
6424
}
6425
+
6426
+ // Type nodes can contain multiple references to the same type. For example:
6427
+ // let x: Foo & (Foo & Bar) = ...
6428
+ // Because we are returning the implementation locations and not the identifier locations,
6429
+ // duplicate entries would be returned here as each of the type references is part of
6430
+ // the same implementation. For that reason, check before we add a new entry
6431
+ function maybeAdd ( a : ReferenceEntry ) {
6432
+ if ( ! forEach ( result , b => a . fileName === b . fileName && a . textSpan . start === b . textSpan . start && a . textSpan . length === b . textSpan . length ) ) {
6433
+ result . push ( a ) ;
6434
+ }
6435
+ }
6425
6436
}
6426
6437
6427
6438
function getSymbolsForComponentTypes ( type : UnionOrIntersectionType , result : Symbol [ ] = [ ] ) : Symbol [ ] {
0 commit comments