@@ -346,7 +346,7 @@ namespace ts {
346
346
? ( ( moduleNames : string [ ] , containingFile : string ) => host . resolveModuleNames ( moduleNames , containingFile ) )
347
347
: ( ( moduleNames : string [ ] , containingFile : string ) => map ( moduleNames , moduleName => resolveModuleName ( moduleName , containingFile , options , host ) . resolvedModule ) ) ;
348
348
349
- let filesByName = createFileMap < SourceFile > ( getCanonicalFileName ) ;
349
+ let filesByName = createFileMap < SourceFile > ( ) ;
350
350
// stores 'filename -> file association' ignoring case
351
351
// used to track cases when two file names differ only in casing
352
352
let filesByNameIgnoreCase = host . useCaseSensitiveFileNames ( ) ? createFileMap < SourceFile > ( fileName => fileName . toLowerCase ( ) ) : undefined ;
@@ -384,7 +384,7 @@ namespace ts {
384
384
385
385
program = {
386
386
getRootFileNames : ( ) => rootNames ,
387
- getSourceFile : getSourceFile ,
387
+ getSourceFile,
388
388
getSourceFiles : ( ) => files ,
389
389
getCompilerOptions : ( ) => options ,
390
390
getSyntacticDiagnostics,
@@ -435,7 +435,7 @@ namespace ts {
435
435
436
436
// check if program source files has changed in the way that can affect structure of the program
437
437
let newSourceFiles : SourceFile [ ] = [ ] ;
438
- let normalizedAbsoluteFileNames : string [ ] = [ ] ;
438
+ let filePaths : Path [ ] = [ ] ;
439
439
let modifiedSourceFiles : SourceFile [ ] = [ ] ;
440
440
441
441
for ( let oldSourceFile of oldProgram . getSourceFiles ( ) ) {
@@ -444,8 +444,8 @@ namespace ts {
444
444
return false ;
445
445
}
446
446
447
- const normalizedAbsolutePath = getNormalizedAbsolutePath ( newSourceFile . fileName , currentDirectory ) ;
448
- normalizedAbsoluteFileNames . push ( normalizedAbsolutePath ) ;
447
+ newSourceFile . path = oldSourceFile . path ;
448
+ filePaths . push ( newSourceFile . path ) ;
449
449
450
450
if ( oldSourceFile !== newSourceFile ) {
451
451
if ( oldSourceFile . hasNoDefaultLib !== newSourceFile . hasNoDefaultLib ) {
@@ -469,7 +469,7 @@ namespace ts {
469
469
470
470
if ( resolveModuleNamesWorker ) {
471
471
let moduleNames = map ( newSourceFile . imports , name => name . text ) ;
472
- let resolutions = resolveModuleNamesWorker ( moduleNames , normalizedAbsolutePath ) ;
472
+ let resolutions = resolveModuleNamesWorker ( moduleNames , getNormalizedAbsolutePath ( newSourceFile . fileName , currentDirectory ) ) ;
473
473
// ensure that module resolution results are still correct
474
474
for ( let i = 0 ; i < moduleNames . length ; ++ i ) {
475
475
let newResolution = resolutions [ i ] ;
@@ -500,7 +500,7 @@ namespace ts {
500
500
501
501
// update fileName -> file mapping
502
502
for ( let i = 0 , len = newSourceFiles . length ; i < len ; ++ i ) {
503
- filesByName . set ( normalizedAbsoluteFileNames [ i ] , newSourceFiles [ i ] ) ;
503
+ filesByName . set ( filePaths [ i ] , newSourceFiles [ i ] ) ;
504
504
}
505
505
506
506
files = newSourceFiles ;
@@ -570,7 +570,7 @@ namespace ts {
570
570
}
571
571
572
572
function getSourceFile ( fileName : string ) : SourceFile {
573
- return filesByName . get ( getNormalizedAbsolutePath ( fileName , currentDirectory ) ) ;
573
+ return filesByName . get ( toPath ( fileName , currentDirectory , getCanonicalFileName ) ) ;
574
574
}
575
575
576
576
function getDiagnosticsHelper (
@@ -741,7 +741,7 @@ namespace ts {
741
741
diagnostic = Diagnostics . File_0_has_unsupported_extension_The_only_supported_extensions_are_1 ;
742
742
diagnosticArgument = [ fileName , "'" + supportedExtensions . join ( "', '" ) + "'" ] ;
743
743
}
744
- else if ( ! findSourceFile ( fileName , getNormalizedAbsolutePath ( fileName , currentDirectory ) , isDefaultLib , refFile , refPos , refEnd ) ) {
744
+ else if ( ! findSourceFile ( fileName , toPath ( fileName , currentDirectory , getCanonicalFileName ) , isDefaultLib , refFile , refPos , refEnd ) ) {
745
745
diagnostic = Diagnostics . File_0_not_found ;
746
746
diagnosticArgument = [ fileName ] ;
747
747
}
@@ -751,13 +751,13 @@ namespace ts {
751
751
}
752
752
}
753
753
else {
754
- let nonTsFile : SourceFile = options . allowNonTsExtensions && findSourceFile ( fileName , getNormalizedAbsolutePath ( fileName , currentDirectory ) , isDefaultLib , refFile , refPos , refEnd ) ;
754
+ let nonTsFile : SourceFile = options . allowNonTsExtensions && findSourceFile ( fileName , toPath ( fileName , currentDirectory , getCanonicalFileName ) , isDefaultLib , refFile , refPos , refEnd ) ;
755
755
if ( ! nonTsFile ) {
756
756
if ( options . allowNonTsExtensions ) {
757
757
diagnostic = Diagnostics . File_0_not_found ;
758
758
diagnosticArgument = [ fileName ] ;
759
759
}
760
- else if ( ! forEach ( supportedExtensions , extension => findSourceFile ( fileName + extension , getNormalizedAbsolutePath ( fileName + extension , currentDirectory ) , isDefaultLib , refFile , refPos , refEnd ) ) ) {
760
+ else if ( ! forEach ( supportedExtensions , extension => findSourceFile ( fileName + extension , toPath ( fileName + extension , currentDirectory , getCanonicalFileName ) , isDefaultLib , refFile , refPos , refEnd ) ) ) {
761
761
diagnostic = Diagnostics . File_0_not_found ;
762
762
fileName += ".ts" ;
763
763
diagnosticArgument = [ fileName ] ;
@@ -786,7 +786,7 @@ namespace ts {
786
786
}
787
787
788
788
// Get source file from normalized fileName
789
- function findSourceFile ( fileName : string , normalizedAbsolutePath : string , isDefaultLib : boolean , refFile ?: SourceFile , refPos ?: number , refEnd ?: number ) : SourceFile {
789
+ function findSourceFile ( fileName : string , normalizedAbsolutePath : Path , isDefaultLib : boolean , refFile ?: SourceFile , refPos ?: number , refEnd ?: number ) : SourceFile {
790
790
if ( filesByName . contains ( normalizedAbsolutePath ) ) {
791
791
const file = filesByName . get ( normalizedAbsolutePath ) ;
792
792
// try to check if we've already seen this file but with a different casing in path
@@ -811,6 +811,8 @@ namespace ts {
811
811
812
812
filesByName . set ( normalizedAbsolutePath , file ) ;
813
813
if ( file ) {
814
+ file . path = normalizedAbsolutePath ;
815
+
814
816
if ( host . useCaseSensitiveFileNames ( ) ) {
815
817
// for case-sensitive file systems check if we've already seen some file with similar filename ignoring case
816
818
const existingFile = filesByNameIgnoreCase . get ( normalizedAbsolutePath ) ;
@@ -865,14 +867,7 @@ namespace ts {
865
867
let resolution = resolutions [ i ] ;
866
868
setResolvedModule ( file , moduleNames [ i ] , resolution ) ;
867
869
if ( resolution && ! options . noResolve ) {
868
- const absoluteImportPath = isRootedDiskPath ( resolution . resolvedFileName )
869
- ? resolution . resolvedFileName
870
- : getNormalizedAbsolutePath ( resolution . resolvedFileName , currentDirectory ) ;
871
-
872
- // convert an absolute import path to path that is relative to current directory
873
- // this was host still can locate it but files names in user output will be shorter (and thus look nicer).
874
- const relativePath = getRelativePathToDirectoryOrUrl ( currentDirectory , absoluteImportPath , currentDirectory , getCanonicalFileName , false ) ;
875
- const importedFile = findSourceFile ( relativePath , absoluteImportPath , /* isDefaultLib */ false , file , skipTrivia ( file . text , file . imports [ i ] . pos ) , file . imports [ i ] . end ) ;
870
+ const importedFile = findSourceFile ( resolution . resolvedFileName , toPath ( resolution . resolvedFileName , currentDirectory , getCanonicalFileName ) , /* isDefaultLib */ false , file , skipTrivia ( file . text , file . imports [ i ] . pos ) , file . imports [ i ] . end ) ;
876
871
877
872
if ( importedFile && resolution . isExternalLibraryImport ) {
878
873
if ( ! isExternalModule ( importedFile ) ) {
0 commit comments