@@ -15,6 +15,12 @@ import (
1515 "github.com/microsoft/typescript-go/internal/tspath"
1616)
1717
18+ type libResolution struct {
19+ libraryName string
20+ resolution * module.ResolvedModule
21+ trace []string
22+ }
23+
1824type fileLoader struct {
1925 opts ProgramOptions
2026 resolver * module.Resolver
@@ -35,7 +41,7 @@ type fileLoader struct {
3541 dtsDirectories collections.Set [tspath.Path ]
3642
3743 pathForLibFileCache collections.SyncMap [string , string ]
38- pathForLibFileResolutions collections.SyncMap [tspath.Path , module. ModeAwareCache [ * module. ResolvedModule ] ]
44+ pathForLibFileResolutions collections.SyncMap [tspath.Path , * libResolution ]
3945}
4046
4147type processedFiles struct {
@@ -200,12 +206,15 @@ func processAllProgramFiles(
200206 }
201207 }
202208
203- loader .pathForLibFileResolutions .Range (func (key tspath.Path , value module.ModeAwareCache [* module.ResolvedModule ]) bool {
204- resolvedModules [key ] = value
205- for _ , resolvedModule := range value {
206- for _ , diag := range resolvedModule .ResolutionDiagnostics {
207- fileLoadDiagnostics .Add (diag )
208- }
209+ loader .pathForLibFileResolutions .Range (func (key tspath.Path , value * libResolution ) bool {
210+ resolvedModules [key ] = module.ModeAwareCache [* module.ResolvedModule ]{
211+ module.ModeAwareCacheKey {Name : value .libraryName , Mode : core .ModuleKindCommonJS }: value .resolution ,
212+ }
213+ for _ , trace := range value .trace {
214+ opts .Host .Trace (trace )
215+ }
216+ for _ , diag := range value .resolution .ResolutionDiagnostics {
217+ fileLoadDiagnostics .Add (diag )
209218 }
210219 return true
211220 })
@@ -255,15 +264,17 @@ func (p *fileLoader) addAutomaticTypeDirectiveTasks() {
255264func (p * fileLoader ) resolveAutomaticTypeDirectives (containingFileName string ) (
256265 toParse []resolvedRef ,
257266 typeResolutionsInFile module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ],
267+ typeResolutionsTrace []string ,
258268) {
259269 automaticTypeDirectiveNames := module .GetAutomaticTypeDirectiveNames (p .opts .Config .CompilerOptions (), p .opts .Host )
260270 if len (automaticTypeDirectiveNames ) != 0 {
261271 toParse = make ([]resolvedRef , 0 , len (automaticTypeDirectiveNames ))
262272 typeResolutionsInFile = make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (automaticTypeDirectiveNames ))
263273 for _ , name := range automaticTypeDirectiveNames {
264274 resolutionMode := core .ModuleKindNodeNext
265- resolved := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , resolutionMode , nil )
275+ resolved , trace := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , resolutionMode , nil )
266276 typeResolutionsInFile [module.ModeAwareCacheKey {Name : name , Mode : resolutionMode }] = resolved
277+ typeResolutionsTrace = append (typeResolutionsTrace , trace ... )
267278 if resolved .IsResolved () {
268279 toParse = append (toParse , resolvedRef {
269280 fileName : resolved .ResolvedFileName ,
@@ -273,7 +284,7 @@ func (p *fileLoader) resolveAutomaticTypeDirectives(containingFileName string) (
273284 }
274285 }
275286 }
276- return toParse , typeResolutionsInFile
287+ return toParse , typeResolutionsInFile , typeResolutionsTrace
277288}
278289
279290func (p * fileLoader ) addProjectReferenceTasks (singleThreaded bool ) {
@@ -393,11 +404,13 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
393404 meta := t .metadata
394405
395406 typeResolutionsInFile := make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (file .TypeReferenceDirectives ))
407+ var typeResolutionsTrace []string
396408 for _ , ref := range file .TypeReferenceDirectives {
397409 redirect := p .projectReferenceFileMapper .getRedirectForResolution (file )
398410 resolutionMode := getModeForTypeReferenceDirectiveInFile (ref , file , meta , module .GetCompilerOptionsWithRedirect (p .opts .Config .CompilerOptions (), redirect ))
399- resolved := p .resolver .ResolveTypeReferenceDirective (ref .FileName , file .FileName (), resolutionMode , redirect )
411+ resolved , trace := p .resolver .ResolveTypeReferenceDirective (ref .FileName , file .FileName (), resolutionMode , redirect )
400412 typeResolutionsInFile [module.ModeAwareCacheKey {Name : ref .FileName , Mode : resolutionMode }] = resolved
413+ typeResolutionsTrace = append (typeResolutionsTrace , trace ... )
401414
402415 if resolved .IsResolved () {
403416 t .addSubTask (resolvedRef {
@@ -410,6 +423,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
410423 }
411424
412425 t .typeResolutionsInFile = typeResolutionsInFile
426+ t .typeResolutionsTrace = typeResolutionsTrace
413427}
414428
415429const externalHelpersModuleNameText = "tslib" // TODO(jakebailey): dedupe
@@ -455,6 +469,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
455469
456470 if len (moduleNames ) != 0 {
457471 resolutionsInFile := make (module.ModeAwareCache [* module.ResolvedModule ], len (moduleNames ))
472+ var resolutionsTrace []string
458473
459474 for index , entry := range moduleNames {
460475 moduleName := entry .Text ()
@@ -463,8 +478,9 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
463478 }
464479
465480 mode := getModeForUsageLocation (file .FileName (), meta , entry , optionsForFile )
466- resolvedModule := p .resolver .ResolveModuleName (moduleName , file .FileName (), mode , redirect )
481+ resolvedModule , trace := p .resolver .ResolveModuleName (moduleName , file .FileName (), mode , redirect )
467482 resolutionsInFile [module.ModeAwareCacheKey {Name : moduleName , Mode : mode }] = resolvedModule
483+ resolutionsTrace = append (resolutionsTrace , trace ... )
468484
469485 if ! resolvedModule .IsResolved () {
470486 continue
@@ -501,6 +517,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
501517 }
502518
503519 t .resolutionsInFile = resolutionsInFile
520+ t .resolutionsTrace = resolutionsTrace
504521 }
505522}
506523
@@ -526,11 +543,13 @@ func (p *fileLoader) pathForLibFile(name string) string {
526543 if p .opts .Config .CompilerOptions ().LibReplacement .IsTrue () {
527544 libraryName := getLibraryNameFromLibFileName (name )
528545 resolveFrom := getInferredLibraryNameResolveFrom (p .opts .Config .CompilerOptions (), p .opts .Host .GetCurrentDirectory (), name )
529- resolution := p .resolver .ResolveModuleName (libraryName , resolveFrom , core .ModuleKindCommonJS , nil )
546+ resolution , trace := p .resolver .ResolveModuleName (libraryName , resolveFrom , core .ModuleKindCommonJS , nil )
530547 if resolution .IsResolved () {
531548 path = resolution .ResolvedFileName
532- p .pathForLibFileResolutions .LoadOrStore (p .toPath (resolveFrom ), module.ModeAwareCache [* module.ResolvedModule ]{
533- module.ModeAwareCacheKey {Name : libraryName , Mode : core .ModuleKindCommonJS }: resolution ,
549+ p .pathForLibFileResolutions .LoadOrStore (p .toPath (resolveFrom ), & libResolution {
550+ libraryName : libraryName ,
551+ resolution : resolution ,
552+ trace : trace ,
534553 })
535554 }
536555 }
0 commit comments