Fix bug where findAllReferences included a node outside of sourceFilesToSearch (#22062)

This commit is contained in:
Andy 2018-03-01 13:44:53 -08:00 committed by GitHub
parent 9acad22678
commit c12369b354
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -476,6 +476,8 @@ namespace ts.FindAllReferences.Core {
*/
readonly markSeenReExportRHS = nodeSeenTracker();
private readonly includedSourceFiles: Map<true>;
constructor(
readonly sourceFiles: ReadonlyArray<SourceFile>,
/** True if we're searching for constructor references. */
@ -484,7 +486,13 @@ namespace ts.FindAllReferences.Core {
readonly cancellationToken: CancellationToken,
readonly searchMeaning: SemanticMeaning,
readonly options: Options,
private readonly result: Push<SymbolAndEntries>) {}
private readonly result: Push<SymbolAndEntries>) {
this.includedSourceFiles = arrayToSet(sourceFiles, s => s.fileName);
}
includesSourceFile(sourceFile: SourceFile): boolean {
return this.includedSourceFiles.has(sourceFile.fileName);
}
private importTracker: ImportTracker | undefined;
/** Gets every place to look for references of an exported symbols. See `ImportsResult` in `importTracker.ts` for more documentation. */
@ -586,7 +594,10 @@ namespace ts.FindAllReferences.Core {
// Go to the symbol we imported from and find references for it.
function searchForImportedSymbol(symbol: Symbol, state: State): void {
for (const declaration of symbol.declarations) {
getReferencesInSourceFile(declaration.getSourceFile(), state.createSearch(declaration, symbol, ImportExport.Import), state);
const exportingFile = declaration.getSourceFile();
if (state.includesSourceFile(exportingFile)) {
getReferencesInSourceFile(exportingFile, state.createSearch(declaration, symbol, ImportExport.Import), state);
}
}
}

View file

@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />
// @Filename: /a.ts
////export const [|x|] = 0;
// @Filename: /b.ts
////import { [|x|] } from "./a";
const [r0, r1] = test.ranges();
verify.documentHighlightsOf(r0, [r0], { filesToSearch: [r0.fileName] });
verify.documentHighlightsOf(r1, [r1], { filesToSearch: [r1.fileName] });