MCPcopy Create free account
hub / github.com/microsoft/typescript-go / pathForLibFile

Method pathForLibFile

internal/compiler/fileloader.go:644–668  ·  view source on GitHub ↗
(name string)

Source from the content-addressed store, hash-verified

642}
643
644func (p *fileLoader) pathForLibFile(name string) *LibFile {
645 if cached, ok := p.pathForLibFileCache.Load(name); ok {
646 return cached
647 }
648
649 path := tspath.CombinePaths(p.defaultLibraryPath, name)
650 replaced := false
651 if p.opts.Config.CompilerOptions().LibReplacement.IsTrue() && name != "lib.d.ts" {
652 libraryName := getLibraryNameFromLibFileName(name)
653 resolveFrom := getInferredLibraryNameResolveFrom(p.opts.Config.CompilerOptions(), p.opts.Host.GetCurrentDirectory(), name)
654 resolution, trace := p.resolveLibrary(libraryName, resolveFrom)
655 if resolution.IsResolved() {
656 path = resolution.ResolvedFileName
657 replaced = true
658 }
659 p.pathForLibFileResolutions.LoadOrStore(p.toPath(resolveFrom), &libResolution{
660 libraryName: libraryName,
661 resolution: resolution,
662 trace: trace,
663 })
664 }
665
666 libPath, _ := p.pathForLibFileCache.LoadOrStore(name, &LibFile{name, path, replaced})
667 return libPath
668}
669
670func (p *fileLoader) resolveLibrary(libraryName, resolveFrom string) (*module.ResolvedModule, []module.DiagAndArgs) {
671 if tr := p.opts.Tracing; tr != nil {

Callers 2

processAllProgramFilesFunction · 0.95
loadMethod · 0.80

Calls 11

resolveLibraryMethod · 0.95
toPathMethod · 0.95
CombinePathsFunction · 0.92
IsTrueMethod · 0.80
CompilerOptionsMethod · 0.65
GetCurrentDirectoryMethod · 0.65
LoadMethod · 0.45
IsResolvedMethod · 0.45
LoadOrStoreMethod · 0.45

Tested by

no test coverage detected