55/// <reference path="../compiler/commandLineParser.ts"/>
66namespace vfs {
77 import compareStrings = collections . compareStrings ;
8- import KeyedCollection = collections . SortedCollection ;
8+ import SortedCollection = collections . SortedCollection ;
99 import Metadata = collections . Metadata ;
1010 import EventEmitter = events . EventEmitter ;
1111 import IO = Harness . IO ;
@@ -123,8 +123,8 @@ namespace vfs {
123123 private _currentDirectory : string ;
124124 private _currentDirectoryStack : string [ ] | undefined ;
125125 private _shadowRoot : VirtualFileSystem | undefined ;
126- private _watchedFiles : KeyedCollection < string , FileWatcherEntry [ ] > | undefined ;
127- private _watchedDirectories : KeyedCollection < string , DirectoryWatcherEntryArray > | undefined ;
126+ private _watchedFiles : SortedCollection < string , FileWatcherEntry [ ] > | undefined ;
127+ private _watchedDirectories : SortedCollection < string , DirectoryWatcherEntryArray > | undefined ;
128128 private _onRootFileSystemChange : ( path : string , change : FileSystemChange ) => void ;
129129
130130 constructor ( currentDirectory : string , useCaseSensitiveFileNames : boolean ) {
@@ -134,6 +134,18 @@ namespace vfs {
134134 this . _onRootFileSystemChange = ( path , change ) => this . onRootFileSystemChange ( path , change ) ;
135135 }
136136
137+ public get stringComparer ( ) {
138+ return this . useCaseSensitiveFileNames
139+ ? compareStrings . caseSensitive
140+ : compareStrings . caseInsensitive ;
141+ }
142+
143+ public get pathComparer ( ) {
144+ return this . useCaseSensitiveFileNames
145+ ? vpath . compare . caseSensitive
146+ : vpath . compare . caseInsensitive ;
147+ }
148+
137149 /**
138150 * Gets the file system shadowed by this instance.
139151 */
@@ -207,13 +219,6 @@ namespace vfs {
207219 return vfs ;
208220 }
209221
210- /**
211- * Gets a value indicating whether to file names are equivalent for the file system's case sensitivity.
212- */
213- public sameName ( a : string , b : string ) {
214- return compareStrings ( a , b , ! this . useCaseSensitiveFileNames ) === 0 ;
215- }
216-
217222 /**
218223 * Changes the current directory to the supplied path.
219224 */
@@ -405,7 +410,7 @@ namespace vfs {
405410 public watchFile ( path : string , watcher : ( path : string , change : FileSystemChange ) => void ) : ts . FileWatcher {
406411 if ( ! this . _watchedFiles ) {
407412 const pathComparer = this . useCaseSensitiveFileNames ? vpath . compare . caseSensitive : vpath . compare . caseInsensitive ;
408- this . _watchedFiles = new KeyedCollection < string , FileWatcherEntry [ ] > ( pathComparer ) ;
413+ this . _watchedFiles = new SortedCollection < string , FileWatcherEntry [ ] > ( pathComparer ) ;
409414 }
410415
411416 path = vpath . resolve ( this . currentDirectory , path ) ;
@@ -434,7 +439,7 @@ namespace vfs {
434439 public watchDirectory ( path : string , watcher : ( path : string ) => void , recursive ?: boolean ) {
435440 if ( ! this . _watchedDirectories ) {
436441 const pathComparer = this . useCaseSensitiveFileNames ? vpath . compare . caseSensitive : vpath . compare . caseInsensitive ;
437- this . _watchedDirectories = new KeyedCollection < string , DirectoryWatcherEntryArray > ( pathComparer ) ;
442+ this . _watchedDirectories = new SortedCollection < string , DirectoryWatcherEntryArray > ( pathComparer ) ;
438443 }
439444
440445 path = vpath . resolve ( this . currentDirectory , path ) ;
@@ -636,7 +641,7 @@ namespace vfs {
636641 export class VirtualDirectory extends VirtualFileSystemEntry {
637642 protected _shadowRoot : VirtualDirectory | undefined ;
638643 private _parent : VirtualDirectory ;
639- private _entries : KeyedCollection < string , VirtualEntry > | undefined ;
644+ private _entries : SortedCollection < string , VirtualEntry > | undefined ;
640645 private _resolver : FileSystemResolver | undefined ;
641646 private _onChildFileSystemChange : ( path : string , change : FileSystemChange ) => void ;
642647
@@ -902,7 +907,7 @@ namespace vfs {
902907
903908 protected getOwnEntries ( ) {
904909 if ( ! this . _entries ) {
905- const entries = new KeyedCollection < string , VirtualEntry > ( this . fileSystem . useCaseSensitiveFileNames ? compareStrings . caseSensitive : compareStrings . caseInsensitive ) ;
910+ const entries = new SortedCollection < string , VirtualEntry > ( this . fileSystem . stringComparer ) ;
906911 const resolver = this . _resolver ;
907912 const shadowRoot = this . _shadowRoot ;
908913 if ( resolver ) {
@@ -1048,16 +1053,16 @@ namespace vfs {
10481053 export class VirtualDirectorySymlink extends VirtualDirectory {
10491054 private _targetPath : string ;
10501055 private _target : VirtualDirectory | undefined ;
1051- private _pullEntries : KeyedCollection < string , VirtualEntryView > | undefined ;
1052- private _allEntries : KeyedCollection < string , VirtualEntryView > | undefined ;
1056+ private _views : SortedCollection < string , VirtualEntryView > | undefined ;
1057+ private _allViews : SortedCollection < string , VirtualEntryView > | undefined ;
10531058 private _onTargetParentChildRemoved : ( entry : VirtualEntry ) => void ;
10541059 private _onTargetChildRemoved : ( entry : VirtualEntry ) => void ;
10551060 private _onTargetChildAdded : ( entry : VirtualEntry ) => void ;
10561061 private _onTargetFileSystemChange : ( path : string , change : FileSystemChange ) => void ;
10571062
10581063 constructor ( parent : VirtualDirectory , name : string , target : string ) {
10591064 super ( parent , name ) ;
1060- this . _pullEntries = new KeyedCollection < string , VirtualEntryView > ( this . fileSystem . useCaseSensitiveFileNames ? compareStrings . caseSensitive : compareStrings . caseInsensitive ) ;
1065+ this . _views = new SortedCollection < string , VirtualEntryView > ( this . fileSystem . stringComparer ) ;
10611066 this . _targetPath = target ;
10621067 this . _onTargetParentChildRemoved = entry => this . onTargetParentChildRemoved ( entry ) ;
10631068 this . _onTargetChildAdded = entry => this . onTargetChildAdded ( entry ) ;
@@ -1110,66 +1115,66 @@ namespace vfs {
11101115 }
11111116
11121117 protected addOwnDirectory ( name : string , resolver ?: FileSystemResolver ) : VirtualDirectory | undefined {
1113- const realTarget = this . target ;
1114- const child = realTarget && realTarget . addDirectory ( name , resolver ) ;
1118+ const target = this . target ;
1119+ const child = target && target . addDirectory ( name , resolver ) ;
11151120 return child && this . getView ( child ) ;
11161121 }
11171122
11181123 protected addOwnFile ( name : string , content ?: FileSystemResolver | ContentResolver | string ) : VirtualFile | undefined {
1119- const realTarget = this . target ;
1120- const child = realTarget && realTarget . addFile ( name , content ) ;
1124+ const target = this . target ;
1125+ const child = target && target . addFile ( name , content ) ;
11211126 return child && this . getView ( child ) ;
11221127 }
11231128
1124- protected addOwnSymlink ( name : string , target : VirtualEntry ) : VirtualSymlink | undefined {
1125- const realTarget = this . target ;
1126- const child = realTarget && realTarget . addSymlink ( name , target ) ;
1129+ protected addOwnSymlink ( name : string , linkTarget : VirtualEntry ) : VirtualSymlink | undefined {
1130+ const target = this . target ;
1131+ const child = target && target . addSymlink ( name , linkTarget ) ;
11271132 return child && this . getView ( child ) ;
11281133 }
11291134
11301135 protected removeOwnDirectory ( name : string ) : boolean {
1131- const realTarget = this . target ;
1132- return realTarget && realTarget . removeDirectory ( name ) || false ;
1136+ const target = this . target ;
1137+ return target && target . removeDirectory ( name ) || false ;
11331138 }
11341139
11351140 protected removeOwnFile ( name : string ) : boolean {
1136- const realTarget = this . target ;
1137- return realTarget && realTarget . removeFile ( name ) || false ;
1141+ const target = this . target ;
1142+ return target && target . removeFile ( name ) || false ;
11381143 }
11391144
1140- protected getOwnEntries ( ) : KeyedCollection < string , VirtualEntryView > {
1141- if ( ! this . _allEntries ) {
1142- const realTarget = this . target ;
1143- this . _allEntries = new KeyedCollection < string , VirtualEntryView > ( this . fileSystem . useCaseSensitiveFileNames ? compareStrings . caseSensitive : compareStrings . caseInsensitive ) ;
1144- if ( realTarget ) {
1145- for ( const entry of realTarget . getEntries ( ) ) {
1146- this . _allEntries . set ( entry . name , this . getView ( entry ) ) ;
1145+ protected getOwnEntries ( ) : SortedCollection < string , VirtualEntryView > {
1146+ if ( ! this . _allViews ) {
1147+ this . _allViews = new SortedCollection < string , VirtualEntryView > ( this . fileSystem . stringComparer ) ;
1148+ const target = this . target ;
1149+ if ( target ) {
1150+ for ( const entry of target . getEntries ( ) ) {
1151+ this . _allViews . set ( entry . name , this . getView ( entry ) ) ;
11471152 }
11481153 }
11491154 }
1150- return this . _allEntries ;
1155+ return this . _allViews ;
11511156 }
11521157
11531158 private getView ( entry : VirtualFile ) : VirtualFileView ;
11541159 private getView ( entry : VirtualDirectory ) : VirtualDirectoryView ;
11551160 private getView ( entry : VirtualEntry ) : VirtualEntryView ;
11561161 private getView ( entry : VirtualEntry ) {
1157- let symlink = this . _pullEntries . get ( entry . name ) ;
1162+ let view = this . _views . get ( entry . name ) ;
11581163 if ( entry instanceof VirtualFile ) {
1159- if ( symlink instanceof VirtualFileView ) {
1160- return symlink ;
1164+ if ( view instanceof VirtualFileView ) {
1165+ return view ;
11611166 }
1162- symlink = new VirtualFileView ( this , entry . name , entry . path ) ;
1163- this . _pullEntries . set ( entry . name , symlink ) ;
1167+ view = new VirtualFileView ( this , entry . name , entry . path ) ;
1168+ this . _views . set ( entry . name , view ) ;
11641169 }
11651170 else {
1166- if ( symlink instanceof VirtualDirectoryView ) {
1167- return symlink ;
1171+ if ( view instanceof VirtualDirectoryView ) {
1172+ return view ;
11681173 }
1169- symlink = new VirtualDirectoryView ( this , entry . name , entry . path ) ;
1170- this . _pullEntries . set ( entry . name , symlink ) ;
1174+ view = new VirtualDirectoryView ( this , entry . name , entry . path ) ;
1175+ this . _views . set ( entry . name , view ) ;
11711176 }
1172- return symlink ;
1177+ return view ;
11731178 }
11741179
11751180 private resolveTarget ( ) : void {
@@ -1192,8 +1197,8 @@ namespace vfs {
11921197 this . _target . removeListener ( "childRemoved" , this . _onTargetChildRemoved ) ;
11931198 this . _target . removeListener ( "fileSystemChange" , this . _onTargetFileSystemChange ) ;
11941199 this . _target = undefined ;
1195- this . _pullEntries . clear ( ) ;
1196- this . _allEntries = undefined ;
1200+ this . _views . clear ( ) ;
1201+ this . _allViews = undefined ;
11971202 }
11981203
11991204 private onTargetParentChildRemoved ( entry : VirtualEntry ) {
@@ -1211,7 +1216,7 @@ namespace vfs {
12111216 private onTargetChildRemoved ( entry : VirtualEntry ) {
12121217 const symlink = this . getView ( entry ) ;
12131218 this . getOwnEntries ( ) . delete ( entry . name ) ;
1214- this . _pullEntries . delete ( entry . name ) ;
1219+ this . _views . delete ( entry . name ) ;
12151220 this . emit ( "childRemoved" , symlink ) ;
12161221 }
12171222
@@ -1411,16 +1416,16 @@ namespace vfs {
14111416 * Gets the text content of this file.
14121417 */
14131418 public get content ( ) : string | undefined {
1414- const realTarget = this . target ;
1415- return realTarget && realTarget . content ;
1419+ const target = this . target ;
1420+ return target && target . content ;
14161421 }
14171422
14181423 /**
14191424 * Sets the text content of this file.
14201425 */
14211426 public set content ( value : string | undefined ) {
1422- const realTarget = this . target ;
1423- if ( realTarget ) realTarget . content = value ;
1427+ const target = this . target ;
1428+ if ( target ) target . content = value ;
14241429 }
14251430
14261431 /**
0 commit comments