Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23224,10 +23224,10 @@ namespace ts {
// this variable and functions that use it are deliberately moved here from the outer scope
// to avoid scope pollution
const resolvedTypeReferenceDirectives = host.getResolvedTypeReferenceDirectives();
let fileToDirective: FileMap<string>;
let fileToDirective: Map<string>;
if (resolvedTypeReferenceDirectives) {
// populate reverse mapping: file path -> type reference directive that was resolved to this file
fileToDirective = createFileMap<string>();
fileToDirective = createMap<string>();
resolvedTypeReferenceDirectives.forEach((resolvedDirective, key) => {
if (!resolvedDirective) {
return;
Expand Down Expand Up @@ -23355,7 +23355,7 @@ namespace ts {
// check that at least one declaration of top level symbol originates from type declaration file
for (const decl of symbol.declarations) {
const file = getSourceFileOfNode(decl);
if (fileToDirective.contains(file.path)) {
if (fileToDirective.has(file.path)) {
return true;
}
}
Expand Down
14 changes: 5 additions & 9 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace ts {
};
}

export function createFileMap<T>(keyMapper?: (key: string) => string): FileMap<T> {
export function createFileMap<T>(keyMapper: (key: string) => string): FileMap<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also remove the check in toKeykeyMapper ? keyMapper(path) : path.

const files = createMap<T>();
return {
get,
Expand All @@ -169,28 +169,24 @@ namespace ts {

// path should already be well-formed so it does not need to be normalized
function get(path: Path): T {
return files.get(toKey(path));
return files.get(keyMapper(path));
}

function set(path: Path, value: T) {
files.set(toKey(path), value);
files.set(keyMapper(path), value);
}

function contains(path: Path) {
return files.has(toKey(path));
return files.has(keyMapper(path));
}

function remove(path: Path) {
files.delete(toKey(path));
files.delete(keyMapper(path));
}

function clear() {
files.clear();
}

function toKey(path: Path): string {
return keyMapper ? keyMapper(path) : path;
}
}

export function toPath(fileName: string, basePath: string, getCanonicalFileName: (path: string) => string): Path {
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/moduleNameResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ namespace ts {
}

export function createModuleResolutionCache(currentDirectory: string, getCanonicalFileName: (s: string) => string): ModuleResolutionCache {
const directoryToModuleNameMap = createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
const directoryToModuleNameMap = createMap<Map<ResolvedModuleWithFailedLookupLocations>>();
const moduleNameToDirectoryMap = createMap<PerModuleNameCache>();

return { getOrCreateCacheForDirectory, getOrCreateCacheForModuleName };
Expand Down Expand Up @@ -334,7 +334,7 @@ namespace ts {
}

function createPerModuleNameCache(): PerModuleNameCache {
const directoryPathMap = createFileMap<ResolvedModuleWithFailedLookupLocations>();
const directoryPathMap = createMap<ResolvedModuleWithFailedLookupLocations>();

return { get, set };

Expand All @@ -356,7 +356,7 @@ namespace ts {
function set(directory: string, result: ResolvedModuleWithFailedLookupLocations): void {
const path = toPath(directory, currentDirectory, getCanonicalFileName);
// if entry is already in cache do nothing
if (directoryPathMap.contains(path)) {
if (directoryPathMap.has(path)) {
return;
}
directoryPathMap.set(path, result);
Expand All @@ -370,7 +370,7 @@ namespace ts {
let current = path;
while (true) {
const parent = getDirectoryPath(current);
if (parent === current || directoryPathMap.contains(parent)) {
if (parent === current || directoryPathMap.has(parent)) {
break;
}
directoryPathMap.set(parent, result);
Expand Down
12 changes: 6 additions & 6 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ namespace ts {
}

interface DiagnosticCache {
perFile?: FileMap<Diagnostic[]>;
perFile?: Map<Diagnostic[]>;
allDiagnostics?: Diagnostic[];
}

Expand Down Expand Up @@ -472,7 +472,7 @@ namespace ts {
resolveTypeReferenceDirectiveNamesWorker = (typeReferenceDirectiveNames, containingFile) => loadWithLocalCache(typeReferenceDirectiveNames, containingFile, loader);
}

const filesByName = createFileMap<SourceFile>();
const filesByName = createMap<SourceFile>();
// stores 'filename -> file association' ignoring case
// used to track cases when two file names differ only in casing
const filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createFileMap<SourceFile>(fileName => fileName.toLowerCase()) : undefined;
Expand Down Expand Up @@ -1316,7 +1316,7 @@ namespace ts {
const result = getDiagnostics(sourceFile, cancellationToken) || emptyArray;
if (sourceFile) {
if (!cache.perFile) {
cache.perFile = createFileMap<Diagnostic[]>();
cache.perFile = createMap<Diagnostic[]>();
}
cache.perFile.set(sourceFile.path, result);
}
Expand Down Expand Up @@ -1533,7 +1533,7 @@ namespace ts {

// Get source file from normalized fileName
function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
if (filesByName.contains(path)) {
if (filesByName.has(path)) {
const file = filesByName.get(path);
// try to check if we've already seen this file but with a different casing in path
// NOTE: this only makes sense for case-insensitive file systems
Expand Down Expand Up @@ -1953,7 +1953,7 @@ namespace ts {
// If the emit is enabled make sure that every output file is unique and not overwriting any of the input files
if (!options.noEmit && !options.suppressOutputPathCheck) {
const emitHost = getEmitHost();
const emitFilesSeen = createFileMap<boolean>(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : undefined);
const emitFilesSeen = createFileMap<boolean>(!host.useCaseSensitiveFileNames() ? key => key.toLocaleLowerCase() : key => key);
forEachEmittedFile(emitHost, (emitFileNames) => {
verifyEmitFilePath(emitFileNames.jsFilePath, emitFilesSeen);
verifyEmitFilePath(emitFileNames.declarationFilePath, emitFilesSeen);
Expand All @@ -1965,7 +1965,7 @@ namespace ts {
if (emitFileName) {
const emitFilePath = toPath(emitFileName, currentDirectory, getCanonicalFileName);
// Report error if the output overwrites input file
if (filesByName.contains(emitFilePath)) {
if (filesByName.has(emitFilePath)) {
let chain: DiagnosticMessageChain;
if (!options.configFilePath) {
// The program is from either an inferred project or an external project
Expand Down
12 changes: 6 additions & 6 deletions src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,13 @@ namespace Harness {
const getCanonicalFileName = ts.createGetCanonicalFileName(useCaseSensitiveFileNames);

/** Maps a symlink name to a realpath. Used only for exposing `realpath`. */
const realPathMap = ts.createFileMap<string>();
const realPathMap = ts.createMap<string>();
/**
* Maps a file name to a source file.
* This will have a different SourceFile for every symlink pointing to that file;
* if the program resolves realpaths then symlink entries will be ignored.
*/
const fileMap = ts.createFileMap<ts.SourceFile>();
const fileMap = ts.createMap<ts.SourceFile>();
for (const file of inputFiles) {
if (file.content !== undefined) {
const fileName = ts.normalizePath(file.unitName);
Expand Down Expand Up @@ -975,7 +975,7 @@ namespace Harness {
getCanonicalFileName,
useCaseSensitiveFileNames: () => useCaseSensitiveFileNames,
getNewLine: () => newLine,
fileExists: fileName => fileMap.contains(toPath(fileName)),
fileExists: fileName => fileMap.has(toPath(fileName)),
readFile: (fileName: string): string => {
const file = fileMap.get(toPath(fileName));
if (ts.endsWith(fileName, "json")) {
Expand All @@ -999,7 +999,7 @@ namespace Harness {
getDirectories: d => {
const path = ts.toPath(d, currentDirectory, getCanonicalFileName);
const result: string[] = [];
fileMap.forEachValue(key => {
ts.forEachKey(fileMap, key => {
if (key.indexOf(path) === 0 && key.lastIndexOf("/") > path.length) {
let dirName = key.substr(path.length, key.indexOf("/", path.length + 1) - path.length);
if (dirName[0] === "/") {
Expand All @@ -1015,12 +1015,12 @@ namespace Harness {
};
}

function mapHasFileInDirectory(directoryPath: ts.Path, map: ts.FileMap<any>): boolean {
function mapHasFileInDirectory(directoryPath: ts.Path, map: ts.Map<{}>): boolean {
if (!map) {
return false;
}
let exists = false;
map.forEachValue(fileName => {
ts.forEachKey(map, fileName => {
if (!exists && ts.startsWith(fileName, directoryPath) && fileName[directoryPath.length] === "/") {
exists = true;
}
Expand Down
16 changes: 8 additions & 8 deletions src/harness/unittests/tsserverProjectSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ namespace ts.projectSystem {
return typeof (<File>s).content === "string";
}

export function addFolder(fullPath: string, toPath: (s: string) => Path, fs: FileMap<FSEntry>): Folder {
export function addFolder(fullPath: string, toPath: (s: string) => Path, fs: Map<FSEntry>): Folder {
const path = toPath(fullPath);
if (fs.contains(path)) {
if (fs.has(path)) {
Debug.assert(isFolder(fs.get(path)));
return (<Folder>fs.get(path));
}
Expand Down Expand Up @@ -370,7 +370,7 @@ namespace ts.projectSystem {

private readonly output: string[] = [];

private fs: ts.FileMap<FSEntry>;
private fs: Map<FSEntry>;
private getCanonicalFileName: (s: string) => string;
private toPath: (f: string) => Path;
private timeoutCallbacks = new Callbacks();
Expand All @@ -390,7 +390,7 @@ namespace ts.projectSystem {

reloadFS(filesOrFolders: FileOrFolder[]) {
this.filesOrFolders = filesOrFolders;
this.fs = createFileMap<FSEntry>();
this.fs = createMap<FSEntry>();
// always inject safelist file in the list of files
for (const fileOrFolder of filesOrFolders.concat(safeList)) {
const path = this.toPath(fileOrFolder.path);
Expand All @@ -408,12 +408,12 @@ namespace ts.projectSystem {

fileExists(s: string) {
const path = this.toPath(s);
return this.fs.contains(path) && isFile(this.fs.get(path));
return this.fs.has(path) && isFile(this.fs.get(path));
}

getFileSize(s: string) {
const path = this.toPath(s);
if (this.fs.contains(path)) {
if (this.fs.has(path)) {
const entry = this.fs.get(path);
if (isFile(entry)) {
return entry.fileSize ? entry.fileSize : entry.content.length;
Expand All @@ -424,12 +424,12 @@ namespace ts.projectSystem {

directoryExists(s: string) {
const path = this.toPath(s);
return this.fs.contains(path) && isFolder(this.fs.get(path));
return this.fs.has(path) && isFolder(this.fs.get(path));
}

getDirectories(s: string) {
const path = this.toPath(s);
if (!this.fs.contains(path)) {
if (!this.fs.has(path)) {
return [];
}
else {
Expand Down
10 changes: 5 additions & 5 deletions src/server/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ namespace ts.server {
* NOTE: this field is created on demand and should not be accessed directly.
* Use 'getFileInfos' instead.
*/
private fileInfos_doNotAccessDirectly: FileMap<T>;
private fileInfos_doNotAccessDirectly: Map<T>;

constructor(public readonly project: Project, private ctor: { new (scriptInfo: ScriptInfo, project: Project): T }) {
}

private getFileInfos() {
return this.fileInfos_doNotAccessDirectly || (this.fileInfos_doNotAccessDirectly = createFileMap<T>());
return this.fileInfos_doNotAccessDirectly || (this.fileInfos_doNotAccessDirectly = createMap<T>());
}

protected hasFileInfos() {
Expand All @@ -117,19 +117,19 @@ namespace ts.server {
}

protected getFileInfoPaths(): Path[] {
return this.getFileInfos().getKeys();
return arrayFrom(this.getFileInfos().keys() as Iterator<Path>);
}

protected setFileInfo(path: Path, info: T) {
this.getFileInfos().set(path, info);
}

protected removeFileInfo(path: Path) {
this.getFileInfos().remove(path);
this.getFileInfos().delete(path);
}

protected forEachFileInfo(action: (fileInfo: T) => any) {
this.getFileInfos().forEachValue((_path, value) => action(value));
this.getFileInfos().forEach(action);
}

abstract getFilesAffectedBy(scriptInfo: ScriptInfo): string[];
Expand Down
13 changes: 6 additions & 7 deletions src/server/editorServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ namespace ts.server {
/**
* Container of all known scripts
*/
private readonly filenameToScriptInfo = createFileMap<ScriptInfo>();
private readonly filenameToScriptInfo = createMap<ScriptInfo>();
/**
* maps external project file name to list of config files that were the part of this project
*/
Expand Down Expand Up @@ -568,7 +568,7 @@ namespace ts.server {
if (info.containingProjects.length === 0) {
// Orphan script info, remove it as we can always reload it on next open
info.stopWatcher();
this.filenameToScriptInfo.remove(info.path);
this.filenameToScriptInfo.delete(info.path);
}
else {
// file has been changed which might affect the set of referenced files in projects that include
Expand All @@ -588,7 +588,7 @@ namespace ts.server {
// TODO: handle isOpen = true case

if (!info.isScriptOpen()) {
this.filenameToScriptInfo.remove(info.path);
this.filenameToScriptInfo.delete(info.path);
this.lastDeletedFile = info;

// capture list of projects since detachAllProjects will wipe out original list
Expand Down Expand Up @@ -852,14 +852,13 @@ namespace ts.server {
}

private deleteOrphanScriptInfoNotInAnyProject() {
for (const path of this.filenameToScriptInfo.getKeys()) {
const info = this.filenameToScriptInfo.get(path);
this.filenameToScriptInfo.forEach(info => {
if (!info.isScriptOpen() && info.containingProjects.length === 0) {
// if there are not projects that include this script info - delete it
info.stopWatcher();
this.filenameToScriptInfo.remove(info.path);
this.filenameToScriptInfo.delete(info.path);
}
}
});
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/server/lsHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace ts.server {
export class LSHost implements ts.LanguageServiceHost, ModuleResolutionHost {
private compilationSettings: ts.CompilerOptions;
private readonly resolvedModuleNames = createFileMap<Map<ResolvedModuleWithFailedLookupLocations>>();
private readonly resolvedTypeReferenceDirectives = createFileMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>();
private readonly resolvedModuleNames = createMap<Map<ResolvedModuleWithFailedLookupLocations>>();
private readonly resolvedTypeReferenceDirectives = createMap<Map<ResolvedTypeReferenceDirectiveWithFailedLookupLocations>>();
private readonly getCanonicalFileName: (fileName: string) => string;

private filesWithChangedSetOfUnresolvedImports: Path[];
Expand Down Expand Up @@ -65,7 +65,7 @@ namespace ts.server {
private resolveNamesWithLocalCache<T extends { failedLookupLocations: string[] }, R>(
names: string[],
containingFile: string,
cache: ts.FileMap<Map<T>>,
cache: Map<Map<T>>,
loader: (name: string, containingFile: string, options: CompilerOptions, host: ModuleResolutionHost) => T,
getResult: (s: T) => R,
getResultFileName: (result: R) => string | undefined,
Expand Down Expand Up @@ -231,8 +231,8 @@ namespace ts.server {
}

notifyFileRemoved(info: ScriptInfo) {
this.resolvedModuleNames.remove(info.path);
this.resolvedTypeReferenceDirectives.remove(info.path);
this.resolvedModuleNames.delete(info.path);
this.resolvedTypeReferenceDirectives.delete(info.path);
}

setCompilationSettings(opt: ts.CompilerOptions) {
Expand Down
Loading