From 534bb62c592cb2f53c178515e9b592a710d86197 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 29 Oct 2015 16:43:12 -0700 Subject: [PATCH] remove 'path' suffix from FileMap methods --- src/compiler/core.ts | 16 ++++++++-------- src/compiler/program.ts | 14 +++++++------- src/compiler/types.ts | 8 ++++---- src/server/editorServices.ts | 28 ++++++++++++++-------------- src/services/services.ts | 14 +++++++------- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index c0e5739263e..068ab1865bb 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -20,10 +20,10 @@ namespace ts { export function createFileMap(keyMapper?: (key: string) => string): FileMap { let files: Map = {}; return { - getPath, - setPath, - containsPath, - removePath, + get, + set, + contains, + remove, forEachValue: forEachValueInMap, clear }; @@ -35,19 +35,19 @@ namespace ts { } // path should already be well-formed so it does not need to be normalized - function getPath(path: Path): T { + function get(path: Path): T { return files[toKey(path)]; } - function setPath(path: Path, value: T) { + function set(path: Path, value: T) { files[toKey(path)] = value; } - function containsPath(path: Path) { + function contains(path: Path) { return hasProperty(files, toKey(path)); } - function removePath(path: Path) { + function remove(path: Path) { const key = toKey(path); delete files[key]; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index c579f66253b..4822a86b527 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -500,7 +500,7 @@ namespace ts { // update fileName -> file mapping for (let i = 0, len = newSourceFiles.length; i < len; ++i) { - filesByName.setPath(filePaths[i], newSourceFiles[i]); + filesByName.set(filePaths[i], newSourceFiles[i]); } files = newSourceFiles; @@ -570,7 +570,7 @@ namespace ts { } function getSourceFile(fileName: string): SourceFile { - return filesByName.getPath(toPath(fileName, currentDirectory, getCanonicalFileName)); + return filesByName.get(toPath(fileName, currentDirectory, getCanonicalFileName)); } function getDiagnosticsHelper( @@ -787,8 +787,8 @@ namespace ts { // Get source file from normalized fileName function findSourceFile(fileName: string, normalizedAbsolutePath: Path, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile { - if (filesByName.containsPath(normalizedAbsolutePath)) { - const file = filesByName.getPath(normalizedAbsolutePath); + if (filesByName.contains(normalizedAbsolutePath)) { + const file = filesByName.get(normalizedAbsolutePath); // 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 if (file && options.forceConsistentCasingInFileNames && getNormalizedAbsolutePath(file.fileName, currentDirectory) !== normalizedAbsolutePath) { @@ -809,18 +809,18 @@ namespace ts { } }); - filesByName.setPath(normalizedAbsolutePath, file); + filesByName.set(normalizedAbsolutePath, file); if (file) { file.path = normalizedAbsolutePath; if (host.useCaseSensitiveFileNames()) { // for case-sensitive file systems check if we've already seen some file with similar filename ignoring case - const existingFile = filesByNameIgnoreCase.getPath(normalizedAbsolutePath); + const existingFile = filesByNameIgnoreCase.get(normalizedAbsolutePath); if (existingFile) { reportFileNamesDifferOnlyInCasingError(fileName, existingFile.fileName, refFile, refPos, refEnd); } else { - filesByNameIgnoreCase.setPath(normalizedAbsolutePath, file); + filesByNameIgnoreCase.set(normalizedAbsolutePath, file); } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1e0b8129ac4..b58e6307202 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -8,10 +8,10 @@ namespace ts { export type Path = string & { __pathBrand: any }; export interface FileMap { - getPath(fileName: Path): T; - setPath(fileName: Path, value: T): void; - containsPath(fileName: Path): boolean; - removePath(fileName: Path): void; + get(fileName: Path): T; + set(fileName: Path, value: T): void; + contains(fileName: Path): boolean; + remove(fileName: Path): void; forEachValue(f: (key: Path, v: T) => void): void; clear(): void; diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 3bc69b9a179..df3b63903c5 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -106,7 +106,7 @@ namespace ts.server { resolveModuleNames(moduleNames: string[], containingFile: string): ResolvedModule[] { let path = toPath(containingFile, this.host.getCurrentDirectory(), this.getCanonicalFileName); - let currentResolutionsInFile = this.resolvedModuleNames.getPath(path); + let currentResolutionsInFile = this.resolvedModuleNames.get(path); let newResolutions: Map = {}; let resolvedModules: ResolvedModule[] = []; @@ -135,7 +135,7 @@ namespace ts.server { } // replace old results with a new one - this.resolvedModuleNames.setPath(path, newResolutions); + this.resolvedModuleNames.set(path, newResolutions); return resolvedModules; function moduleResolutionIsValid(resolution: TimestampedResolvedModule): boolean { @@ -205,35 +205,35 @@ namespace ts.server { removeReferencedFile(info: ScriptInfo) { if (!info.isOpen) { - this.filenameToScript.removePath(info.path); - this.resolvedModuleNames.removePath(info.path); + this.filenameToScript.remove(info.path); + this.resolvedModuleNames.remove(info.path); } } getScriptInfo(filename: string): ScriptInfo { let path = toPath(filename, this.host.getCurrentDirectory(), this.getCanonicalFileName); - let scriptInfo = this.filenameToScript.getPath(path); + let scriptInfo = this.filenameToScript.get(path); if (!scriptInfo) { scriptInfo = this.project.openReferencedFile(filename); if (scriptInfo) { - this.filenameToScript.setPath(path, scriptInfo); + this.filenameToScript.set(path, scriptInfo); } } return scriptInfo; } addRoot(info: ScriptInfo) { - if (!this.filenameToScript.containsPath(info.path)) { - this.filenameToScript.setPath(info.path, info); + if (!this.filenameToScript.contains(info.path)) { + this.filenameToScript.set(info.path, info); this.roots.push(info); } } removeRoot(info: ScriptInfo) { - if (!this.filenameToScript.containsPath(info.path)) { - this.filenameToScript.removePath(info.path); + if (!this.filenameToScript.contains(info.path)) { + this.filenameToScript.remove(info.path); this.roots = copyListRemovingItem(info, this.roots); - this.resolvedModuleNames.removePath(info.path); + this.resolvedModuleNames.remove(info.path); } } @@ -283,7 +283,7 @@ namespace ts.server { */ lineToTextSpan(filename: string, line: number): ts.TextSpan { let path = toPath(filename, this.host.getCurrentDirectory(), this.getCanonicalFileName); - const script: ScriptInfo = this.filenameToScript.getPath(path); + const script: ScriptInfo = this.filenameToScript.get(path); const index = script.snap().index; const lineInfo = index.lineNumberToInfo(line + 1); @@ -304,7 +304,7 @@ namespace ts.server { */ lineOffsetToPosition(filename: string, line: number, offset: number): number { let path = toPath(filename, this.host.getCurrentDirectory(), this.getCanonicalFileName); - const script: ScriptInfo = this.filenameToScript.getPath(path); + const script: ScriptInfo = this.filenameToScript.get(path); const index = script.snap().index; const lineInfo = index.lineNumberToInfo(line); @@ -318,7 +318,7 @@ namespace ts.server { */ positionToLineOffset(filename: string, position: number): ILineInfo { let path = toPath(filename, this.host.getCurrentDirectory(), this.getCanonicalFileName); - const script: ScriptInfo = this.filenameToScript.getPath(path); + const script: ScriptInfo = this.filenameToScript.get(path); const index = script.snap().index; const lineOffset = index.charOffsetToLineNumberAndPos(position); return { line: lineOffset.line, offset: lineOffset.offset + 1 }; diff --git a/src/services/services.ts b/src/services/services.ts index 954a0a37dc9..6b7aa0ecbff 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1728,16 +1728,16 @@ namespace ts { }; } - this.fileNameToEntry.setPath(path, entry); + this.fileNameToEntry.set(path, entry); return entry; } private getEntry(path: Path): HostFileInformation { - return this.fileNameToEntry.getPath(path); + return this.fileNameToEntry.get(path); } private contains(path: Path): boolean { - return this.fileNameToEntry.containsPath(path); + return this.fileNameToEntry.contains(path); } public getOrCreateEntry(fileName: string): HostFileInformation { @@ -2053,7 +2053,7 @@ namespace ts { let bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true); let path = toPath(fileName, currentDirectory, getCanonicalFileName); - let entry = bucket.getPath(path); + let entry = bucket.get(path); if (!entry) { Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?"); @@ -2065,7 +2065,7 @@ namespace ts { languageServiceRefCount: 0, owners: [] }; - bucket.setPath(path, entry); + bucket.set(path, entry); } else { // We have an entry for this file. However, it may be for a different version of @@ -2095,12 +2095,12 @@ namespace ts { let path = toPath(fileName, currentDirectory, getCanonicalFileName); - let entry = bucket.getPath(path); + let entry = bucket.get(path); entry.languageServiceRefCount--; Debug.assert(entry.languageServiceRefCount >= 0); if (entry.languageServiceRefCount === 0) { - bucket.removePath(path); + bucket.remove(path); } }