@@ -1030,19 +1030,12 @@ namespace Harness {
10301030 return result ;
10311031 }
10321032
1033- const carriageReturnLineFeed = "\r\n" ;
1034- const lineFeed = "\n" ;
1035-
10361033 export const defaultLibFileName = "lib.d.ts" ;
10371034 export const es2015DefaultLibFileName = "lib.es2015.d.ts" ;
10381035
10391036 // Cache of lib files from "built/local"
10401037 let libFileNameSourceFileMap : ts . Map < ts . SourceFile > | undefined ;
10411038
1042- // Cache of lib files from "tests/lib/"
1043- const testLibFileNameSourceFileMap = ts . createMap < ts . SourceFile > ( ) ;
1044- const es6TestLibFileNameSourceFileMap = ts . createMap < ts . SourceFile > ( ) ;
1045-
10461039 export function getDefaultLibrarySourceFile ( fileName = defaultLibFileName ) : ts . SourceFile {
10471040 if ( ! isDefaultLibraryFile ( fileName ) ) {
10481041 return undefined ;
@@ -1084,155 +1077,6 @@ namespace Harness {
10841077 return fileName ;
10851078 }
10861079
1087- export function createCompilerHost (
1088- inputFiles : TestFile [ ] ,
1089- writeFile : ( fn : string , contents : string , writeByteOrderMark : boolean ) => void ,
1090- scriptTarget : ts . ScriptTarget ,
1091- useCaseSensitiveFileNames : boolean ,
1092- // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
1093- currentDirectory : string ,
1094- newLineKind ?: ts . NewLineKind ,
1095- libFiles ?: string ) : ts . CompilerHost {
1096-
1097- // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
1098- const getCanonicalFileName = ts . createGetCanonicalFileName ( useCaseSensitiveFileNames ) ;
1099-
1100- /** Maps a symlink name to a realpath. Used only for exposing `realpath`. */
1101- const realPathMap = ts . createMap < string > ( ) ;
1102- /**
1103- * Maps a file name to a source file.
1104- * This will have a different SourceFile for every symlink pointing to that file;
1105- * if the program resolves realpaths then symlink entries will be ignored.
1106- */
1107- const fileMap = ts . createMap < ts . SourceFile > ( ) ;
1108- for ( const file of inputFiles ) {
1109- if ( file . content !== undefined ) {
1110- const fileName = ts . normalizePath ( file . unitName ) ;
1111- const path = ts . toPath ( file . unitName , currentDirectory , getCanonicalFileName ) ;
1112- if ( file . fileOptions && file . fileOptions . symlink ) {
1113- const links = file . fileOptions . symlink . split ( "," ) ;
1114- for ( const link of links ) {
1115- const linkPath = ts . toPath ( link , currentDirectory , getCanonicalFileName ) ;
1116- realPathMap . set ( linkPath , fileName ) ;
1117- // Create a different SourceFile for every symlink.
1118- const sourceFile = createSourceFileAndAssertInvariants ( linkPath , file . content , scriptTarget ) ;
1119- fileMap . set ( linkPath , sourceFile ) ;
1120- }
1121- }
1122- const sourceFile = createSourceFileAndAssertInvariants ( fileName , file . content , scriptTarget ) ;
1123- fileMap . set ( path , sourceFile ) ;
1124- }
1125- }
1126-
1127- if ( libFiles ) {
1128- // Because @libFiles don't change between execution. We would cache the result of the files and reuse it to speed help compilation
1129- for ( const fileName of libFiles . split ( "," ) ) {
1130- const libFileName = "tests/lib/" + fileName ;
1131-
1132- if ( scriptTarget <= ts . ScriptTarget . ES5 ) {
1133- if ( ! testLibFileNameSourceFileMap . get ( libFileName ) ) {
1134- testLibFileNameSourceFileMap . set ( libFileName , createSourceFileAndAssertInvariants ( libFileName , IO . readFile ( libFileName ) , scriptTarget ) ) ;
1135- }
1136- }
1137- else {
1138- if ( ! es6TestLibFileNameSourceFileMap . get ( libFileName ) ) {
1139- es6TestLibFileNameSourceFileMap . set ( libFileName , createSourceFileAndAssertInvariants ( libFileName , IO . readFile ( libFileName ) , scriptTarget ) ) ;
1140- }
1141- }
1142- }
1143- }
1144-
1145- function getSourceFile ( fileName : string ) {
1146- fileName = ts . normalizePath ( fileName ) ;
1147- const fromFileMap = fileMap . get ( toPath ( fileName ) ) ;
1148- if ( fromFileMap ) {
1149- return fromFileMap ;
1150- }
1151- else if ( fileName === fourslashFileName ) {
1152- const tsFn = "tests/cases/fourslash/" + fourslashFileName ;
1153- fourslashSourceFile = fourslashSourceFile || createSourceFileAndAssertInvariants ( tsFn , Harness . IO . readFile ( tsFn ) , scriptTarget ) ;
1154- return fourslashSourceFile ;
1155- }
1156- else if ( ts . startsWith ( fileName , "tests/lib/" ) ) {
1157- return scriptTarget <= ts . ScriptTarget . ES5 ? testLibFileNameSourceFileMap . get ( fileName ) : es6TestLibFileNameSourceFileMap . get ( fileName ) ;
1158- }
1159- else {
1160- // Don't throw here -- the compiler might be looking for a test that actually doesn't exist as part of the TC
1161- // Return if it is other library file, otherwise return undefined
1162- return getDefaultLibrarySourceFile ( fileName ) ;
1163- }
1164- }
1165-
1166- const newLine =
1167- newLineKind === ts . NewLineKind . CarriageReturnLineFeed ? carriageReturnLineFeed :
1168- newLineKind === ts . NewLineKind . LineFeed ? lineFeed :
1169- Harness . IO . newLine ( ) ;
1170-
1171- function toPath ( fileName : string ) : ts . Path {
1172- return ts . toPath ( fileName , currentDirectory , getCanonicalFileName ) ;
1173- }
1174-
1175- return {
1176- getCurrentDirectory : ( ) => currentDirectory ,
1177- getSourceFile,
1178- getDefaultLibFileName,
1179- writeFile,
1180- getCanonicalFileName,
1181- useCaseSensitiveFileNames : ( ) => useCaseSensitiveFileNames ,
1182- getNewLine : ( ) => newLine ,
1183- fileExists : fileName => fileMap . has ( toPath ( fileName ) ) ,
1184- readFile ( fileName : string ) : string | undefined {
1185- const file = fileMap . get ( toPath ( fileName ) ) ;
1186- if ( ts . endsWith ( fileName , "json" ) ) {
1187- // strip comments
1188- return file . getText ( ) ;
1189- }
1190- return file . text ;
1191- } ,
1192- realpath : ( fileName : string ) : ts . Path => {
1193- const path = toPath ( fileName ) ;
1194- return ( realPathMap . get ( path ) as ts . Path ) || path ;
1195- } ,
1196- directoryExists : dir => {
1197- let path = ts . toPath ( dir , currentDirectory , getCanonicalFileName ) ;
1198- // Strip trailing /, which may exist if the path is a drive root
1199- if ( path [ path . length - 1 ] === "/" ) {
1200- path = < ts . Path > path . substr ( 0 , path . length - 1 ) ;
1201- }
1202- return mapHasFileInDirectory ( path , fileMap ) ;
1203- } ,
1204- getDirectories : d => {
1205- const path = ts . toPath ( d , currentDirectory , getCanonicalFileName ) ;
1206- const result : string [ ] = [ ] ;
1207- ts . forEachKey ( fileMap , key => {
1208- if ( key . indexOf ( path ) === 0 && key . lastIndexOf ( "/" ) > path . length ) {
1209- let dirName = key . substr ( path . length , key . indexOf ( "/" , path . length + 1 ) - path . length ) ;
1210- if ( dirName [ 0 ] === "/" ) {
1211- dirName = dirName . substr ( 1 ) ;
1212- }
1213- if ( result . indexOf ( dirName ) < 0 ) {
1214- result . push ( dirName ) ;
1215- }
1216- }
1217- } ) ;
1218- return result ;
1219- }
1220- } ;
1221- }
1222-
1223- function mapHasFileInDirectory ( directoryPath : ts . Path , map : ts . Map < { } > ) : boolean {
1224- if ( ! map ) {
1225- return false ;
1226- }
1227- let exists = false ;
1228- ts . forEachKey ( map , fileName => {
1229- if ( ! exists && ts . startsWith ( fileName , directoryPath ) && fileName [ directoryPath . length ] === "/" ) {
1230- exists = true ;
1231- }
1232- } ) ;
1233- return exists ;
1234- }
1235-
12361080 interface HarnessOptions {
12371081 useCaseSensitiveFileNames ?: boolean ;
12381082 includeBuiltFile ?: string ;
0 commit comments