@@ -17,10 +17,10 @@ class ExtensionRunner extends RunnerBase {
17
17
private extensionPath = ts . combinePaths ( this . basePath , "available" ) ;
18
18
private sourcePath = ts . combinePaths ( this . basePath , "source" ) ;
19
19
private fourslashPath = ts . combinePaths ( this . basePath , "fourslash" ) ;
20
- private extensionAPI : ts . Map < string > = { } ;
21
- private extensions : ts . Map < ts . Map < string > > = { } ;
22
- private virtualLib : ts . Map < string > = { } ;
23
- private virtualFs : ts . Map < string > = { } ;
20
+ private extensionAPI = ts . createMap < string > ( ) ;
21
+ private extensions = ts . createMap < ts . Map < string > > ( ) ;
22
+ private virtualLib = ts . createMap < string > ( ) ;
23
+ private virtualFs = ts . createMap < string > ( ) ;
24
24
25
25
prettyPrintDiagnostic ( diagnostic : ts . Diagnostic ) : string {
26
26
const message = ts . flattenDiagnosticMessageText ( diagnostic . messageText , "\n" ) ;
@@ -41,12 +41,12 @@ class ExtensionRunner extends RunnerBase {
41
41
ts . Debug . assert ( set !== this . virtualFs , "You cannot try to load the fs into itself." ) ;
42
42
43
43
// Load a fileset at the given location, but exclude the 'lib' kind files from the added set (they'll be reloaded at the top level before compilation)
44
- ts . forEachKey ( set , key => ts . forEachKey ( this . virtualLib , path => key === path ) ? void 0 : void ( this . virtualFs [ this . getCanonicalFileName ( `${ prefix } /${ key } ` ) ] = set [ key ] ) ) ;
44
+ ts . forEach ( Object . keys ( set ) , key => ts . forEach ( Object . keys ( this . virtualLib ) , path => key === path ) ? void 0 : void ( this . virtualFs [ this . getCanonicalFileName ( `${ prefix } /${ key } ` ) ] = set [ key ] ) ) ;
45
45
}
46
46
47
47
loadSetIntoFs ( set : ts . Map < string > ) {
48
48
ts . Debug . assert ( set !== this . virtualFs , "You cannot try to load the fs into itself." ) ;
49
- ts . forEachKey ( set , key => void ( this . virtualFs [ this . getCanonicalFileName ( key ) ] = set [ key ] ) ) ;
49
+ ts . forEach ( Object . keys ( set ) , key => void ( this . virtualFs [ this . getCanonicalFileName ( key ) ] = set [ key ] ) ) ;
50
50
}
51
51
52
52
private traces : string [ ] = [ ] ;
@@ -62,7 +62,7 @@ class ExtensionRunner extends RunnerBase {
62
62
} ,
63
63
directoryExists : ( path ) => {
64
64
const fullPath = this . mockHost . getCanonicalFileName ( path ) ;
65
- return ts . forEach ( ts . getKeys ( this . virtualFs ) , key => ts . startsWith ( key , fullPath ) ) ;
65
+ return ts . forEach ( Object . keys ( this . virtualFs ) , key => ts . startsWith ( key , fullPath ) ) ;
66
66
} ,
67
67
getCurrentDirectory ( ) : string { return "/" ; } ,
68
68
getSourceFile : ( path , languageVersion , onError ) : ts . SourceFile => {
@@ -76,7 +76,7 @@ class ExtensionRunner extends RunnerBase {
76
76
getCanonicalFileName : this . getCanonicalFileName ,
77
77
getDirectories : ( path ) => {
78
78
path = this . mockHost . getCanonicalFileName ( path ) ;
79
- return ts . filter ( ts . map ( ts . filter ( ts . getKeys ( this . virtualFs ) ,
79
+ return ts . filter ( ts . map ( ts . filter ( Object . keys ( this . virtualFs ) ,
80
80
fullpath => ts . startsWith ( fullpath , path ) && fullpath . substr ( path . length , 1 ) === "/" ) ,
81
81
fullpath => fullpath . substr ( path . length + 1 ) . indexOf ( "/" ) >= 0 ? fullpath . substr ( 0 , 1 + path . length + fullpath . substr ( path . length + 1 ) . indexOf ( "/" ) ) : fullpath ) ,
82
82
fullpath => fullpath . lastIndexOf ( "." ) === - 1 ) ;
@@ -118,7 +118,7 @@ class ExtensionRunner extends RunnerBase {
118
118
} ;
119
119
host . getScriptInfo = ( fileName : string ) => {
120
120
fileName = this . getCanonicalFileName ( fileName ) ;
121
- return ts . lookUp ( host . fileNameToScript , fileName ) ;
121
+ return host . fileNameToScript [ fileName ] ;
122
122
} ;
123
123
host . getDirectories = ( s : string ) => this . mockHost . getDirectories ( s ) ;
124
124
host . addScript = ( fileName : string , content : string , isRootFile : boolean ) : void => {
@@ -149,7 +149,7 @@ class ExtensionRunner extends RunnerBase {
149
149
150
150
languageServiceCompile ( typescriptFiles : string [ ] , options : ts . CompilerOptions ) : Harness . Compiler . CompilerResult {
151
151
const self = this ;
152
- const host = this . makeMockLSHost ( ts . getKeys ( this . virtualFs ) , options ) ;
152
+ const host = this . makeMockLSHost ( Object . keys ( this . virtualFs ) , options ) ;
153
153
const service = ts . createLanguageService ( host ) ;
154
154
const fileResults : Harness . Compiler . GeneratedFile [ ] = [ ] ;
155
155
@@ -199,7 +199,7 @@ class ExtensionRunner extends RunnerBase {
199
199
this . loadSetIntoFs ( fileset ) ;
200
200
201
201
// Consider all TS files in the passed fileset as the root files, but not any under a node_modules folder
202
- const typescriptFiles = ts . filter ( ts . getKeys ( fileset ) , name => ts . endsWith ( name , ".ts" ) && ! ( name . indexOf ( "node_modules" ) >= 0 ) ) ;
202
+ const typescriptFiles = ts . filter ( Object . keys ( fileset ) , name => ts . endsWith ( name , ".ts" ) && ! ( name . indexOf ( "node_modules" ) >= 0 ) ) ;
203
203
return compileFunc ( typescriptFiles , options ) ;
204
204
}
205
205
@@ -212,22 +212,24 @@ class ExtensionRunner extends RunnerBase {
212
212
}
213
213
throw new Error ( "Compiling test harness extension API code resulted in errors." ) ;
214
214
}
215
- ts . copyMap ( this . virtualFs , out ) ;
216
- this . virtualFs = { } ;
215
+ for ( const key in this . virtualFs ) {
216
+ out [ key ] = this . virtualFs [ key ] ;
217
+ }
218
+ this . virtualFs = ts . createMap < string > ( ) ;
217
219
return results ;
218
220
}
219
221
220
222
private loadExtensions ( ) {
221
- this . extensionAPI = {
223
+ this . extensionAPI = ts . createMap ( {
222
224
"package.json" : Harness . IO . readFile ( ts . combinePaths ( this . extensionPath , "extension-api/package.json" ) ) ,
223
225
"index.ts" : Harness . IO . readFile ( ts . combinePaths ( this . extensionPath , "extension-api/index.ts" ) ) ,
224
- } ;
226
+ } ) ;
225
227
this . buildMap ( ( str , opts ) => this . programCompile ( str , opts ) , this . extensionAPI , this . extensionAPI , { module : ts . ModuleKind . CommonJS , declaration : true } , /*shouldError*/ true ) ;
226
228
227
229
ts . forEach ( Harness . IO . getDirectories ( this . extensionPath ) , path => {
228
230
if ( path === "extension-api" || path === "typescript" ) return ; // Since these are dependencies of every actual test extension, we handle them specially
229
231
const packageDir = ts . combinePaths ( this . extensionPath , path ) ;
230
- const extensionFileset : ts . Map < string > = { } ;
232
+ const extensionFileset = ts . createMap < string > ( ) ;
231
233
const extensionFiles = this . enumerateFiles ( packageDir , /*regex*/ undefined , { recursive : true } ) ;
232
234
ts . forEach ( extensionFiles , name => {
233
235
const shortName = name . substring ( packageDir . length + 1 ) ;
@@ -244,10 +246,10 @@ class ExtensionRunner extends RunnerBase {
244
246
super ( ) ;
245
247
const { content : libContent } = Harness . getDefaultLibraryFile ( Harness . IO ) ;
246
248
const tsLibContents = Harness . IO . readFile ( "built/local/typescript.d.ts" ) ;
247
- this . virtualLib = {
249
+ this . virtualLib = ts . createMap ( {
248
250
"/lib/lib.d.ts" : libContent ,
249
251
"/node_modules/typescript/index.d.ts" : tsLibContents
250
- } ;
252
+ } ) ;
251
253
this . loadExtensions ( ) ;
252
254
}
253
255
@@ -304,7 +306,7 @@ class ExtensionRunner extends RunnerBase {
304
306
shortCasePath = caseName . substring ( this . scenarioPath . length + 1 ) . replace ( / \. j s o n $ / , "" ) ;
305
307
testConfigText = Harness . IO . readFile ( caseName ) ;
306
308
testConfig = JSON . parse ( testConfigText ) ;
307
- inputSources = { } ;
309
+ inputSources = ts . createMap < string > ( ) ;
308
310
inputTestFiles = [ ] ;
309
311
ts . forEach ( testConfig . inputFiles , name => {
310
312
inputSources [ name ] = Harness . IO . readFile ( ts . combinePaths ( this . sourcePath , name ) ) ;
@@ -329,9 +331,11 @@ class ExtensionRunner extends RunnerBase {
329
331
let result : Harness . Compiler . CompilerResult ;
330
332
before ( ( ) => {
331
333
this . traces = [ ] ; // Clear out any traces from tests which made traces, but didn't specify traceResolution
332
- this . virtualFs = { } ; // In case a fourslash test was run last (which doesn't clear FS on end like buildMap does), clear the FS
333
- sources = { } ;
334
- ts . copyMap ( inputSources , sources ) ;
334
+ this . virtualFs = ts . createMap < string > ( ) ; // In case a fourslash test was run last (which doesn't clear FS on end like buildMap does), clear the FS
335
+ sources = ts . createMap < string > ( ) ;
336
+ for ( const key in inputSources ) {
337
+ sources [ key ] = inputSources [ key ] ;
338
+ }
335
339
ts . forEach ( testConfig . availableExtensions , ext => this . loadSetIntoFsAt ( this . extensions [ ext ] , `/node_modules/${ ext } ` ) ) ;
336
340
result = this . buildMap ( compileCb , sources , sources , testConfig . compilerOptions , /*shouldError*/ false ) ;
337
341
} ) ;
@@ -465,7 +469,7 @@ class ExtensionRunner extends RunnerBase {
465
469
466
470
it ( "passes fourslash verification" , ( ) => {
467
471
if ( testConfig . fourslashTest ) {
468
- this . virtualFs = { } ;
472
+ this . virtualFs = ts . createMap < string > ( ) ;
469
473
const testFile = `${ this . fourslashPath } /${ testConfig . fourslashTest } ` ;
470
474
let testFileContents = Harness . IO . readFile ( testFile ) ;
471
475
testFileContents = testFileContents . replace ( `/// <reference path="../../fourslash/fourslash.ts" />` , "" ) ;
@@ -482,7 +486,7 @@ class ExtensionRunner extends RunnerBase {
482
486
this . loadSetIntoFs ( this . virtualLib ) ;
483
487
ts . forEach ( testConfig . availableExtensions , ext => this . loadSetIntoFsAt ( this . extensions [ ext ] , `/node_modules/${ ext } ` ) ) ;
484
488
485
- const adapterFactory = ( token : ts . HostCancellationToken ) => this . makeLSMockAdapter ( ts . getKeys ( this . virtualFs ) , testConfig . compilerOptions , token ) ;
489
+ const adapterFactory = ( token : ts . HostCancellationToken ) => this . makeLSMockAdapter ( Object . keys ( this . virtualFs ) , testConfig . compilerOptions , token ) ;
486
490
487
491
FourSlash . runFourSlashTestContent ( shortCasePath , adapterFactory , finishedTestContent , testFile ) ;
488
492
}
0 commit comments