@@ -15,6 +15,12 @@ import (
15
15
"github.com/microsoft/typescript-go/internal/tspath"
16
16
)
17
17
18
+ type libResolution struct {
19
+ libraryName string
20
+ resolution * module.ResolvedModule
21
+ trace []string
22
+ }
23
+
18
24
type fileLoader struct {
19
25
opts ProgramOptions
20
26
resolver * module.Resolver
@@ -35,7 +41,7 @@ type fileLoader struct {
35
41
dtsDirectories collections.Set [tspath.Path ]
36
42
37
43
pathForLibFileCache collections.SyncMap [string , string ]
38
- pathForLibFileResolutions collections.SyncMap [tspath.Path , module. ModeAwareCache [ * module. ResolvedModule ] ]
44
+ pathForLibFileResolutions collections.SyncMap [tspath.Path , * libResolution ]
39
45
}
40
46
41
47
type processedFiles struct {
@@ -200,12 +206,15 @@ func processAllProgramFiles(
200
206
}
201
207
}
202
208
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 )
209
218
}
210
219
return true
211
220
})
@@ -255,15 +264,17 @@ func (p *fileLoader) addAutomaticTypeDirectiveTasks() {
255
264
func (p * fileLoader ) resolveAutomaticTypeDirectives (containingFileName string ) (
256
265
toParse []resolvedRef ,
257
266
typeResolutionsInFile module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ],
267
+ typeResolutionsTrace []string ,
258
268
) {
259
269
automaticTypeDirectiveNames := module .GetAutomaticTypeDirectiveNames (p .opts .Config .CompilerOptions (), p .opts .Host )
260
270
if len (automaticTypeDirectiveNames ) != 0 {
261
271
toParse = make ([]resolvedRef , 0 , len (automaticTypeDirectiveNames ))
262
272
typeResolutionsInFile = make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (automaticTypeDirectiveNames ))
263
273
for _ , name := range automaticTypeDirectiveNames {
264
274
resolutionMode := core .ModuleKindNodeNext
265
- resolved := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , resolutionMode , nil )
275
+ resolved , trace := p .resolver .ResolveTypeReferenceDirective (name , containingFileName , resolutionMode , nil )
266
276
typeResolutionsInFile [module.ModeAwareCacheKey {Name : name , Mode : resolutionMode }] = resolved
277
+ typeResolutionsTrace = append (typeResolutionsTrace , trace ... )
267
278
if resolved .IsResolved () {
268
279
toParse = append (toParse , resolvedRef {
269
280
fileName : resolved .ResolvedFileName ,
@@ -273,7 +284,7 @@ func (p *fileLoader) resolveAutomaticTypeDirectives(containingFileName string) (
273
284
}
274
285
}
275
286
}
276
- return toParse , typeResolutionsInFile
287
+ return toParse , typeResolutionsInFile , typeResolutionsTrace
277
288
}
278
289
279
290
func (p * fileLoader ) addProjectReferenceTasks (singleThreaded bool ) {
@@ -393,11 +404,13 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
393
404
meta := t .metadata
394
405
395
406
typeResolutionsInFile := make (module.ModeAwareCache [* module.ResolvedTypeReferenceDirective ], len (file .TypeReferenceDirectives ))
407
+ var typeResolutionsTrace []string
396
408
for _ , ref := range file .TypeReferenceDirectives {
397
409
redirect := p .projectReferenceFileMapper .getRedirectForResolution (file )
398
410
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 )
400
412
typeResolutionsInFile [module.ModeAwareCacheKey {Name : ref .FileName , Mode : resolutionMode }] = resolved
413
+ typeResolutionsTrace = append (typeResolutionsTrace , trace ... )
401
414
402
415
if resolved .IsResolved () {
403
416
t .addSubTask (resolvedRef {
@@ -410,6 +423,7 @@ func (p *fileLoader) resolveTypeReferenceDirectives(t *parseTask) {
410
423
}
411
424
412
425
t .typeResolutionsInFile = typeResolutionsInFile
426
+ t .typeResolutionsTrace = typeResolutionsTrace
413
427
}
414
428
415
429
const externalHelpersModuleNameText = "tslib" // TODO(jakebailey): dedupe
@@ -455,6 +469,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
455
469
456
470
if len (moduleNames ) != 0 {
457
471
resolutionsInFile := make (module.ModeAwareCache [* module.ResolvedModule ], len (moduleNames ))
472
+ var resolutionsTrace []string
458
473
459
474
for index , entry := range moduleNames {
460
475
moduleName := entry .Text ()
@@ -463,8 +478,9 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
463
478
}
464
479
465
480
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 )
467
482
resolutionsInFile [module.ModeAwareCacheKey {Name : moduleName , Mode : mode }] = resolvedModule
483
+ resolutionsTrace = append (resolutionsTrace , trace ... )
468
484
469
485
if ! resolvedModule .IsResolved () {
470
486
continue
@@ -501,6 +517,7 @@ func (p *fileLoader) resolveImportsAndModuleAugmentations(t *parseTask) {
501
517
}
502
518
503
519
t .resolutionsInFile = resolutionsInFile
520
+ t .resolutionsTrace = resolutionsTrace
504
521
}
505
522
}
506
523
@@ -526,11 +543,13 @@ func (p *fileLoader) pathForLibFile(name string) string {
526
543
if p .opts .Config .CompilerOptions ().LibReplacement .IsTrue () {
527
544
libraryName := getLibraryNameFromLibFileName (name )
528
545
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 )
530
547
if resolution .IsResolved () {
531
548
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 ,
534
553
})
535
554
}
536
555
}
0 commit comments