Skip to content

Commit 5bf9b30

Browse files
author
Andy Hanson
committed
Replace isSearchedFor with directly passing searchSymbols
1 parent 50442b5 commit 5bf9b30

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/services/findAllReferences.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ namespace ts.FindAllReferences {
4141
if (shorthandModuleSymbol) {
4242
searchSymbols.push(shorthandModuleSymbol);
4343
}
44-
function isSearchedFor(symbol: Symbol): boolean {
45-
return contains(searchSymbols, symbol);
46-
}
4744

4845
// Compute the meaning from the location and the symbol it references
4946
const searchMeaning = getIntersectingMeaningFromDeclarations(getMeaningFromLocation(node), declarations);
@@ -80,7 +77,7 @@ namespace ts.FindAllReferences {
8077

8178
function getRefs(scope: ts.Node, searchName: string): void {
8279
getReferencesInNode(scope, symbol, searchName, node, searchMeaning, findInStrings, findInComments, result,
83-
symbolToIndex, implementations, typeChecker, cancellationToken, isSearchedFor, inheritsFromCache);
80+
symbolToIndex, implementations, typeChecker, cancellationToken, searchSymbols, inheritsFromCache);
8481
}
8582
}
8683

@@ -456,7 +453,7 @@ namespace ts.FindAllReferences {
456453
implementations: boolean,
457454
typeChecker: TypeChecker,
458455
cancellationToken: CancellationToken,
459-
isSearchedFor: (symbol: Symbol) => boolean,
456+
searchSymbols: Symbol[],
460457
inheritsFromCache: Map<boolean>): void {
461458

462459
const sourceFile = container.getSourceFile();
@@ -502,7 +499,7 @@ namespace ts.FindAllReferences {
502499
if (referenceSymbol) {
503500
const referenceSymbolDeclaration = referenceSymbol.valueDeclaration;
504501
const shorthandValueSymbol = typeChecker.getShorthandAssignmentValueSymbol(referenceSymbolDeclaration);
505-
const relatedSymbol = getRelatedSymbol(isSearchedFor, referenceSymbol, referenceLocation,
502+
const relatedSymbol = getRelatedSymbol(searchSymbols, referenceSymbol, referenceLocation,
506503
/*searchLocationIsConstructor*/ searchLocation.kind === SyntaxKind.ConstructorKeyword, parents, inheritsFromCache, typeChecker);
507504

508505
if (relatedSymbol) {
@@ -514,7 +511,7 @@ namespace ts.FindAllReferences {
514511
* the position in short-hand property assignment excluding property accessing. However, if we do findAllReference at the
515512
* position of property accessing, the referenceEntry of such position will be handled in the first case.
516513
*/
517-
else if (!(referenceSymbol.flags & SymbolFlags.Transient) && isSearchedFor(shorthandValueSymbol)) {
514+
else if (!(referenceSymbol.flags & SymbolFlags.Transient) && contains(searchSymbols, shorthandValueSymbol)) {
518515
addReferenceToRelatedSymbol(referenceSymbolDeclaration.name, shorthandValueSymbol);
519516
}
520517
else if (searchLocation.kind === SyntaxKind.ConstructorKeyword) {
@@ -1178,8 +1175,8 @@ namespace ts.FindAllReferences {
11781175
}
11791176
}
11801177

1181-
function getRelatedSymbol(isSearchedFor: (symbol: Symbol) => boolean, referenceSymbol: Symbol, referenceLocation: Node, searchLocationIsConstructor: boolean, parents: Symbol[] | undefined, cache: Map<boolean>, typeChecker: TypeChecker): Symbol | undefined {
1182-
if (isSearchedFor(referenceSymbol)) {
1178+
function getRelatedSymbol(searchSymbols: Symbol[], referenceSymbol: Symbol, referenceLocation: Node, searchLocationIsConstructor: boolean, parents: Symbol[] | undefined, cache: Map<boolean>, typeChecker: TypeChecker): Symbol | undefined {
1179+
if (contains(searchSymbols, referenceSymbol)) {
11831180
// If we are searching for constructor uses, they must be 'new' expressions.
11841181
return (!searchLocationIsConstructor || isNewExpressionTarget(referenceLocation)) ? referenceSymbol : undefined;
11851182
}
@@ -1188,7 +1185,7 @@ namespace ts.FindAllReferences {
11881185
// symbols but by looking up for related symbol of this alias so it can handle multiple level of indirectness.
11891186
const aliasSymbol = getAliasSymbolForPropertyNameSymbol(referenceSymbol, referenceLocation, typeChecker);
11901187
if (aliasSymbol) {
1191-
return getRelatedSymbol(isSearchedFor, aliasSymbol, referenceLocation, searchLocationIsConstructor, parents, cache, typeChecker);
1188+
return getRelatedSymbol(searchSymbols, aliasSymbol, referenceLocation, searchLocationIsConstructor, parents, cache, typeChecker);
11921189
}
11931190

11941191
// If the reference location is in an object literal, try to get the contextual type for the
@@ -1197,7 +1194,7 @@ namespace ts.FindAllReferences {
11971194
const containingObjectLiteralElement = getContainingObjectLiteralElement(referenceLocation);
11981195
if (containingObjectLiteralElement) {
11991196
const contextualSymbol = forEach(getPropertySymbolsFromContextualType(containingObjectLiteralElement, typeChecker), contextualSymbol =>
1200-
find(typeChecker.getRootSymbols(contextualSymbol), isSearchedFor));
1197+
find(typeChecker.getRootSymbols(contextualSymbol), symbol => contains(searchSymbols, symbol)));
12011198

12021199
if (contextualSymbol) {
12031200
return contextualSymbol;
@@ -1208,7 +1205,7 @@ namespace ts.FindAllReferences {
12081205
// In below eg. get 'property' from type of elems iterating type
12091206
// for ( { property: p2 } of elems) { }
12101207
const propertySymbol = getPropertySymbolOfDestructuringAssignment(referenceLocation, typeChecker);
1211-
if (propertySymbol && isSearchedFor(propertySymbol)) {
1208+
if (propertySymbol && contains(searchSymbols, propertySymbol)) {
12121209
return propertySymbol;
12131210
}
12141211
}
@@ -1217,15 +1214,15 @@ namespace ts.FindAllReferences {
12171214
// then include the binding element in the related symbols
12181215
// let { a } : { a };
12191216
const bindingElementPropertySymbol = getPropertySymbolOfObjectBindingPatternWithoutPropertyName(referenceSymbol, typeChecker);
1220-
if (bindingElementPropertySymbol && isSearchedFor(bindingElementPropertySymbol)) {
1217+
if (bindingElementPropertySymbol && contains(searchSymbols, bindingElementPropertySymbol)) {
12211218
return bindingElementPropertySymbol;
12221219
}
12231220

12241221
// Unwrap symbols to get to the root (e.g. transient symbols as a result of widening)
12251222
// Or a union property, use its underlying unioned symbols
12261223
return forEach(typeChecker.getRootSymbols(referenceSymbol), rootSymbol => {
12271224
// if it is in the list, then we are done
1228-
if (isSearchedFor(rootSymbol)) {
1225+
if (contains(searchSymbols, rootSymbol)) {
12291226
return rootSymbol;
12301227
}
12311228

@@ -1242,7 +1239,7 @@ namespace ts.FindAllReferences {
12421239

12431240
const result: Symbol[] = [];
12441241
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result, /*previousIterationSymbolsCache*/ createMap<Symbol>(), typeChecker);
1245-
return find(result, isSearchedFor);
1242+
return find(result, symbol => contains(searchSymbols, symbol));
12461243
}
12471244

12481245
return undefined;

0 commit comments

Comments
 (0)