@@ -810,14 +810,18 @@ module Harness {
810810 export function createCompilerHost ( inputFiles : { unitName : string ; content : string ; } [ ] ,
811811 writeFile : ( fn : string , contents : string , writeByteOrderMark : boolean ) => void ,
812812 scriptTarget : ts . ScriptTarget ,
813- useCaseSensitiveFileNames : boolean ) : ts . CompilerHost {
813+ useCaseSensitiveFileNames : boolean ,
814+ // the currentDirectory is needed for rwcRunner to passed in specified current directory to compiler host
815+ currentDirectory ?: string ) : ts . CompilerHost {
814816
815817 // Local get canonical file name function, that depends on passed in parameter for useCaseSensitiveFileNames
816818 function getCanonicalFileName ( fileName : string ) : string {
817819 return useCaseSensitiveFileNames ? fileName : fileName . toLowerCase ( ) ;
818820 }
819821
820822 var filemap : { [ filename : string ] : ts . SourceFile ; } = { } ;
823+ var getCurrentDirectory = currentDirectory === undefined ? ts . sys . getCurrentDirectory : ( ) => currentDirectory ;
824+
821825 // Register input files
822826 function register ( file : { unitName : string ; content : string ; } ) {
823827 if ( file . content !== undefined ) {
@@ -828,11 +832,15 @@ module Harness {
828832 inputFiles . forEach ( register ) ;
829833
830834 return {
831- getCurrentDirectory : ts . sys . getCurrentDirectory ,
835+ getCurrentDirectory,
832836 getSourceFile : ( fn , languageVersion ) => {
833837 if ( Object . prototype . hasOwnProperty . call ( filemap , getCanonicalFileName ( fn ) ) ) {
834838 return filemap [ getCanonicalFileName ( fn ) ] ;
835839 }
840+ else if ( currentDirectory ) {
841+ var canonicalAbsolutePath = getCanonicalFileName ( ts . getNormalizedAbsolutePath ( fn , currentDirectory ) ) ;
842+ return Object . prototype . hasOwnProperty . call ( filemap , getCanonicalFileName ( canonicalAbsolutePath ) ) ? filemap [ canonicalAbsolutePath ] : undefined ;
843+ }
836844 else if ( fn === fourslashFilename ) {
837845 var tsFn = 'tests/cases/fourslash/' + fourslashFilename ;
838846 fourslashSourceFile = fourslashSourceFile || ts . createSourceFile ( tsFn , Harness . IO . readFile ( tsFn ) , scriptTarget ) ;
@@ -909,7 +917,9 @@ module Harness {
909917 otherFiles : { unitName : string ; content : string } [ ] ,
910918 onComplete : ( result : CompilerResult , program : ts . Program ) => void ,
911919 settingsCallback ?: ( settings : ts . CompilerOptions ) => void ,
912- options ?: ts . CompilerOptions ) {
920+ options ?: ts . CompilerOptions ,
921+ // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
922+ currentDirectory ?: string ) {
913923
914924 options = options || { noResolve : false } ;
915925 options . target = options . target || ts . ScriptTarget . ES3 ;
@@ -1063,8 +1073,7 @@ module Harness {
10631073 var programFiles = inputFiles . map ( file => file . unitName ) ;
10641074 var program = ts . createProgram ( programFiles , options , createCompilerHost ( inputFiles . concat ( otherFiles ) ,
10651075 ( fn , contents , writeByteOrderMark ) => fileOutputs . push ( { fileName : fn , code : contents , writeByteOrderMark : writeByteOrderMark } ) ,
1066- options . target ,
1067- useCaseSensitiveFileNames ) ) ;
1076+ options . target , useCaseSensitiveFileNames , currentDirectory ) ) ;
10681077
10691078 var checker = program . getTypeChecker ( /*produceDiagnostics*/ true ) ;
10701079
@@ -1095,7 +1104,9 @@ module Harness {
10951104 otherFiles : { unitName : string ; content : string ; } [ ] ,
10961105 result : CompilerResult ,
10971106 settingsCallback ?: ( settings : ts . CompilerOptions ) => void ,
1098- options ?: ts . CompilerOptions ) {
1107+ options ?: ts . CompilerOptions ,
1108+ // Current directory is needed for rwcRunner to be able to use currentDirectory defined in json file
1109+ currentDirectory ?: string ) {
10991110 if ( options . declaration && result . errors . length === 0 && result . declFilesCode . length !== result . files . length ) {
11001111 throw new Error ( 'There were no errors and declFiles generated did not match number of js files generated' ) ;
11011112 }
@@ -1108,9 +1119,8 @@ module Harness {
11081119
11091120 ts . forEach ( inputFiles , file => addDtsFile ( file , declInputFiles ) ) ;
11101121 ts . forEach ( otherFiles , file => addDtsFile ( file , declOtherFiles ) ) ;
1111- this . compileFiles ( declInputFiles , declOtherFiles , function ( compileResult ) {
1112- declResult = compileResult ;
1113- } , settingsCallback , options ) ;
1122+ this . compileFiles ( declInputFiles , declOtherFiles , function ( compileResult ) { declResult = compileResult ; } ,
1123+ settingsCallback , options , currentDirectory ) ;
11141124
11151125 return { declInputFiles, declOtherFiles, declResult } ;
11161126 }
0 commit comments