@@ -568,7 +568,9 @@ namespace ts {
568
568
}
569
569
570
570
function getSourceFile ( fileName : string ) {
571
- return filesByName . get ( fileName ) ;
571
+ // first try to use file name as is to find file
572
+ // then try to convert relative file name to absolute and use it to retrieve source file
573
+ return filesByName . get ( fileName ) || filesByName . get ( getNormalizedAbsolutePath ( fileName , host . getCurrentDirectory ( ) ) ) ;
572
574
}
573
575
574
576
function getDiagnosticsHelper (
@@ -775,60 +777,62 @@ namespace ts {
775
777
776
778
// Get source file from normalized fileName
777
779
function findSourceFile ( fileName : string , isDefaultLib : boolean , refFile ?: SourceFile , refPos ?: number , refEnd ?: number ) : SourceFile {
778
- let canonicalName = host . getCanonicalFileName ( normalizeSlashes ( fileName ) ) ;
779
- if ( filesByName . contains ( canonicalName ) ) {
780
+ if ( filesByName . contains ( fileName ) ) {
780
781
// We've already looked for this file, use cached result
781
- return getSourceFileFromCache ( fileName , canonicalName , /*useAbsolutePath*/ false ) ;
782
+ return getSourceFileFromCache ( fileName , /*useAbsolutePath*/ false ) ;
783
+ }
784
+
785
+ let normalizedAbsolutePath = getNormalizedAbsolutePath ( fileName , host . getCurrentDirectory ( ) ) ;
786
+ if ( filesByName . contains ( normalizedAbsolutePath ) ) {
787
+ const file = getSourceFileFromCache ( normalizedAbsolutePath , /*useAbsolutePath*/ true ) ;
788
+ // we don't have resolution for this relative file name but the match was found by absolute file name
789
+ // store resolution for relative name as well
790
+ filesByName . set ( fileName , file ) ;
791
+ return file ;
782
792
}
783
- else {
784
- let normalizedAbsolutePath = getNormalizedAbsolutePath ( fileName , host . getCurrentDirectory ( ) ) ;
785
- let canonicalAbsolutePath = host . getCanonicalFileName ( normalizedAbsolutePath ) ;
786
- if ( filesByName . contains ( canonicalAbsolutePath ) ) {
787
- return getSourceFileFromCache ( normalizedAbsolutePath , canonicalAbsolutePath , /*useAbsolutePath*/ true ) ;
788
- }
789
793
790
- // We haven't looked for this file, do so now and cache result
791
- let file = host . getSourceFile ( fileName , options . target , hostErrorMessage => {
792
- if ( refFile !== undefined && refPos !== undefined && refEnd !== undefined ) {
793
- fileProcessingDiagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
794
- Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
795
- }
796
- else {
797
- fileProcessingDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
798
- }
799
- } ) ;
800
- filesByName . set ( canonicalName , file ) ;
801
- if ( file ) {
802
- skipDefaultLib = skipDefaultLib || file . hasNoDefaultLib ;
794
+ // We haven't looked for this file, do so now and cache result
795
+ let file = host . getSourceFile ( fileName , options . target , hostErrorMessage => {
796
+ if ( refFile !== undefined && refPos !== undefined && refEnd !== undefined ) {
797
+ fileProcessingDiagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
798
+ Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
799
+ }
800
+ else {
801
+ fileProcessingDiagnostics . add ( createCompilerDiagnostic ( Diagnostics . Cannot_read_file_0_Colon_1 , fileName , hostErrorMessage ) ) ;
802
+ }
803
+ } ) ;
804
+
805
+ filesByName . set ( fileName , file ) ;
806
+ if ( file ) {
807
+ skipDefaultLib = skipDefaultLib || file . hasNoDefaultLib ;
803
808
804
- // Set the source file for normalized absolute path
805
- filesByName . set ( canonicalAbsolutePath , file ) ;
806
-
807
- let basePath = getDirectoryPath ( fileName ) ;
808
- if ( ! options . noResolve ) {
809
- processReferencedFiles ( file , basePath ) ;
810
- }
809
+ // Set the source file for normalized absolute path
810
+ filesByName . set ( normalizedAbsolutePath , file ) ;
811
+
812
+ let basePath = getDirectoryPath ( fileName ) ;
813
+ if ( ! options . noResolve ) {
814
+ processReferencedFiles ( file , basePath ) ;
815
+ }
811
816
812
- // always process imported modules to record module name resolutions
813
- processImportedModules ( file , basePath ) ;
817
+ // always process imported modules to record module name resolutions
818
+ processImportedModules ( file , basePath ) ;
814
819
815
- if ( isDefaultLib ) {
816
- file . isDefaultLib = true ;
817
- files . unshift ( file ) ;
818
- }
819
- else {
820
- files . push ( file ) ;
821
- }
820
+ if ( isDefaultLib ) {
821
+ file . isDefaultLib = true ;
822
+ files . unshift ( file ) ;
823
+ }
824
+ else {
825
+ files . push ( file ) ;
822
826
}
823
-
824
- return file ;
825
827
}
826
828
827
- function getSourceFileFromCache ( fileName : string , canonicalName : string , useAbsolutePath : boolean ) : SourceFile {
828
- let file = filesByName . get ( canonicalName ) ;
829
+ return file ;
830
+
831
+ function getSourceFileFromCache ( fileName : string , useAbsolutePath : boolean ) : SourceFile {
832
+ let file = filesByName . get ( fileName ) ;
829
833
if ( file && host . useCaseSensitiveFileNames ( ) ) {
830
834
let sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath ( file . fileName , host . getCurrentDirectory ( ) ) : file . fileName ;
831
- if ( canonicalName !== sourceFileName ) {
835
+ if ( normalizeSlashes ( fileName ) !== normalizeSlashes ( sourceFileName ) ) {
832
836
if ( refFile !== undefined && refPos !== undefined && refEnd !== undefined ) {
833
837
fileProcessingDiagnostics . add ( createFileDiagnostic ( refFile , refPos , refEnd - refPos ,
834
838
Diagnostics . File_name_0_differs_from_already_included_file_name_1_only_in_casing , fileName , sourceFileName ) ) ;
@@ -862,8 +866,8 @@ namespace ts {
862
866
const importedFile = findModuleSourceFile ( resolution . resolvedFileName , file . imports [ i ] ) ;
863
867
if ( importedFile && resolution . isExternalLibraryImport ) {
864
868
if ( ! isExternalModule ( importedFile ) ) {
865
- let start = getTokenPosOfNode ( file . imports [ i ] , file )
866
- fileProcessingDiagnostics . add ( createFileDiagnostic ( file , start , file . imports [ i ] . end - start , Diagnostics . Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition , importedFile . fileName ) ) ;
869
+ let start = getTokenPosOfNode ( file . imports [ i ] , file )
870
+ fileProcessingDiagnostics . add ( createFileDiagnostic ( file , start , file . imports [ i ] . end - start , Diagnostics . Exported_external_package_typings_file_0_is_not_a_module_Please_contact_the_package_author_to_update_the_package_definition , importedFile . fileName ) ) ;
867
871
}
868
872
else if ( ! fileExtensionIs ( importedFile . fileName , ".d.ts" ) ) {
869
873
let start = getTokenPosOfNode ( file . imports [ i ] , file )
0 commit comments