@@ -922,10 +922,15 @@ namespace Harness {
922922 export const defaultLibFileName = "lib.d.ts" ;
923923 export const es2015DefaultLibFileName = "lib.es2015.d.ts" ;
924924
925+ // Cache of lib files from "built/local"
925926 const libFileNameSourceFileMap = ts . createMap < ts . SourceFile > ( {
926927 [ defaultLibFileName ] : createSourceFileAndAssertInvariants ( defaultLibFileName , IO . readFile ( libFolder + "lib.es5.d.ts" ) , /*languageVersion*/ ts . ScriptTarget . Latest )
927928 } ) ;
928929
930+ // Cache of lib files from "tests/lib/"
931+ const testLibFileNameSourceFileMap = ts . createMap < ts . SourceFile > ( ) ;
932+ const es6TestLibFileNameSourceFileMap = ts . createMap < ts . SourceFile > ( ) ;
933+
929934 export function getDefaultLibrarySourceFile ( fileName = defaultLibFileName ) : ts . SourceFile {
930935 if ( ! isDefaultLibraryFile ( fileName ) ) {
931936 return undefined ;
@@ -966,7 +971,8 @@ namespace Harness {
966971 useCaseSensitiveFileNames : boolean ,
967972 // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
968973 currentDirectory : string ,
969- newLineKind ?: ts . NewLineKind ) : ts . CompilerHost {
974+ newLineKind ?: ts . NewLineKind ,
975+ libFiles ?: string ) : ts . CompilerHost {
970976
971977 // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
972978 const getCanonicalFileName = ts . createGetCanonicalFileName ( useCaseSensitiveFileNames ) ;
@@ -988,6 +994,24 @@ namespace Harness {
988994 }
989995 }
990996
997+ if ( libFiles ) {
998+ // Because @libFiles don't change between execution. We would cache the result of the files and reuse it to speed help compilation
999+ for ( const fileName of libFiles . split ( "," ) ) {
1000+ const libFileName = "tests/lib/" + fileName ;
1001+
1002+ if ( scriptTarget <= ts . ScriptTarget . ES5 ) {
1003+ if ( ! testLibFileNameSourceFileMap [ libFileName ] ) {
1004+ testLibFileNameSourceFileMap [ libFileName ] = createSourceFileAndAssertInvariants ( libFileName , IO . readFile ( libFileName ) , scriptTarget ) ;
1005+ }
1006+ }
1007+ else {
1008+ if ( ! es6TestLibFileNameSourceFileMap [ libFileName ] ) {
1009+ es6TestLibFileNameSourceFileMap [ libFileName ] = createSourceFileAndAssertInvariants ( libFileName , IO . readFile ( libFileName ) , scriptTarget ) ;
1010+ }
1011+ }
1012+ }
1013+ }
1014+
9911015 function getSourceFile ( fileName : string ) {
9921016 fileName = ts . normalizePath ( fileName ) ;
9931017 const path = ts . toPath ( fileName , currentDirectory , getCanonicalFileName ) ;
@@ -999,6 +1023,9 @@ namespace Harness {
9991023 fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants ( tsFn , Harness . IO . readFile ( tsFn ) , scriptTarget ) ;
10001024 return fourslashSourceFile ;
10011025 }
1026+ else if ( ts . startsWith ( fileName , "tests/lib/" ) ) {
1027+ return scriptTarget <= ts . ScriptTarget . ES5 ? testLibFileNameSourceFileMap [ fileName ] : es6TestLibFileNameSourceFileMap [ fileName ] ;
1028+ }
10021029 else {
10031030 // Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
10041031 // Return if it is other library file, otherwise return undefined
@@ -1203,7 +1230,8 @@ namespace Harness {
12031230 if ( options . libFiles ) {
12041231 for ( const fileName of options . libFiles . split ( "," ) ) {
12051232 const libFileName = "tests/lib/" + fileName ;
1206- programFiles . push ( { unitName : libFileName , content : normalizeLineEndings ( IO . readFile ( libFileName ) , Harness . IO . newLine ( ) ) } ) ;
1233+ // Content is undefined here because in createCompilerHost we will create sourceFile for the lib file and cache the result
1234+ programFiles . push ( { unitName : libFileName , content : undefined } ) ;
12071235 }
12081236 }
12091237
@@ -1216,7 +1244,8 @@ namespace Harness {
12161244 options . target ,
12171245 useCaseSensitiveFileNames ,
12181246 currentDirectory ,
1219- options . newLine ) ;
1247+ options . newLine ,
1248+ options . libFiles ) ;
12201249
12211250 let traceResults : string [ ] ;
12221251 if ( options . traceResolution ) {
0 commit comments