Skip to content

Commit 44be1f4

Browse files
Index libraries by name
Co-authored-by: DanielRosenwasser <[email protected]>
1 parent 81167b9 commit 44be1f4

3 files changed

Lines changed: 11 additions & 12 deletions

File tree

‎tsc/internal/compiler/fileloader.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ type processedFiles struct {
125125
sourceFileMetaDatas map[tspath.Path]ast.SourceFileMetaData
126126
jsxRuntimeImportSpecifiers map[tspath.Path]*jsxRuntimeImportSpecifier
127127
importHelpersImportSpecifiers map[tspath.Path]*ast.StringLiteralNode
128-
libFiles map[tspath.Path]*LibFile
128+
libFiles map[string]*ast.SourceFile
129+
libFilesByPath map[tspath.Path]*LibFile
129130
// List of present unsupported extensions
130131
sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
131132
includeProcessor *includeProcessor

‎tsc/internal/compiler/filesparser.go‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
357357
var jsxRuntimeImportSpecifiers map[tspath.Path]*jsxRuntimeImportSpecifier
358358
var importHelpersImportSpecifiers map[tspath.Path]*ast.StringLiteralNode
359359
var sourceFilesFoundSearchingNodeModules collections.Set[tspath.Path]
360-
libFilesMap := make(map[tspath.Path]*LibFile, libFileCount)
360+
libFilesMap := make(map[string]*ast.SourceFile, libFileCount)
361+
libFilesByPath := make(map[tspath.Path]*LibFile, libFileCount)
361362

362363
var redirectTargetsMap map[tspath.Path][]string
363364
var redirectFilesByPath map[tspath.Path]*redirectsFile
@@ -515,7 +516,8 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
515516

516517
if task.libFile != nil {
517518
libFiles = append(libFiles, file)
518-
libFilesMap[path] = task.libFile
519+
libFilesMap[task.libFile.Name] = file
520+
libFilesByPath[path] = task.libFile
519521
} else {
520522
files = append(files, file)
521523
}
@@ -576,6 +578,7 @@ func (w *filesParser) getProcessedFiles(loader *fileLoader) processedFiles {
576578
importHelpersImportSpecifiers: importHelpersImportSpecifiers,
577579
sourceFilesFoundSearchingNodeModules: sourceFilesFoundSearchingNodeModules,
578580
libFiles: libFilesMap,
581+
libFilesByPath: libFilesByPath,
579582
missingFiles: missingFiles,
580583
includeProcessor: includeProcessor,
581584
outputFileToProjectReferenceSource: outputFileToProjectReferenceSource,

‎tsc/internal/compiler/program.go‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ func (p *Program) GetDefaultResolutionModeForFile(sourceFile ast.HasFileName) co
17101710
}
17111711

17121712
func (p *Program) IsSourceFileDefaultLibrary(path tspath.Path) bool {
1713-
_, ok := p.libFiles[path]
1713+
_, ok := p.libFilesByPath[path]
17141714
return ok
17151715
}
17161716

@@ -1722,7 +1722,7 @@ func (p *Program) IsGlobalTypingsFile(fileName string) bool {
17221722
}
17231723

17241724
func (p *Program) GetDefaultLibFile(path tspath.Path) *LibFile {
1725-
if libFile, ok := p.libFiles[path]; ok {
1725+
if libFile, ok := p.libFilesByPath[path]; ok {
17261726
return libFile
17271727
}
17281728
return nil
@@ -2091,12 +2091,7 @@ func (p *Program) GetLibFileFromReference(ref *ast.FileReference) *ast.SourceFil
20912091
if !ok {
20922092
return nil
20932093
}
2094-
for path, libFile := range p.libFiles {
2095-
if libFile.Name == name {
2096-
return p.filesByPath[path]
2097-
}
2098-
}
2099-
return nil
2094+
return p.libFiles[name]
21002095
}
21012096

21022097
func (p *Program) GetResolvedTypeReferenceDirectiveFromTypeReferenceDirective(typeRef *ast.FileReference, sourceFile *ast.SourceFile) *module.ResolvedTypeReferenceDirective {
@@ -2208,7 +2203,7 @@ func (p *Program) collectPackageNames() *packageNamesInfo {
22082203
}
22092204

22102205
func (p *Program) IsLibFile(sourceFile *ast.SourceFile) bool {
2211-
_, ok := p.libFiles[sourceFile.Path()]
2206+
_, ok := p.libFilesByPath[sourceFile.Path()]
22122207
return ok
22132208
}
22142209

0 commit comments

Comments
 (0)