Skip to content

Commit ef54047

Browse files
committed
address PR feedback
1 parent 269ae3a commit ef54047

File tree

5 files changed

+34
-22
lines changed

5 files changed

+34
-22
lines changed

src/compiler/core.ts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,39 @@ module ts {
1515
True = -1
1616
}
1717

18-
export class FileMap<T> {
19-
private files: Map<T> = {};
20-
21-
constructor(private getCanonicalFileName: (fileName: string) => string) {
18+
export function createFileMap<T>(getCanonicalFileName: (fileName: string) => string): FileMap<T> {
19+
let files: Map<T> = {};
20+
return {
21+
get,
22+
set,
23+
contains,
24+
delete: deleteItem,
25+
forEachValue: forEachValueInMap
2226
}
2327

24-
public set(fileName: string, value: T) {
25-
this.files[this.normalizeKey(fileName)] = value;
28+
function set(fileName: string, value: T) {
29+
files[normalizeKey(fileName)] = value;
2630
}
2731

28-
public get(fileName: string) {
29-
return this.files[this.normalizeKey(fileName)];
32+
function get(fileName: string) {
33+
return files[normalizeKey(fileName)];
3034
}
3135

32-
public contains(fileName: string) {
33-
return hasProperty(this.files, this.normalizeKey(fileName));
36+
function contains(fileName: string) {
37+
return hasProperty(files, normalizeKey(fileName));
3438
}
3539

36-
public delete(fileName: string) {
37-
let key = this.normalizeKey(fileName);
38-
delete this.files[key];
40+
function deleteItem (fileName: string) {
41+
let key = normalizeKey(fileName);
42+
delete files[key];
3943
}
4044

41-
public forEachValue(f: (value: T) => void) {
42-
forEachValue(this.files, f);
45+
function forEachValueInMap(f: (value: T) => void) {
46+
forEachValue(files, f);
4347
}
4448

45-
private normalizeKey(key: string) {
46-
return this.getCanonicalFileName(normalizeSlashes(key));
49+
function normalizeKey(key: string) {
50+
return getCanonicalFileName(normalizeSlashes(key));
4751
}
4852
}
4953

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ module ts {
158158
let start = new Date().getTime();
159159

160160
host = host || createCompilerHost(options);
161-
let filesByName: FileMap<SourceFile> = new FileMap<SourceFile>(host.getCanonicalFileName);
161+
let filesByName = createFileMap<SourceFile>(host.getCanonicalFileName);
162162

163163
forEach(rootNames, name => processRootFile(name, false));
164164
if (!seenNoDefaultLib) {

src/compiler/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ module ts {
33
[index: string]: T;
44
}
55

6+
export interface FileMap<T> {
7+
get(fileName: string): T;
8+
set(fileName: string, value: T): void;
9+
contains(fileName: string): boolean;
10+
delete(fileName: string): void;
11+
forEachValue(f: (v: T) => void): void;
12+
}
13+
614
export interface TextRange {
715
pos: number;
816
end: number;

src/services/services.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,7 +1638,7 @@ module ts {
16381638

16391639
constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) {
16401640
// script id => script index
1641-
this.fileNameToEntry = new FileMap<HostFileInformation>(getCanonicalFileName);
1641+
this.fileNameToEntry = createFileMap<HostFileInformation>(getCanonicalFileName);
16421642

16431643
// Initialize the list with the root file names
16441644
let rootFileNames = host.getScriptFileNames();
@@ -1881,7 +1881,7 @@ module ts {
18811881
// Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have
18821882
// for those settings.
18831883
let buckets: Map<FileMap<DocumentRegistryEntry>> = {};
1884-
let getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames || false);
1884+
let getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames);
18851885

18861886
function getKeyFromCompilationSettings(settings: CompilerOptions): string {
18871887
return "_" + settings.target; // + "|" + settings.propagateEnumConstantoString()
@@ -1891,7 +1891,7 @@ module ts {
18911891
let key = getKeyFromCompilationSettings(settings);
18921892
let bucket = lookUp(buckets, key);
18931893
if (!bucket && createIfMissing) {
1894-
buckets[key] = bucket = new FileMap<DocumentRegistryEntry>(getCanonicalFileName);
1894+
buckets[key] = bucket = createFileMap<DocumentRegistryEntry>(getCanonicalFileName);
18951895
}
18961896
return bucket;
18971897
}

src/services/shims.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ module ts {
272272
}
273273

274274
public useCaseSensitiveFileNames(): boolean {
275-
return this.shimHost.useCaseSensitiveFileNames && this.useCaseSensitiveFileNames();
275+
return this.shimHost.useCaseSensitiveFileNames ? this.shimHost.useCaseSensitiveFileNames() : false;
276276
}
277277

278278
public getCompilationSettings(): CompilerOptions {

0 commit comments

Comments
 (0)