mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-12 12:57:11 -06:00
address PR feedback
This commit is contained in:
parent
25c093673c
commit
b4f1df2afa
@ -15,35 +15,39 @@ module ts {
|
||||
True = -1
|
||||
}
|
||||
|
||||
export class FileMap<T> {
|
||||
private files: Map<T> = {};
|
||||
|
||||
constructor(private getCanonicalFileName: (fileName: string) => string) {
|
||||
export function createFileMap<T>(getCanonicalFileName: (fileName: string) => string): FileMap<T> {
|
||||
let files: Map<T> = {};
|
||||
return {
|
||||
get,
|
||||
set,
|
||||
contains,
|
||||
delete: deleteItem,
|
||||
forEachValue: forEachValueInMap
|
||||
}
|
||||
|
||||
public set(fileName: string, value: T) {
|
||||
this.files[this.normalizeKey(fileName)] = value;
|
||||
function set(fileName: string, value: T) {
|
||||
files[normalizeKey(fileName)] = value;
|
||||
}
|
||||
|
||||
public get(fileName: string) {
|
||||
return this.files[this.normalizeKey(fileName)];
|
||||
function get(fileName: string) {
|
||||
return files[normalizeKey(fileName)];
|
||||
}
|
||||
|
||||
public contains(fileName: string) {
|
||||
return hasProperty(this.files, this.normalizeKey(fileName));
|
||||
function contains(fileName: string) {
|
||||
return hasProperty(files, normalizeKey(fileName));
|
||||
}
|
||||
|
||||
public delete(fileName: string) {
|
||||
let key = this.normalizeKey(fileName);
|
||||
delete this.files[key];
|
||||
function deleteItem (fileName: string) {
|
||||
let key = normalizeKey(fileName);
|
||||
delete files[key];
|
||||
}
|
||||
|
||||
public forEachValue(f: (value: T) => void) {
|
||||
forEachValue(this.files, f);
|
||||
function forEachValueInMap(f: (value: T) => void) {
|
||||
forEachValue(files, f);
|
||||
}
|
||||
|
||||
private normalizeKey(key: string) {
|
||||
return this.getCanonicalFileName(normalizeSlashes(key));
|
||||
function normalizeKey(key: string) {
|
||||
return getCanonicalFileName(normalizeSlashes(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -152,7 +152,7 @@ module ts {
|
||||
let start = new Date().getTime();
|
||||
|
||||
host = host || createCompilerHost(options);
|
||||
let filesByName: FileMap<SourceFile> = new FileMap<SourceFile>(host.getCanonicalFileName);
|
||||
let filesByName = createFileMap<SourceFile>(host.getCanonicalFileName);
|
||||
|
||||
forEach(rootNames, name => processRootFile(name, false));
|
||||
if (!seenNoDefaultLib) {
|
||||
|
||||
@ -3,6 +3,14 @@ module ts {
|
||||
[index: string]: T;
|
||||
}
|
||||
|
||||
export interface FileMap<T> {
|
||||
get(fileName: string): T;
|
||||
set(fileName: string, value: T): void;
|
||||
contains(fileName: string): boolean;
|
||||
delete(fileName: string): void;
|
||||
forEachValue(f: (v: T) => void): void;
|
||||
}
|
||||
|
||||
export interface TextRange {
|
||||
pos: number;
|
||||
end: number;
|
||||
|
||||
@ -1636,7 +1636,7 @@ module ts {
|
||||
|
||||
constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) {
|
||||
// script id => script index
|
||||
this.fileNameToEntry = new FileMap<HostFileInformation>(getCanonicalFileName);
|
||||
this.fileNameToEntry = createFileMap<HostFileInformation>(getCanonicalFileName);
|
||||
|
||||
// Initialize the list with the root file names
|
||||
let rootFileNames = host.getScriptFileNames();
|
||||
@ -1893,7 +1893,7 @@ module ts {
|
||||
// Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have
|
||||
// for those settings.
|
||||
let buckets: Map<FileMap<DocumentRegistryEntry>> = {};
|
||||
let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames || false);
|
||||
let getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames);
|
||||
|
||||
function getKeyFromCompilationSettings(settings: CompilerOptions): string {
|
||||
return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString()
|
||||
@ -1903,7 +1903,7 @@ module ts {
|
||||
let key = getKeyFromCompilationSettings(settings);
|
||||
let bucket = lookUp(buckets, key);
|
||||
if (!bucket && createIfMissing) {
|
||||
buckets[key] = bucket = new FileMap<DocumentRegistryEntry>(getCanonicalFileName);
|
||||
buckets[key] = bucket = createFileMap<DocumentRegistryEntry>(getCanonicalFileName);
|
||||
}
|
||||
return bucket;
|
||||
}
|
||||
|
||||
@ -272,7 +272,7 @@ module ts {
|
||||
}
|
||||
|
||||
public useCaseSensitiveFileNames(): boolean {
|
||||
return this.shimHost.useCaseSensitiveFileNames && this.useCaseSensitiveFileNames();
|
||||
return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false;
|
||||
}
|
||||
|
||||
public getCompilationSettings(): CompilerOptions {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user