Skip to content

Commit

Permalink
redirectsTarget is keyed with Path (#44278)
Browse files Browse the repository at this point in the history
* redirectsTarget is keyed with Path

* sourceFileToPackageName to keyed with Path

* feedback
  • Loading branch information
sheetalkamat committed May 26, 2021
1 parent b1eaf3e commit 32323ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/services/documentHighlights.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 32323ce

Please sign in to comment.