Prevent duplicate entries from type references

This commit is contained in:
Richard Knoll committed 2016-09-09 16:24:59 -07:00
1 parent 1cdd1d35a3
commit 2069e1cb0c
2 files changed
+15 -4

No files matched your search

+14 -3
View File
@@ -6408,20 +6408,31 @@ namespace ts {
if (containingTypeReference) {
const parent = containingTypeReference.parent;
if (isVariableLike(parent) && parent.type === containingTypeReference && parent.initializer && isImplementationExpression(parent.initializer)) {
result.push(getReferenceEntryFromNode(parent.initializer));
maybeAdd(getReferenceEntryFromNode(parent.initializer));
}
else if (isFunctionLike(parent) && parent.type === containingTypeReference && parent.body && parent.body.kind === SyntaxKind.Block) {
forEachReturnStatement(<Block>parent.body, (returnStatement) => {
if (returnStatement.expression && isImplementationExpression(returnStatement.expression)) {
result.push(getReferenceEntryFromNode(returnStatement.expression));
maybeAdd(getReferenceEntryFromNode(returnStatement.expression));
}
});
}
else if (isTypeAssertionExpression(parent) && isImplementationExpression(parent.expression)) {
result.push(getReferenceEntryFromNode(parent.expression));
maybeAdd(getReferenceEntryFromNode(parent.expression));
}
}
}
// Type nodes can contain multiple references to the same type. For example:
// let x: Foo & (Foo & Bar) = ...
// Because we are returning the implementation locations and not the identifier locations,
// duplicate entries would be returned here as each of the type references is part of
// the same implementation. For that reason, check before we add a new entry
function maybeAdd(a: ReferenceEntry) {
if (!forEach(result, b => a.fileName === b.fileName && a.textSpan.start === b.textSpan.start && a.textSpan.length === b.textSpan.length)) {
result.push(a);
}
}
}
function getSymbolsForComponentTypes(type: UnionOrIntersectionType, result: Symbol[] = []): Symbol[] {
@@ -13,7 +13,7 @@
//// let x1: Foo = [|{ hello () { /**typeReference*/ } }|];
//// let x2: () => Foo = [|(() => { hello () { /**functionType*/} })|];
//// let x3: Foo | Bar = [|{ hello () { /**unionType*/} }|];
//// let x4: Foo & Bar = [|{ hello () { /**intersectionType*/} }|];
//// let x4: Foo & (Foo & Bar) = [|{ hello () { /**intersectionType*/} }|];
//// let x5: [Foo] = [|[{ hello () { /**tupleType*/} }]|];
//// let x6: (Foo) = [|{ hello () { /**parenthesizedType*/} }|];
//// let x7: (new() => Foo) = [|class { hello () { /**constructorType*/} }|];