1
1
/// <reference path="harness.ts" />
2
2
/// <reference path="..\compiler\commandLineParser.ts"/>
3
3
namespace Utils {
4
- export class VirtualFileSystemEntry < T > {
5
- fileSystem : VirtualFileSystem < T > ;
4
+ export class VirtualFileSystemEntry {
5
+ fileSystem : VirtualFileSystem ;
6
6
name : string ;
7
7
8
- constructor ( fileSystem : VirtualFileSystem < T > , name : string ) {
8
+ constructor ( fileSystem : VirtualFileSystem , name : string ) {
9
9
this . fileSystem = fileSystem ;
10
10
this . name = name ;
11
11
}
@@ -15,15 +15,15 @@ namespace Utils {
15
15
isFileSystem ( ) { return false ; }
16
16
}
17
17
18
- export class VirtualFile < T > extends VirtualFileSystemEntry < T > {
19
- content : T ;
18
+ export class VirtualFile extends VirtualFileSystemEntry {
19
+ content ?: Harness . LanguageService . ScriptInfo ;
20
20
isFile ( ) { return true ; }
21
21
}
22
22
23
- export abstract class VirtualFileSystemContainer < T > extends VirtualFileSystemEntry < T > {
24
- abstract getFileSystemEntries ( ) : VirtualFileSystemEntry < T > [ ] ;
23
+ export abstract class VirtualFileSystemContainer extends VirtualFileSystemEntry {
24
+ abstract getFileSystemEntries ( ) : VirtualFileSystemEntry [ ] ;
25
25
26
- getFileSystemEntry ( name : string ) : VirtualFileSystemEntry < T > {
26
+ getFileSystemEntry ( name : string ) : VirtualFileSystemEntry {
27
27
for ( const entry of this . getFileSystemEntries ( ) ) {
28
28
if ( this . fileSystem . sameName ( entry . name , name ) ) {
29
29
return entry ;
@@ -32,57 +32,57 @@ namespace Utils {
32
32
return undefined ;
33
33
}
34
34
35
- getDirectories ( ) : VirtualDirectory < T > [ ] {
36
- return < VirtualDirectory < T > [ ] > ts . filter ( this . getFileSystemEntries ( ) , entry => entry . isDirectory ( ) ) ;
35
+ getDirectories ( ) : VirtualDirectory [ ] {
36
+ return < VirtualDirectory [ ] > ts . filter ( this . getFileSystemEntries ( ) , entry => entry . isDirectory ( ) ) ;
37
37
}
38
38
39
- getFiles ( ) : VirtualFile < T > [ ] {
40
- return < VirtualFile < T > [ ] > ts . filter ( this . getFileSystemEntries ( ) , entry => entry . isFile ( ) ) ;
39
+ getFiles ( ) : VirtualFile [ ] {
40
+ return < VirtualFile [ ] > ts . filter ( this . getFileSystemEntries ( ) , entry => entry . isFile ( ) ) ;
41
41
}
42
42
43
- getDirectory ( name : string ) : VirtualDirectory < T > {
43
+ getDirectory ( name : string ) : VirtualDirectory {
44
44
const entry = this . getFileSystemEntry ( name ) ;
45
- return entry . isDirectory ( ) ? < VirtualDirectory < T > > entry : undefined ;
45
+ return entry . isDirectory ( ) ? < VirtualDirectory > entry : undefined ;
46
46
}
47
47
48
- getFile ( name : string ) : VirtualFile < T > {
48
+ getFile ( name : string ) : VirtualFile {
49
49
const entry = this . getFileSystemEntry ( name ) ;
50
- return entry . isFile ( ) ? < VirtualFile < T > > entry : undefined ;
50
+ return entry . isFile ( ) ? < VirtualFile > entry : undefined ;
51
51
}
52
52
}
53
53
54
- export class VirtualDirectory < T > extends VirtualFileSystemContainer < T > {
55
- private entries : VirtualFileSystemEntry < T > [ ] = [ ] ;
54
+ export class VirtualDirectory extends VirtualFileSystemContainer {
55
+ private entries : VirtualFileSystemEntry [ ] = [ ] ;
56
56
57
57
isDirectory ( ) { return true ; }
58
58
59
59
getFileSystemEntries ( ) { return this . entries . slice ( ) ; }
60
60
61
- addDirectory ( name : string ) : VirtualDirectory < T > {
61
+ addDirectory ( name : string ) : VirtualDirectory {
62
62
const entry = this . getFileSystemEntry ( name ) ;
63
63
if ( entry === undefined ) {
64
- const directory = new VirtualDirectory < T > ( this . fileSystem , name ) ;
64
+ const directory = new VirtualDirectory ( this . fileSystem , name ) ;
65
65
this . entries . push ( directory ) ;
66
66
return directory ;
67
67
}
68
68
else if ( entry . isDirectory ( ) ) {
69
- return < VirtualDirectory < T > > entry ;
69
+ return < VirtualDirectory > entry ;
70
70
}
71
71
else {
72
72
return undefined ;
73
73
}
74
74
}
75
75
76
- addFile ( name : string , content ?: T ) : VirtualFile < T > {
76
+ addFile ( name : string , content ?: Harness . LanguageService . ScriptInfo ) : VirtualFile {
77
77
const entry = this . getFileSystemEntry ( name ) ;
78
78
if ( entry === undefined ) {
79
- const file = new VirtualFile < T > ( this . fileSystem , name ) ;
79
+ const file = new VirtualFile ( this . fileSystem , name ) ;
80
80
file . content = content ;
81
81
this . entries . push ( file ) ;
82
82
return file ;
83
83
}
84
84
else if ( entry . isFile ( ) ) {
85
- const file = < VirtualFile < T > > entry ;
85
+ const file = < VirtualFile > entry ;
86
86
file . content = content ;
87
87
return file ;
88
88
}
@@ -92,16 +92,16 @@ namespace Utils {
92
92
}
93
93
}
94
94
95
- export class VirtualFileSystem < T > extends VirtualFileSystemContainer < T > {
96
- private root : VirtualDirectory < T > ;
95
+ export class VirtualFileSystem extends VirtualFileSystemContainer {
96
+ private root : VirtualDirectory ;
97
97
98
98
currentDirectory : string ;
99
99
useCaseSensitiveFileNames : boolean ;
100
100
101
101
constructor ( currentDirectory : string , useCaseSensitiveFileNames : boolean ) {
102
102
super ( undefined , "" ) ;
103
103
this . fileSystem = this ;
104
- this . root = new VirtualDirectory < T > ( this , "" ) ;
104
+ this . root = new VirtualDirectory ( this , "" ) ;
105
105
this . currentDirectory = currentDirectory ;
106
106
this . useCaseSensitiveFileNames = useCaseSensitiveFileNames ;
107
107
}
@@ -111,9 +111,9 @@ namespace Utils {
111
111
getFileSystemEntries ( ) { return this . root . getFileSystemEntries ( ) ; }
112
112
113
113
addDirectory ( path : string ) {
114
- path = this . normalizePathRoot ( path ) ;
114
+ path = ts . normalizePath ( path ) ;
115
115
const components = ts . getNormalizedPathComponents ( path , this . currentDirectory ) ;
116
- let directory : VirtualDirectory < T > = this . root ;
116
+ let directory : VirtualDirectory = this . root ;
117
117
for ( const component of components ) {
118
118
directory = directory . addDirectory ( component ) ;
119
119
if ( directory === undefined ) {
@@ -124,8 +124,8 @@ namespace Utils {
124
124
return directory ;
125
125
}
126
126
127
- addFile ( path : string , content ?: T ) {
128
- const absolutePath = this . normalizePathRoot ( ts . getNormalizedAbsolutePath ( path , this . currentDirectory ) ) ;
127
+ addFile ( path : string , content ?: Harness . LanguageService . ScriptInfo ) {
128
+ const absolutePath = ts . normalizePath ( ts . getNormalizedAbsolutePath ( path , this . currentDirectory ) ) ;
129
129
const fileName = ts . getBaseFileName ( path ) ;
130
130
const directoryPath = ts . getDirectoryPath ( absolutePath ) ;
131
131
const directory = this . addDirectory ( directoryPath ) ;
@@ -142,15 +142,15 @@ namespace Utils {
142
142
}
143
143
144
144
traversePath ( path : string ) {
145
- path = this . normalizePathRoot ( path ) ;
146
- let directory : VirtualDirectory < T > = this . root ;
145
+ path = ts . normalizePath ( path ) ;
146
+ let directory : VirtualDirectory = this . root ;
147
147
for ( const component of ts . getNormalizedPathComponents ( path , this . currentDirectory ) ) {
148
148
const entry = directory . getFileSystemEntry ( component ) ;
149
149
if ( entry === undefined ) {
150
150
return undefined ;
151
151
}
152
152
else if ( entry . isDirectory ( ) ) {
153
- directory = < VirtualDirectory < T > > entry ;
153
+ directory = < VirtualDirectory > entry ;
154
154
}
155
155
else {
156
156
return entry ;
@@ -168,7 +168,7 @@ namespace Utils {
168
168
getAccessibleFileSystemEntries ( path : string ) {
169
169
const entry = this . traversePath ( path ) ;
170
170
if ( entry && entry . isDirectory ( ) ) {
171
- const directory = < VirtualDirectory < T > > entry ;
171
+ const directory = < VirtualDirectory > entry ;
172
172
return {
173
173
files : ts . map ( directory . getFiles ( ) , f => f . name ) ,
174
174
directories : ts . map ( directory . getDirectories ( ) , d => d . name )
@@ -178,11 +178,11 @@ namespace Utils {
178
178
}
179
179
180
180
getAllFileEntries ( ) {
181
- const fileEntries : VirtualFile < T > [ ] = [ ] ;
181
+ const fileEntries : VirtualFile [ ] = [ ] ;
182
182
getFilesRecursive ( this . root , fileEntries ) ;
183
183
return fileEntries ;
184
184
185
- function getFilesRecursive ( dir : VirtualDirectory < T > , result : VirtualFile < T > [ ] ) {
185
+ function getFilesRecursive ( dir : VirtualDirectory , result : VirtualFile [ ] ) {
186
186
const files = dir . getFiles ( ) ;
187
187
const dirs = dir . getDirectories ( ) ;
188
188
for ( const file of files ) {
@@ -193,17 +193,9 @@ namespace Utils {
193
193
}
194
194
}
195
195
}
196
-
197
- normalizePathRoot ( path : string ) {
198
- const components = ts . getNormalizedPathComponents ( path , this . currentDirectory ) ;
199
-
200
- // Toss the root component
201
- components [ 0 ] = "" ;
202
- return components . join ( ts . directorySeparator ) ;
203
- }
204
196
}
205
197
206
- export class MockParseConfigHost extends VirtualFileSystem < string > implements ts . ParseConfigHost {
198
+ export class MockParseConfigHost extends VirtualFileSystem implements ts . ParseConfigHost {
207
199
constructor ( currentDirectory : string , ignoreCase : boolean , files : string [ ] ) {
208
200
super ( currentDirectory , ignoreCase ) ;
209
201
for ( const file of files ) {
0 commit comments