@@ -29,6 +29,7 @@ namespace ts {
29
29
path : string ;
30
30
extension : Extension ;
31
31
packageId : PackageId | undefined ;
32
+ originalPath ?: string | true ;
32
33
}
33
34
34
35
/** Result of trying to resolve a module at a file. Needs to have 'packageId' added later. */
@@ -62,9 +63,9 @@ namespace ts {
62
63
return { fileName : resolved . path , packageId : resolved . packageId } ;
63
64
}
64
65
65
- function createResolvedModuleWithFailedLookupLocations ( resolved : Resolved | undefined , originalPath : string | undefined , isExternalLibraryImport : boolean , failedLookupLocations : string [ ] ) : ResolvedModuleWithFailedLookupLocations {
66
+ function createResolvedModuleWithFailedLookupLocations ( resolved : Resolved | undefined , isExternalLibraryImport : boolean , failedLookupLocations : string [ ] ) : ResolvedModuleWithFailedLookupLocations {
66
67
return {
67
- resolvedModule : resolved && { resolvedFileName : resolved . path , originalPath, extension : resolved . extension , isExternalLibraryImport, packageId : resolved . packageId } ,
68
+ resolvedModule : resolved && { resolvedFileName : resolved . path , originalPath : resolved . originalPath === true ? undefined : resolved . originalPath , extension : resolved . extension , isExternalLibraryImport, packageId : resolved . packageId } ,
68
69
failedLookupLocations
69
70
} ;
70
71
}
@@ -754,12 +755,12 @@ namespace ts {
754
755
tryResolve ( Extensions . JavaScript ) ||
755
756
( compilerOptions . resolveJsonModule ? tryResolve ( Extensions . Json ) : undefined ) ) ;
756
757
if ( result && result . value ) {
757
- const { resolved, originalPath , isExternalLibraryImport } = result . value ;
758
- return createResolvedModuleWithFailedLookupLocations ( resolved , originalPath , isExternalLibraryImport , failedLookupLocations ) ;
758
+ const { resolved, isExternalLibraryImport } = result . value ;
759
+ return createResolvedModuleWithFailedLookupLocations ( resolved , isExternalLibraryImport , failedLookupLocations ) ;
759
760
}
760
761
return { resolvedModule : undefined , failedLookupLocations } ;
761
762
762
- function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , originalPath ?: string , isExternalLibraryImport : boolean } > {
763
+ function tryResolve ( extensions : Extensions ) : SearchResult < { resolved : Resolved , isExternalLibraryImport : boolean } > {
763
764
const loader : ResolutionKindSpecificLoader = ( extensions , candidate , failedLookupLocations , onlyRecordFailures , state ) => nodeLoadModuleByRelativeName ( extensions , candidate , failedLookupLocations , onlyRecordFailures , state , /*considerPackageJson*/ true ) ;
764
765
const resolved = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loader , failedLookupLocations , state ) ;
765
766
if ( resolved ) {
@@ -774,17 +775,13 @@ namespace ts {
774
775
if ( ! resolved ) return undefined ;
775
776
776
777
let resolvedValue = resolved . value ;
777
- let originalPath : string | undefined ;
778
- if ( ! compilerOptions . preserveSymlinks && resolvedValue ) {
779
- originalPath = resolvedValue . path ;
778
+ if ( ! compilerOptions . preserveSymlinks && resolvedValue && ! resolvedValue . originalPath ) {
780
779
const path = realPath ( resolvedValue . path , host , traceEnabled ) ;
781
- if ( path === originalPath ) {
782
- originalPath = undefined ;
783
- }
784
- resolvedValue = { ...resolvedValue , path } ;
780
+ const originalPath = path === resolvedValue . path ? undefined : resolvedValue . path ;
781
+ resolvedValue = { ...resolvedValue , path, originalPath } ;
785
782
}
786
783
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
787
- return { value : resolvedValue && { resolved : resolvedValue , originalPath , isExternalLibraryImport : true } } ;
784
+ return { value : resolvedValue && { resolved : resolvedValue , isExternalLibraryImport : true } } ;
788
785
}
789
786
else {
790
787
const { path : candidate , parts } = normalizePathAndParts ( combinePaths ( containingDirectory , moduleName ) ) ;
@@ -1234,7 +1231,7 @@ namespace ts {
1234
1231
trace ( host , Diagnostics . Resolution_for_module_0_was_found_in_cache_from_location_1 , moduleName , containingDirectory ) ;
1235
1232
}
1236
1233
failedLookupLocations . push ( ...result . failedLookupLocations ) ;
1237
- return { value : result . resolvedModule && { path : result . resolvedModule . resolvedFileName , extension : result . resolvedModule . extension , packageId : result . resolvedModule . packageId } } ;
1234
+ return { value : result . resolvedModule && { path : result . resolvedModule . resolvedFileName , originalPath : result . resolvedModule . originalPath || true , extension : result . resolvedModule . extension , packageId : result . resolvedModule . packageId } } ;
1238
1235
}
1239
1236
}
1240
1237
@@ -1246,7 +1243,7 @@ namespace ts {
1246
1243
1247
1244
const resolved = tryResolve ( Extensions . TypeScript ) || tryResolve ( Extensions . JavaScript ) ;
1248
1245
// No originalPath because classic resolution doesn't resolve realPath
1249
- return createResolvedModuleWithFailedLookupLocations ( resolved && resolved . value , /*originalPath*/ undefined , /* isExternalLibraryImport*/ false , failedLookupLocations ) ;
1246
+ return createResolvedModuleWithFailedLookupLocations ( resolved && resolved . value , /*isExternalLibraryImport*/ false , failedLookupLocations ) ;
1250
1247
1251
1248
function tryResolve ( extensions : Extensions ) : SearchResult < Resolved > {
1252
1249
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings ( extensions , moduleName , containingDirectory , loadModuleFromFileNoPackageId , failedLookupLocations , state ) ;
@@ -1293,7 +1290,7 @@ namespace ts {
1293
1290
const state : ModuleResolutionState = { compilerOptions, host, traceEnabled } ;
1294
1291
const failedLookupLocations : string [ ] = [ ] ;
1295
1292
const resolved = loadModuleFromNodeModulesOneLevel ( Extensions . DtsOnly , moduleName , globalCache , failedLookupLocations , state ) ;
1296
- return createResolvedModuleWithFailedLookupLocations ( resolved , /*originalPath*/ undefined , /* isExternalLibraryImport*/ true , failedLookupLocations ) ;
1293
+ return createResolvedModuleWithFailedLookupLocations ( resolved , /*isExternalLibraryImport*/ true , failedLookupLocations ) ;
1297
1294
}
1298
1295
1299
1296
/**
0 commit comments