@@ -922,10 +922,15 @@ namespace Harness {
922
922
export const defaultLibFileName = "lib.d.ts" ;
923
923
export const es2015DefaultLibFileName = "lib.es2015.d.ts" ;
924
924
925
+ // Cache of lib files from "built/local"
925
926
const libFileNameSourceFileMap = ts . createMapFromTemplate < ts . SourceFile > ( {
926
927
[ defaultLibFileName ] : createSourceFileAndAssertInvariants ( defaultLibFileName , IO . readFile ( libFolder + "lib.es5.d.ts" ) , /*languageVersion*/ ts . ScriptTarget . Latest )
927
928
} ) ;
928
929
930
+ // Cache of lib files from "tests/lib/"
931
+ const testLibFileNameSourceFileMap = ts . createMap < ts . SourceFile > ( ) ;
932
+ const es6TestLibFileNameSourceFileMap = ts . createMap < ts . SourceFile > ( ) ;
933
+
929
934
export function getDefaultLibrarySourceFile ( fileName = defaultLibFileName ) : ts . SourceFile {
930
935
if ( ! isDefaultLibraryFile ( fileName ) ) {
931
936
return undefined ;
@@ -967,7 +972,8 @@ namespace Harness {
967
972
useCaseSensitiveFileNames : boolean ,
968
973
// the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
969
974
currentDirectory : string ,
970
- newLineKind ?: ts . NewLineKind ) : ts . CompilerHost {
975
+ newLineKind ?: ts . NewLineKind ,
976
+ libFiles ?: string ) : ts . CompilerHost {
971
977
972
978
// Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
973
979
const getCanonicalFileName = ts . createGetCanonicalFileName ( useCaseSensitiveFileNames ) ;
@@ -999,6 +1005,24 @@ namespace Harness {
999
1005
}
1000
1006
}
1001
1007
1008
+ if ( libFiles ) {
1009
+ // Because @libFiles don't change between execution. We would cache the result of the files and reuse it to speed help compilation
1010
+ for ( const fileName of libFiles . split ( "," ) ) {
1011
+ const libFileName = "tests/lib/" + fileName ;
1012
+
1013
+ if ( scriptTarget <= ts . ScriptTarget . ES5 ) {
1014
+ if ( ! testLibFileNameSourceFileMap [ libFileName ] ) {
1015
+ testLibFileNameSourceFileMap [ libFileName ] = createSourceFileAndAssertInvariants ( libFileName , IO . readFile ( libFileName ) , scriptTarget ) ;
1016
+ }
1017
+ }
1018
+ else {
1019
+ if ( ! es6TestLibFileNameSourceFileMap [ libFileName ] ) {
1020
+ es6TestLibFileNameSourceFileMap [ libFileName ] = createSourceFileAndAssertInvariants ( libFileName , IO . readFile ( libFileName ) , scriptTarget ) ;
1021
+ }
1022
+ }
1023
+ }
1024
+ }
1025
+
1002
1026
function getSourceFile ( fileName : string ) {
1003
1027
fileName = ts . normalizePath ( fileName ) ;
1004
1028
const fromFileMap = fileMap . get ( toPath ( fileName ) ) ;
@@ -1010,6 +1034,9 @@ namespace Harness {
1010
1034
fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants ( tsFn , Harness . IO . readFile ( tsFn ) , scriptTarget ) ;
1011
1035
return fourslashSourceFile ;
1012
1036
}
1037
+ else if ( ts . startsWith ( fileName , "tests/lib/" ) ) {
1038
+ return scriptTarget <= ts . ScriptTarget . ES5 ? testLibFileNameSourceFileMap [ fileName ] : es6TestLibFileNameSourceFileMap [ fileName ] ;
1039
+ }
1013
1040
else {
1014
1041
// Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
1015
1042
// Return if it is other library file, otherwise return undefined
@@ -1221,7 +1248,8 @@ namespace Harness {
1221
1248
if ( options . libFiles ) {
1222
1249
for ( const fileName of options . libFiles . split ( "," ) ) {
1223
1250
const libFileName = "tests/lib/" + fileName ;
1224
- programFiles . push ( { unitName : libFileName , content : normalizeLineEndings ( IO . readFile ( libFileName ) , Harness . IO . newLine ( ) ) } ) ;
1251
+ // Content is undefined here because in createCompilerHost we will create sourceFile for the lib file and cache the result
1252
+ programFiles . push ( { unitName : libFileName , content : undefined } ) ;
1225
1253
}
1226
1254
}
1227
1255
@@ -1234,7 +1262,8 @@ namespace Harness {
1234
1262
options . target ,
1235
1263
useCaseSensitiveFileNames ,
1236
1264
currentDirectory ,
1237
- options . newLine ) ;
1265
+ options . newLine ,
1266
+ options . libFiles ) ;
1238
1267
1239
1268
let traceResults : string [ ] ;
1240
1269
if ( options . traceResolution ) {
0 commit comments