@@ -925,22 +925,46 @@ namespace ts {
925925 }
926926
927927 /** Return the file if it exists. */
928- function tryFile ( fileName : string , failedLookupLocations : Push < string > , onlyRecordFailures : boolean , state : ModuleResolutionState ) : string | undefined {
929- if ( ! onlyRecordFailures ) {
930- if ( state . host . fileExists ( fileName ) ) {
931- if ( state . traceEnabled ) {
932- trace ( state . host , Diagnostics . File_0_exist_use_it_as_a_name_resolution_result , fileName ) ;
928+ function tryFile ( file : string , failedLookupLocations : Push < string > , onlyRecordFailures : boolean , state : ModuleResolutionState ) : string | undefined {
929+
930+ if ( state . compilerOptions . resolutionPlatforms ) {
931+ for ( let platform of state . compilerOptions . resolutionPlatforms ) {
932+ let result = tryFileInner ( platform ) ;
933+ if ( result ) {
934+ return result ;
933935 }
934- return fileName ;
935936 }
936- else {
937- if ( state . traceEnabled ) {
938- trace ( state . host , Diagnostics . File_0_does_not_exist , fileName ) ;
937+ }
938+
939+ return tryFileInner ( null ) ;
940+
941+ function tryFileInner ( platform : string ) : string | undefined {
942+
943+ let fileName = file ;
944+ if ( platform ) {
945+ let lastDot = file . lastIndexOf ( '.' ) ;
946+ if ( lastDot === - 1 ) {
947+ return undefined ;
948+ }
949+ fileName = file . slice ( 0 , lastDot + 1 ) + platform + file . slice ( lastDot ) ;
950+ }
951+
952+ if ( ! onlyRecordFailures ) {
953+ if ( state . host . fileExists ( fileName ) ) {
954+ if ( state . traceEnabled ) {
955+ trace ( state . host , Diagnostics . File_0_exist_use_it_as_a_name_resolution_result , fileName ) ;
956+ }
957+ return fileName ;
958+ }
959+ else {
960+ if ( state . traceEnabled ) {
961+ trace ( state . host , Diagnostics . File_0_does_not_exist , fileName ) ;
962+ }
939963 }
940964 }
965+ failedLookupLocations . push ( fileName ) ;
966+ return undefined ;
941967 }
942- failedLookupLocations . push ( fileName ) ;
943- return undefined ;
944968 }
945969
946970 function loadNodeModuleFromDirectory ( extensions : Extensions , candidate : string , failedLookupLocations : Push < string > , onlyRecordFailures : boolean , state : ModuleResolutionState , considerPackageJson = true ) {
0 commit comments