redirectsTarget is keyed with Path (#44278)

* redirectsTarget is keyed with Path

* sourceFileToPackageName to keyed with Path

* feedback
This commit is contained in:
Sheetal Nandi
2021-05-26 16:50:14 -07:00
committed by GitHub
parent b1eaf3e170
commit 32323ce7fb
3 changed files with 7 additions and 6 deletions

View File

@@ -883,9 +883,9 @@ namespace ts {
// `packageIdToSourceFile` is only used while building the program, while `sourceFileToPackageName` and `isSourceFileTargetOfRedirect` are kept around.
const packageIdToSourceFile = new Map<string, SourceFile>();
// Maps from a SourceFile's `.path` to the name of the package it was imported with.
let sourceFileToPackageName = new Map<string, string>();
let sourceFileToPackageName = new Map<Path, string>();
// Key is a file name. Value is the (non-empty, or undefined) list of files that redirect to it.
let redirectTargetsMap = createMultiMap<string>();
let redirectTargetsMap = createMultiMap<Path, string>();
/**
* map with

View File

@@ -3944,9 +3944,9 @@ namespace ts {
/* @internal */ getLibFileFromReference(ref: FileReference): SourceFile | undefined;
/** Given a source file, get the name of the package it was imported from. */
/* @internal */ sourceFileToPackageName: ESMap<string, string>;
/* @internal */ sourceFileToPackageName: ESMap<Path, string>;
/** Set of all source files that some other source file redirects to. */
/* @internal */ redirectTargetsMap: MultiMap<string, string>;
/* @internal */ redirectTargetsMap: MultiMap<Path, string>;
/** Is the file emitted file */
/* @internal */ isEmittedFile(file: string): boolean;
/* @internal */ getFileIncludeReasons(): MultiMap<Path, FileIncludeReason>;
@@ -3974,7 +3974,7 @@ namespace ts {
}
/* @internal */
export type RedirectTargetsMap = ReadonlyESMap<string, readonly string[]>;
export type RedirectTargetsMap = ReadonlyESMap<Path, readonly string[]>;
export interface ResolvedProjectReference {
commandLine: ParsedCommandLine;

View File

@@ -32,9 +32,10 @@ namespace ts {
const referenceEntries = FindAllReferences.getReferenceEntriesForNode(position, node, program, sourceFilesToSearch, cancellationToken, /*options*/ undefined, sourceFilesSet);
if (!referenceEntries) return undefined;
const map = arrayToMultiMap(referenceEntries.map(FindAllReferences.toHighlightSpan), e => e.fileName, e => e.span);
const getCanonicalFileName = createGetCanonicalFileName(program.useCaseSensitiveFileNames());
return mapDefined(arrayFrom(map.entries()), ([fileName, highlightSpans]) => {
if (!sourceFilesSet.has(fileName)) {
if (!program.redirectTargetsMap.has(fileName)) {
if (!program.redirectTargetsMap.has(toPath(fileName, program.getCurrentDirectory(), getCanonicalFileName))) {
return undefined;
}
const redirectTarget = program.getSourceFile(fileName);