@@ -643,6 +643,14 @@ module ts {
643
643
return false ;
644
644
}
645
645
646
+ export function tryResolveScriptReference ( program : Program , sourceFile : SourceFile , reference : FileReference ) {
647
+ if ( ! program . getCompilerOptions ( ) . noResolve ) {
648
+ var referenceFileName = isRootedDiskPath ( reference . filename ) ? reference . filename : combinePaths ( getDirectoryPath ( sourceFile . filename ) , reference . filename ) ;
649
+ referenceFileName = getNormalizedAbsolutePath ( referenceFileName , program . getCompilerHost ( ) . getCurrentDirectory ( ) ) ;
650
+ return program . getSourceFile ( referenceFileName ) ;
651
+ }
652
+ }
653
+
646
654
export function getAncestor ( node : Node , kind : SyntaxKind ) : Node {
647
655
switch ( kind ) {
648
656
// special-cases that can be come first
@@ -4695,20 +4703,26 @@ module ts {
4695
4703
var canonicalName = host . getCanonicalFileName ( filename ) ;
4696
4704
if ( hasProperty ( filesByName , canonicalName ) ) {
4697
4705
// We've already looked for this file, use cached result
4698
- var file = filesByName [ canonicalName ] ;
4699
- if ( file && host . useCaseSensitiveFileNames ( ) && canonicalName !== file . filename ) {
4700
- errors . push ( createFileDiagnostic ( refFile , refStart , refLength ,
4701
- Diagnostics . Filename_0_differs_from_already_included_filename_1_only_in_casing , filename , file . filename ) ) ;
4702
- }
4706
+ return getSourceFileFromCache ( filename , canonicalName , /*useAbsolutePath*/ false ) ;
4703
4707
}
4704
4708
else {
4709
+ var normalizedAbsolutePath = getNormalizedAbsolutePath ( filename , host . getCurrentDirectory ( ) ) ;
4710
+ var canonicalAbsolutePath = host . getCanonicalFileName ( normalizedAbsolutePath ) ;
4711
+ if ( hasProperty ( filesByName , canonicalAbsolutePath ) ) {
4712
+ return getSourceFileFromCache ( normalizedAbsolutePath , canonicalAbsolutePath , /*useAbsolutePath*/ true ) ;
4713
+ }
4714
+
4705
4715
// We haven't looked for this file, do so now and cache result
4706
4716
var file = filesByName [ canonicalName ] = host . getSourceFile ( filename , options . target , hostErrorMessage => {
4707
4717
errors . push ( createFileDiagnostic ( refFile , refStart , refLength ,
4708
4718
Diagnostics . Cannot_read_file_0_Colon_1 , filename , hostErrorMessage ) ) ;
4709
4719
} ) ;
4710
4720
if ( file ) {
4711
4721
seenNoDefaultLib = seenNoDefaultLib || file . hasNoDefaultLib ;
4722
+
4723
+ // Set the source file for normalized absolute path
4724
+ filesByName [ canonicalAbsolutePath ] = file ;
4725
+
4712
4726
if ( ! options . noResolve ) {
4713
4727
var basePath = getDirectoryPath ( filename ) ;
4714
4728
processReferencedFiles ( file , basePath ) ;
@@ -4726,6 +4740,18 @@ module ts {
4726
4740
}
4727
4741
}
4728
4742
return file ;
4743
+
4744
+ function getSourceFileFromCache ( filename : string , canonicalName : string , useAbsolutePath : boolean ) : SourceFile {
4745
+ var file = filesByName [ canonicalName ] ;
4746
+ if ( file && host . useCaseSensitiveFileNames ( ) ) {
4747
+ var sourceFileName = useAbsolutePath ? getNormalizedAbsolutePath ( file . filename , host . getCurrentDirectory ( ) ) : file . filename ;
4748
+ if ( canonicalName !== sourceFileName ) {
4749
+ errors . push ( createFileDiagnostic ( refFile , refStart , refLength ,
4750
+ Diagnostics . Filename_0_differs_from_already_included_filename_1_only_in_casing , filename , sourceFileName ) ) ;
4751
+ }
4752
+ }
4753
+ return file ;
4754
+ }
4729
4755
}
4730
4756
4731
4757
function processReferencedFiles ( file : SourceFile , basePath : string ) {
0 commit comments