@@ -143,7 +143,10 @@ func processAllProgramFiles(
143143
144144 filesByPath := make (map [tspath.Path ]* ast.SourceFile , totalFileCount )
145145 loader .includeProcessor .fileIncludeReasons = make (map [tspath.Path ][]* fileIncludeReason , totalFileCount )
146- outputFileToProjectReferenceSource := make (map [tspath.Path ]string , totalFileCount )
146+ var outputFileToProjectReferenceSource map [tspath.Path ]string
147+ if ! opts .canUseProjectReferenceSource () {
148+ outputFileToProjectReferenceSource = make (map [tspath.Path ]string , totalFileCount )
149+ }
147150 resolvedModules := make (map [tspath.Path ]module.ModeAwareCache [* module.ResolvedModule ], totalFileCount + 1 )
148151 typeResolutionsInFile := make (map [tspath.Path ]module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], totalFileCount )
149152 sourceFileMetaDatas := make (map [tspath.Path ]ast.SourceFileMetaData , totalFileCount )
@@ -454,9 +457,9 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
454457 typeResolutionsInFile := make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (file .TypeReferenceDirectives ))
455458 var typeResolutionsTrace []string
456459 for index , ref := range file .TypeReferenceDirectives {
457- redirect := p .projectReferenceFileMapper .getRedirectForResolution (file )
460+ redirect , fileName := p .projectReferenceFileMapper .getRedirectForResolution (file )
458461 resolutionMode := getModeForTypeReferenceDirectiveInFile (ref , file , meta , module .GetCompilerOptionsWithRedirect (p .opts .Config .CompilerOptions (), redirect ))
459- resolved , trace := p .resolver .ResolveTypeReferenceDirective (ref .FileName , file . FileName () , resolutionMode , redirect )
462+ resolved , trace := p .resolver .ResolveTypeReferenceDirective (ref .FileName , fileName , resolutionMode , redirect )
460463 typeResolutionsInFile [module.ModeAwareCacheKey {Name : ref .FileName , Mode : resolutionMode }] = resolved
461464 includeReason := & fileIncludeReason {
462465 kind : fileIncludeKindTypeReferenceDirective ,
@@ -498,7 +501,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
498501 isJavaScriptFile := ast .IsSourceFileJS (file )
499502 isExternalModuleFile := ast .IsExternalModule (file )
500503
501- redirect := p .projectReferenceFileMapper .getRedirectForResolution (file )
504+ redirect , fileName := p .projectReferenceFileMapper .getRedirectForResolution (file )
502505 optionsForFile := module .GetCompilerOptionsWithRedirect (p .opts .Config .CompilerOptions (), redirect )
503506 if isJavaScriptFile || (! file .IsDeclarationFile && (optionsForFile .GetIsolatedModules () || isExternalModuleFile )) {
504507 if optionsForFile .ImportHelpers .IsTrue () {
@@ -539,7 +542,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
539542 }
540543
541544 mode := getModeForUsageLocation (file .FileName (), meta , entry , optionsForFile )
542- resolvedModule , trace := p .resolver .ResolveModuleName (moduleName , file . FileName () , mode , redirect )
545+ resolvedModule , trace := p .resolver .ResolveModuleName (moduleName , fileName , mode , redirect )
543546 resolutionsInFile [module.ModeAwareCacheKey {Name : moduleName , Mode : mode }] = resolvedModule
544547 resolutionsTrace = append (resolutionsTrace , trace ... )
545548
@@ -550,7 +553,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
550553 resolvedFileName := resolvedModule .ResolvedFileName
551554 isFromNodeModulesSearch := resolvedModule .IsExternalLibraryImport
552555 // Don't treat redirected files as JS files.
553- isJsFile := ! tspath .FileExtensionIsOneOf (resolvedFileName , tspath .SupportedTSExtensionsWithJsonFlat ) && p .projectReferenceFileMapper .getRedirectForResolution (ast .NewHasFileName (resolvedFileName , p .toPath (resolvedFileName ))) == nil
556+ isJsFile := ! tspath .FileExtensionIsOneOf (resolvedFileName , tspath .SupportedTSExtensionsWithJsonFlat ) && p .projectReferenceFileMapper .getRedirectParsedCommandLineForResolution (ast .NewHasFileName (resolvedFileName , p .toPath (resolvedFileName ))) == nil
554557 isJsFileFromNodeModules := isFromNodeModulesSearch && isJsFile && strings .Contains (resolvedFileName , "/node_modules/" )
555558
556559 // add file to program only if:
@@ -610,19 +613,19 @@ func (p *fileLoader) pathForLibFile(name string) *LibFile {
610613
611614 path := tspath .CombinePaths (p .defaultLibraryPath , name )
612615 replaced := false
613- if p .opts .Config .CompilerOptions ().LibReplacement .IsTrue () {
616+ if p .opts .Config .CompilerOptions ().LibReplacement .IsTrue () && name != "lib.d.ts" {
614617 libraryName := getLibraryNameFromLibFileName (name )
615618 resolveFrom := getInferredLibraryNameResolveFrom (p .opts .Config .CompilerOptions (), p .opts .Host .GetCurrentDirectory (), name )
616619 resolution , trace := p .resolver .ResolveModuleName (libraryName , resolveFrom , core .ModuleKindCommonJS , nil )
617620 if resolution .IsResolved () {
618621 path = resolution .ResolvedFileName
619622 replaced = true
620- p .pathForLibFileResolutions .LoadOrStore (p .toPath (resolveFrom ), & libResolution {
621- libraryName : libraryName ,
622- resolution : resolution ,
623- trace : trace ,
624- })
625623 }
624+ p .pathForLibFileResolutions .LoadOrStore (p .toPath (resolveFrom ), & libResolution {
625+ libraryName : libraryName ,
626+ resolution : resolution ,
627+ trace : trace ,
628+ })
626629 }
627630
628631 libPath , _ := p .pathForLibFileCache .LoadOrStore (name , & LibFile {name , path , replaced })
0 commit comments