From bdb5cba1b149f49fdcba5e8af569951e6e3c4d89 Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Sat, 21 Jun 2025 15:42:39 -0700
Subject: [PATCH 1/7] Begin libReplacement
---
internal/compiler/fileloader.go | 22 ++++++++++++++++++++--
internal/compiler/program.go | 32 ++------------------------------
2 files changed, 22 insertions(+), 32 deletions(-)
diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go
index 9396bc89d5..e7dce2f418 100644
--- a/internal/compiler/fileloader.go
+++ b/internal/compiler/fileloader.go
@@ -59,7 +59,6 @@ type jsxRuntimeImportSpecifier struct {
func processAllProgramFiles(
opts ProgramOptions,
- libs []string,
singleThreaded bool,
) processedFiles {
compilerOptions := opts.Config.CompilerOptions()
@@ -83,11 +82,30 @@ func processAllProgramFiles(
projectReferenceParseTasks: &fileLoaderWorker[*projectReferenceParseTask]{
wg: core.NewWorkGroup(singleThreaded),
},
- rootTasks: make([]*parseTask, 0, len(rootFiles)+len(libs)),
supportedExtensions: core.Flatten(tsoptions.GetSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, supportedExtensions)),
}
loader.addProjectReferenceTasks()
loader.resolver = module.NewResolver(loader.projectReferenceFileMapper.host, compilerOptions, opts.TypingsLocation, opts.ProjectName)
+
+ // TODO(jakebailey): libReplacement
+
+ var libs []string
+ if compilerOptions.NoLib != core.TSTrue {
+ if compilerOptions.Lib == nil {
+ name := tsoptions.GetDefaultLibFileName(compilerOptions)
+ libs = append(libs, tspath.CombinePaths(opts.Host.DefaultLibraryPath(), name))
+ } else {
+ for _, lib := range compilerOptions.Lib {
+ name, ok := tsoptions.GetLibFileName(lib)
+ if ok {
+ libs = append(libs, tspath.CombinePaths(opts.Host.DefaultLibraryPath(), name))
+ }
+ // !!! error on unknown name
+ }
+ }
+ }
+
+ loader.rootTasks = make([]*parseTask, 0, len(rootFiles)+len(libs))
loader.addRootTasks(rootFiles, false)
loader.addRootTasks(libs, true)
loader.addAutomaticTypeDirectiveTasks()
diff --git a/internal/compiler/program.go b/internal/compiler/program.go
index 7cddb367a2..bc87837fca 100644
--- a/internal/compiler/program.go
+++ b/internal/compiler/program.go
@@ -172,37 +172,9 @@ func (p *Program) GetSourceFileFromReference(origin *ast.SourceFile, ref *ast.Fi
}
func NewProgram(opts ProgramOptions) *Program {
- p := &Program{
- opts: opts,
- }
- compilerOptions := p.opts.Config.CompilerOptions()
- if compilerOptions == nil {
- panic("compiler options required")
- }
- if p.opts.Host == nil {
- panic("host required")
- }
+ p := &Program{opts: opts}
p.initCheckerPool()
-
- var libs []string
-
- if compilerOptions.NoLib != core.TSTrue {
- if compilerOptions.Lib == nil {
- name := tsoptions.GetDefaultLibFileName(compilerOptions)
- libs = append(libs, tspath.CombinePaths(p.Host().DefaultLibraryPath(), name))
- } else {
- for _, lib := range compilerOptions.Lib {
- name, ok := tsoptions.GetLibFileName(lib)
- if ok {
- libs = append(libs, tspath.CombinePaths(p.Host().DefaultLibraryPath(), name))
- }
- // !!! error on unknown name
- }
- }
- }
-
- p.processedFiles = processAllProgramFiles(p.opts, libs, p.singleThreaded())
-
+ p.processedFiles = processAllProgramFiles(p.opts, p.singleThreaded())
return p
}
From f2d4ab30b7274c321094d08d5213c1c50799437e Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Sat, 21 Jun 2025 18:10:10 -0700
Subject: [PATCH 2/7] Get it working
---
internal/compiler/fileloader.go | 53 ++++++++++++++++---
internal/compiler/parsetask.go | 6 +--
.../libTypeScriptOverrideSimple.errors.txt | 15 ++++++
...ibTypeScriptOverrideSimple.errors.txt.diff | 19 -------
.../libTypeScriptOverrideSimple.symbols | 3 --
.../libTypeScriptOverrideSimple.symbols.diff | 9 +---
.../libTypeScriptOverrideSimple.types | 6 +--
.../libTypeScriptOverrideSimple.types.diff | 12 -----
...bTypeScriptOverrideSimpleConfig.errors.txt | 6 +--
...ScriptOverrideSimpleConfig.errors.txt.diff | 23 --------
.../libTypeScriptOverrideSimpleConfig.symbols | 10 ++--
...ypeScriptOverrideSimpleConfig.symbols.diff | 23 ++------
.../libTypeScriptOverrideSimpleConfig.types | 10 ++--
...bTypeScriptOverrideSimpleConfig.types.diff | 16 ------
.../libTypeScriptSubfileResolving.errors.txt | 17 ++++++
...TypeScriptSubfileResolving.errors.txt.diff | 21 --------
.../libTypeScriptSubfileResolving.symbols | 3 --
...libTypeScriptSubfileResolving.symbols.diff | 9 +---
.../libTypeScriptSubfileResolving.types | 6 +--
.../libTypeScriptSubfileResolving.types.diff | 12 -----
...ypeScriptSubfileResolvingConfig.errors.txt | 6 +--
...riptSubfileResolvingConfig.errors.txt.diff | 23 --------
...ibTypeScriptSubfileResolvingConfig.symbols | 13 +++--
...eScriptSubfileResolvingConfig.symbols.diff | 26 ++-------
.../libTypeScriptSubfileResolvingConfig.types | 13 +++--
...ypeScriptSubfileResolvingConfig.types.diff | 19 -------
26 files changed, 137 insertions(+), 242 deletions(-)
create mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.errors.txt
delete mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.errors.txt.diff
delete mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.types.diff
delete mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.errors.txt.diff
delete mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.types.diff
create mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.errors.txt
delete mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.errors.txt.diff
delete mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.types.diff
delete mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.errors.txt.diff
delete mode 100644 testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.types.diff
diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go
index e7dce2f418..188dded82c 100644
--- a/internal/compiler/fileloader.go
+++ b/internal/compiler/fileloader.go
@@ -87,18 +87,15 @@ func processAllProgramFiles(
loader.addProjectReferenceTasks()
loader.resolver = module.NewResolver(loader.projectReferenceFileMapper.host, compilerOptions, opts.TypingsLocation, opts.ProjectName)
- // TODO(jakebailey): libReplacement
-
var libs []string
if compilerOptions.NoLib != core.TSTrue {
if compilerOptions.Lib == nil {
name := tsoptions.GetDefaultLibFileName(compilerOptions)
- libs = append(libs, tspath.CombinePaths(opts.Host.DefaultLibraryPath(), name))
+ libs = append(libs, loader.pathForLibFile(name))
} else {
for _, lib := range compilerOptions.Lib {
- name, ok := tsoptions.GetLibFileName(lib)
- if ok {
- libs = append(libs, tspath.CombinePaths(opts.Host.DefaultLibraryPath(), name))
+ if name, ok := tsoptions.GetLibFileName(lib); ok {
+ libs = append(libs, loader.pathForLibFile(name))
}
// !!! error on unknown name
}
@@ -481,6 +478,50 @@ func (p *fileLoader) createSyntheticImport(text string, file *ast.SourceFile) *a
return externalHelpersModuleReference
}
+func (p *fileLoader) pathForLibFile(name string) string {
+ // TODO(jakebailey): cache this
+
+ if p.opts.Config.CompilerOptions().LibReplacement.IsFalseOrUnknown() {
+ return tspath.CombinePaths(p.defaultLibraryPath, name)
+ }
+
+ libraryName := getLibraryNameFromLibFileName(name)
+ resolveFrom := getInferredLibraryNameResolveFrom(p.opts.Config.CompilerOptions(), p.opts.Host.GetCurrentDirectory(), name)
+ resolution := p.resolver.ResolveModuleName(libraryName, resolveFrom, core.ModuleKindCommonJS, nil)
+ if resolution.IsResolved() {
+ return resolution.ResolvedFileName
+ }
+
+ return tspath.CombinePaths(p.defaultLibraryPath, name)
+}
+
+func getLibraryNameFromLibFileName(libFileName string) string {
+ // Support resolving to lib.dom.d.ts -> @typescript/lib-dom, and
+ // lib.dom.iterable.d.ts -> @typescript/lib-dom/iterable
+ // lib.es2015.symbol.wellknown.d.ts -> @typescript/lib-es2015/symbol-wellknown
+ components := strings.Split(libFileName, ".")
+ var path string
+ if len(components) > 1 {
+ path = components[1]
+ }
+ i := 2
+ for i < len(components) && components[i] != "" && components[i] != "d" {
+ path += core.IfElse(i == 2, "/", "-") + components[i]
+ i++
+ }
+ return "@typescript/lib-" + path
+}
+
+func getInferredLibraryNameResolveFrom(options *core.CompilerOptions, currentDirectory string, libFileName string) string {
+ var containingDirectory string
+ if options.ConfigFilePath != "" {
+ containingDirectory = tspath.GetDirectoryPath(options.ConfigFilePath)
+ } else {
+ containingDirectory = currentDirectory
+ }
+ return tspath.CombinePaths(containingDirectory, "__lib_node_modules_lookup_"+libFileName+"__.ts")
+}
+
type resolution struct {
node *ast.Node
resolvedModule *module.ResolvedModule
diff --git a/internal/compiler/parsetask.go b/internal/compiler/parsetask.go
index 75b2e63825..ebb6fdcce3 100644
--- a/internal/compiler/parsetask.go
+++ b/internal/compiler/parsetask.go
@@ -77,11 +77,9 @@ func (t *parseTask) load(loader *fileLoader) {
if compilerOptions.NoLib != core.TSTrue {
for _, lib := range file.LibReferenceDirectives {
- name, ok := tsoptions.GetLibFileName(lib.FileName)
- if !ok {
- continue
+ if name, ok := tsoptions.GetLibFileName(lib.FileName); ok {
+ t.addSubTask(resolvedRef{fileName: loader.pathForLibFile(name)}, true)
}
- t.addSubTask(resolvedRef{fileName: tspath.CombinePaths(loader.defaultLibraryPath, name)}, true)
}
}
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.errors.txt b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.errors.txt
new file mode 100644
index 0000000000..be8ceec77d
--- /dev/null
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.errors.txt
@@ -0,0 +1,15 @@
+index.ts(6,1): error TS2304: Cannot find name 'window'.
+
+
+==== /node_modules/@typescript/lib-dom/index.d.ts (0 errors) ====
+ interface ABC { abc: string }
+==== index.ts (1 errors) ====
+ ///
+ const a: ABC = { abc: "Hello" }
+
+ // This should fail because libdom has been replaced
+ // by the module above ^
+ window.localStorage
+ ~~~~~~
+!!! error TS2304: Cannot find name 'window'.
+
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.errors.txt.diff
deleted file mode 100644
index af3c535b90..0000000000
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.errors.txt.diff
+++ /dev/null
@@ -1,19 +0,0 @@
---- old.libTypeScriptOverrideSimple.errors.txt
-+++ new.libTypeScriptOverrideSimple.errors.txt
-@@= skipped -0, +0 lines =@@
--index.ts(6,1): error TS2304: Cannot find name 'window'.
--
--
--==== /node_modules/@typescript/lib-dom/index.d.ts (0 errors) ====
-- interface ABC { abc: string }
--==== index.ts (1 errors) ====
-- ///
-- const a: ABC = { abc: "Hello" }
--
-- // This should fail because libdom has been replaced
-- // by the module above ^
-- window.localStorage
-- ~~~~~~
--!!! error TS2304: Cannot find name 'window'.
--
-+
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.symbols b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.symbols
index c519a404a8..b11a6ed52e 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.symbols
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.symbols
@@ -15,7 +15,4 @@ const a: ABC = { abc: "Hello" }
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
->window.localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
->window : Symbol(window, Decl(lib.dom.d.ts, --, --))
->localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.symbols.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.symbols.diff
index 03570078e6..54fc22c1be 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.symbols.diff
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.symbols.diff
@@ -8,11 +8,4 @@
+>abc : Symbol(abc, Decl(index.d.ts, 0, 15))
=== index.ts ===
- ///
-@@= skipped -12, +12 lines =@@
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
-+>window.localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
-+>window : Symbol(window, Decl(lib.dom.d.ts, --, --))
-+>localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
+ ///
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.types b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.types
index 4dcbc40564..889c3ca55c 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.types
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.types
@@ -15,7 +15,7 @@ const a: ABC = { abc: "Hello" }
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
->window.localStorage : Storage
->window : Window & typeof globalThis
->localStorage : Storage
+>window.localStorage : any
+>window : any
+>localStorage : any
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.types.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.types.diff
deleted file mode 100644
index f29170c439..0000000000
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimple.types.diff
+++ /dev/null
@@ -1,12 +0,0 @@
---- old.libTypeScriptOverrideSimple.types
-+++ new.libTypeScriptOverrideSimple.types
-@@= skipped -14, +14 lines =@@
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
-->window.localStorage : any
-->window : any
-->localStorage : any
-+>window.localStorage : Storage
-+>window : Window & typeof globalThis
-+>localStorage : Storage
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.errors.txt b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.errors.txt
index a01ceeddd2..d6f5889d4e 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.errors.txt
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.errors.txt
@@ -1,4 +1,4 @@
-/somepath/index.ts(2,10): error TS2304: Cannot find name 'ABC'.
+/somepath/index.ts(6,1): error TS2304: Cannot find name 'window'.
==== /somepath/tsconfig.json (0 errors) ====
@@ -6,12 +6,12 @@
==== /somepath/index.ts (1 errors) ====
///
const a: ABC = { abc: "Hello" }
- ~~~
-!!! error TS2304: Cannot find name 'ABC'.
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
+ ~~~~~~
+!!! error TS2304: Cannot find name 'window'.
==== /somepath/node_modules/@typescript/lib-dom/index.d.ts (0 errors) ====
interface ABC { abc: string }
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.errors.txt.diff
deleted file mode 100644
index 81f51159bf..0000000000
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.errors.txt.diff
+++ /dev/null
@@ -1,23 +0,0 @@
---- old.libTypeScriptOverrideSimpleConfig.errors.txt
-+++ new.libTypeScriptOverrideSimpleConfig.errors.txt
-@@= skipped -0, +0 lines =@@
--/somepath/index.ts(6,1): error TS2304: Cannot find name 'window'.
-+/somepath/index.ts(2,10): error TS2304: Cannot find name 'ABC'.
-
-
- ==== /somepath/tsconfig.json (0 errors) ====
-@@= skipped -5, +5 lines =@@
- ==== /somepath/index.ts (1 errors) ====
- ///
- const a: ABC = { abc: "Hello" }
-+ ~~~
-+!!! error TS2304: Cannot find name 'ABC'.
-
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
-- ~~~~~~
--!!! error TS2304: Cannot find name 'window'.
-
- ==== /somepath/node_modules/@typescript/lib-dom/index.d.ts (0 errors) ====
- interface ABC { abc: string }
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.symbols b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.symbols
index 1f13eb596d..197ea8d111 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.symbols
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.symbols
@@ -4,13 +4,15 @@
///
const a: ABC = { abc: "Hello" }
>a : Symbol(a, Decl(index.ts, 1, 5))
->ABC : Symbol(ABC)
+>ABC : Symbol(ABC, Decl(index.d.ts, 0, 0))
>abc : Symbol(abc, Decl(index.ts, 1, 16))
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
->window.localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
->window : Symbol(window, Decl(lib.dom.d.ts, --, --))
->localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
+
+=== /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
+interface ABC { abc: string }
+>ABC : Symbol(ABC, Decl(index.d.ts, 0, 0))
+>abc : Symbol(abc, Decl(index.d.ts, 0, 15))
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.symbols.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.symbols.diff
index 70c5c86ab3..7c58e28053 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.symbols.diff
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.symbols.diff
@@ -1,21 +1,8 @@
--- old.libTypeScriptOverrideSimpleConfig.symbols
+++ new.libTypeScriptOverrideSimpleConfig.symbols
-@@= skipped -3, +3 lines =@@
- ///
- const a: ABC = { abc: "Hello" }
- >a : Symbol(a, Decl(index.ts, 1, 5))
-->ABC : Symbol(ABC, Decl(index.d.ts, 0, 0))
-+>ABC : Symbol(ABC)
- >abc : Symbol(abc, Decl(index.ts, 1, 16))
-
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
--
--=== /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
--interface ABC { abc: string }
-->ABC : Symbol(ABC, Decl(index.d.ts, 0, 0))
+@@= skipped -13, +13 lines =@@
+ === /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
+ interface ABC { abc: string }
+ >ABC : Symbol(ABC, Decl(index.d.ts, 0, 0))
->abc : Symbol(ABC.abc, Decl(index.d.ts, 0, 15))
-+>window.localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
-+>window : Symbol(window, Decl(lib.dom.d.ts, --, --))
-+>localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
++>abc : Symbol(abc, Decl(index.d.ts, 0, 15))
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.types b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.types
index 3dc706457b..57412e40f6 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.types
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.types
@@ -11,7 +11,11 @@ const a: ABC = { abc: "Hello" }
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
->window.localStorage : Storage
->window : Window & typeof globalThis
->localStorage : Storage
+>window.localStorage : any
+>window : any
+>localStorage : any
+
+=== /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
+interface ABC { abc: string }
+>abc : string
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.types.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.types.diff
deleted file mode 100644
index 08ce51b4ad..0000000000
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptOverrideSimpleConfig.types.diff
+++ /dev/null
@@ -1,16 +0,0 @@
---- old.libTypeScriptOverrideSimpleConfig.types
-+++ new.libTypeScriptOverrideSimpleConfig.types
-@@= skipped -10, +10 lines =@@
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
-->window.localStorage : any
-->window : any
-->localStorage : any
--
--=== /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
--interface ABC { abc: string }
-->abc : string
-+>window.localStorage : Storage
-+>window : Window & typeof globalThis
-+>localStorage : Storage
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.errors.txt b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.errors.txt
new file mode 100644
index 0000000000..c331dcd51c
--- /dev/null
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.errors.txt
@@ -0,0 +1,17 @@
+index.ts(6,1): error TS2304: Cannot find name 'window'.
+
+
+==== /node_modules/@typescript/lib-dom/index.d.ts (0 errors) ====
+ // NOOP
+==== /node_modules/@typescript/lib-dom/iterable.d.ts (0 errors) ====
+ interface DOMIterable { abc: string }
+==== index.ts (1 errors) ====
+ ///
+ const a: DOMIterable = { abc: "Hello" }
+
+ // This should fail because libdom has been replaced
+ // by the module above ^
+ window.localStorage
+ ~~~~~~
+!!! error TS2304: Cannot find name 'window'.
+
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.errors.txt.diff
deleted file mode 100644
index 695cb00b7f..0000000000
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.errors.txt.diff
+++ /dev/null
@@ -1,21 +0,0 @@
---- old.libTypeScriptSubfileResolving.errors.txt
-+++ new.libTypeScriptSubfileResolving.errors.txt
-@@= skipped -0, +0 lines =@@
--index.ts(6,1): error TS2304: Cannot find name 'window'.
--
--
--==== /node_modules/@typescript/lib-dom/index.d.ts (0 errors) ====
-- // NOOP
--==== /node_modules/@typescript/lib-dom/iterable.d.ts (0 errors) ====
-- interface DOMIterable { abc: string }
--==== index.ts (1 errors) ====
-- ///
-- const a: DOMIterable = { abc: "Hello" }
--
-- // This should fail because libdom has been replaced
-- // by the module above ^
-- window.localStorage
-- ~~~~~~
--!!! error TS2304: Cannot find name 'window'.
--
-+
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.symbols b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.symbols
index 4cbc349668..6b5812de94 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.symbols
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.symbols
@@ -18,7 +18,4 @@ const a: DOMIterable = { abc: "Hello" }
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
->window.localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
->window : Symbol(window, Decl(lib.dom.d.ts, --, --))
->localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.symbols.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.symbols.diff
index 56e4932d7e..4f6ebe5bf1 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.symbols.diff
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.symbols.diff
@@ -8,11 +8,4 @@
+>abc : Symbol(abc, Decl(iterable.d.ts, 0, 23))
=== index.ts ===
- ///
-@@= skipped -12, +12 lines =@@
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
-+>window.localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
-+>window : Symbol(window, Decl(lib.dom.d.ts, --, --))
-+>localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
+ ///
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.types b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.types
index 27ec58ce91..47b68d2838 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.types
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.types
@@ -18,7 +18,7 @@ const a: DOMIterable = { abc: "Hello" }
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
->window.localStorage : Storage
->window : Window & typeof globalThis
->localStorage : Storage
+>window.localStorage : any
+>window : any
+>localStorage : any
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.types.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.types.diff
deleted file mode 100644
index 711e3e2d39..0000000000
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolving.types.diff
+++ /dev/null
@@ -1,12 +0,0 @@
---- old.libTypeScriptSubfileResolving.types
-+++ new.libTypeScriptSubfileResolving.types
-@@= skipped -17, +17 lines =@@
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
-->window.localStorage : any
-->window : any
-->localStorage : any
-+>window.localStorage : Storage
-+>window : Window & typeof globalThis
-+>localStorage : Storage
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.errors.txt b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.errors.txt
index eb5ffb7747..c3a3fe70a6 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.errors.txt
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.errors.txt
@@ -1,4 +1,4 @@
-/somepath/index.ts(2,10): error TS2304: Cannot find name 'DOMIterable'.
+/somepath/index.ts(6,1): error TS2304: Cannot find name 'window'.
==== /somepath/tsconfig.json (0 errors) ====
@@ -6,12 +6,12 @@
==== /somepath/index.ts (1 errors) ====
///
const a: DOMIterable = { abc: "Hello" }
- ~~~~~~~~~~~
-!!! error TS2304: Cannot find name 'DOMIterable'.
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
+ ~~~~~~
+!!! error TS2304: Cannot find name 'window'.
==== /somepath/node_modules/@typescript/lib-dom/index.d.ts (0 errors) ====
// NOOP
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.errors.txt.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.errors.txt.diff
deleted file mode 100644
index 84899e77b2..0000000000
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.errors.txt.diff
+++ /dev/null
@@ -1,23 +0,0 @@
---- old.libTypeScriptSubfileResolvingConfig.errors.txt
-+++ new.libTypeScriptSubfileResolvingConfig.errors.txt
-@@= skipped -0, +0 lines =@@
--/somepath/index.ts(6,1): error TS2304: Cannot find name 'window'.
-+/somepath/index.ts(2,10): error TS2304: Cannot find name 'DOMIterable'.
-
-
- ==== /somepath/tsconfig.json (0 errors) ====
-@@= skipped -5, +5 lines =@@
- ==== /somepath/index.ts (1 errors) ====
- ///
- const a: DOMIterable = { abc: "Hello" }
-+ ~~~~~~~~~~~
-+!!! error TS2304: Cannot find name 'DOMIterable'.
-
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
-- ~~~~~~
--!!! error TS2304: Cannot find name 'window'.
-
- ==== /somepath/node_modules/@typescript/lib-dom/index.d.ts (0 errors) ====
- // NOOP
\ No newline at end of file
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.symbols b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.symbols
index 6bf318bfc1..17e830100c 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.symbols
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.symbols
@@ -4,13 +4,18 @@
///
const a: DOMIterable = { abc: "Hello" }
>a : Symbol(a, Decl(index.ts, 1, 5))
->DOMIterable : Symbol(DOMIterable)
+>DOMIterable : Symbol(DOMIterable, Decl(iterable.d.ts, 0, 0))
>abc : Symbol(abc, Decl(index.ts, 1, 24))
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
->window.localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
->window : Symbol(window, Decl(lib.dom.d.ts, --, --))
->localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
+
+=== /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
+
+// NOOP
+=== /somepath/node_modules/@typescript/lib-dom/iterable.d.ts ===
+interface DOMIterable { abc: string }
+>DOMIterable : Symbol(DOMIterable, Decl(iterable.d.ts, 0, 0))
+>abc : Symbol(abc, Decl(iterable.d.ts, 0, 23))
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.symbols.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.symbols.diff
index 79be01d78e..8c56fdeced 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.symbols.diff
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.symbols.diff
@@ -1,24 +1,8 @@
--- old.libTypeScriptSubfileResolvingConfig.symbols
+++ new.libTypeScriptSubfileResolvingConfig.symbols
-@@= skipped -3, +3 lines =@@
- ///
- const a: DOMIterable = { abc: "Hello" }
- >a : Symbol(a, Decl(index.ts, 1, 5))
-->DOMIterable : Symbol(DOMIterable, Decl(iterable.d.ts, 0, 0))
-+>DOMIterable : Symbol(DOMIterable)
- >abc : Symbol(abc, Decl(index.ts, 1, 24))
-
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
--
--=== /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
--
--// NOOP
--=== /somepath/node_modules/@typescript/lib-dom/iterable.d.ts ===
--interface DOMIterable { abc: string }
-->DOMIterable : Symbol(DOMIterable, Decl(iterable.d.ts, 0, 0))
+@@= skipped -16, +16 lines =@@
+ === /somepath/node_modules/@typescript/lib-dom/iterable.d.ts ===
+ interface DOMIterable { abc: string }
+ >DOMIterable : Symbol(DOMIterable, Decl(iterable.d.ts, 0, 0))
->abc : Symbol(DOMIterable.abc, Decl(iterable.d.ts, 0, 23))
-+>window.localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
-+>window : Symbol(window, Decl(lib.dom.d.ts, --, --))
-+>localStorage : Symbol(localStorage, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --))
++>abc : Symbol(abc, Decl(iterable.d.ts, 0, 23))
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.types b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.types
index 646067073d..f2e4e27f11 100644
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.types
+++ b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.types
@@ -11,7 +11,14 @@ const a: DOMIterable = { abc: "Hello" }
// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
->window.localStorage : Storage
->window : Window & typeof globalThis
->localStorage : Storage
+>window.localStorage : any
+>window : any
+>localStorage : any
+
+=== /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
+
+// NOOP
+=== /somepath/node_modules/@typescript/lib-dom/iterable.d.ts ===
+interface DOMIterable { abc: string }
+>abc : string
diff --git a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.types.diff b/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.types.diff
deleted file mode 100644
index a970dcb08d..0000000000
--- a/testdata/baselines/reference/submodule/compiler/libTypeScriptSubfileResolvingConfig.types.diff
+++ /dev/null
@@ -1,19 +0,0 @@
---- old.libTypeScriptSubfileResolvingConfig.types
-+++ new.libTypeScriptSubfileResolvingConfig.types
-@@= skipped -10, +10 lines =@@
- // This should fail because libdom has been replaced
- // by the module above ^
- window.localStorage
-->window.localStorage : any
-->window : any
-->localStorage : any
--
--=== /somepath/node_modules/@typescript/lib-dom/index.d.ts ===
--
--// NOOP
--=== /somepath/node_modules/@typescript/lib-dom/iterable.d.ts ===
--interface DOMIterable { abc: string }
-->abc : string
-+>window.localStorage : Storage
-+>window : Window & typeof globalThis
-+>localStorage : Storage
From d7ed37438effb09b055b3db18868911059f06979 Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Sat, 21 Jun 2025 20:11:55 -0700
Subject: [PATCH 3/7] Caching
---
internal/compiler/fileloader.go | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go
index 188dded82c..fbdfbc47b3 100644
--- a/internal/compiler/fileloader.go
+++ b/internal/compiler/fileloader.go
@@ -34,6 +34,8 @@ type fileLoader struct {
projectReferenceFileMapper *projectReferenceFileMapper
dtsDirectories collections.Set[tspath.Path]
+
+ pathForLibFileCache collections.SyncMap[string, string]
}
type processedFiles struct {
@@ -479,20 +481,22 @@ func (p *fileLoader) createSyntheticImport(text string, file *ast.SourceFile) *a
}
func (p *fileLoader) pathForLibFile(name string) string {
- // TODO(jakebailey): cache this
-
- if p.opts.Config.CompilerOptions().LibReplacement.IsFalseOrUnknown() {
- return tspath.CombinePaths(p.defaultLibraryPath, name)
+ if cached, ok := p.pathForLibFileCache.Load(name); ok {
+ return cached
}
- libraryName := getLibraryNameFromLibFileName(name)
- resolveFrom := getInferredLibraryNameResolveFrom(p.opts.Config.CompilerOptions(), p.opts.Host.GetCurrentDirectory(), name)
- resolution := p.resolver.ResolveModuleName(libraryName, resolveFrom, core.ModuleKindCommonJS, nil)
- if resolution.IsResolved() {
- return resolution.ResolvedFileName
+ path := tspath.CombinePaths(p.defaultLibraryPath, name)
+ if p.opts.Config.CompilerOptions().LibReplacement.IsTrue() {
+ libraryName := getLibraryNameFromLibFileName(name)
+ resolveFrom := getInferredLibraryNameResolveFrom(p.opts.Config.CompilerOptions(), p.opts.Host.GetCurrentDirectory(), name)
+ resolution := p.resolver.ResolveModuleName(libraryName, resolveFrom, core.ModuleKindCommonJS, nil)
+ if resolution.IsResolved() {
+ path = resolution.ResolvedFileName
+ }
}
- return tspath.CombinePaths(p.defaultLibraryPath, name)
+ path, _ = p.pathForLibFileCache.LoadOrStore(name, path)
+ return path
}
func getLibraryNameFromLibFileName(libFileName string) string {
From 4b046896834684aecef24efaf7e333514e0a41bb Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Sat, 21 Jun 2025 20:17:25 -0700
Subject: [PATCH 4/7] Small simplification
---
internal/compiler/fileloader.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go
index fbdfbc47b3..f4d05f4c01 100644
--- a/internal/compiler/fileloader.go
+++ b/internal/compiler/fileloader.go
@@ -84,6 +84,7 @@ func processAllProgramFiles(
projectReferenceParseTasks: &fileLoaderWorker[*projectReferenceParseTask]{
wg: core.NewWorkGroup(singleThreaded),
},
+ rootTasks: make([]*parseTask, 0, len(rootFiles)+len(compilerOptions.Lib)),
supportedExtensions: core.Flatten(tsoptions.GetSupportedExtensionsWithJsonIfResolveJsonModule(compilerOptions, supportedExtensions)),
}
loader.addProjectReferenceTasks()
@@ -104,7 +105,6 @@ func processAllProgramFiles(
}
}
- loader.rootTasks = make([]*parseTask, 0, len(rootFiles)+len(libs))
loader.addRootTasks(rootFiles, false)
loader.addRootTasks(libs, true)
loader.addAutomaticTypeDirectiveTasks()
From 04401dad2596cd27bdc469b2556434034a4e9633 Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Sat, 21 Jun 2025 20:17:52 -0700
Subject: [PATCH 5/7] Small simplification
---
internal/compiler/fileloader.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go
index f4d05f4c01..c49b66e789 100644
--- a/internal/compiler/fileloader.go
+++ b/internal/compiler/fileloader.go
@@ -91,7 +91,7 @@ func processAllProgramFiles(
loader.resolver = module.NewResolver(loader.projectReferenceFileMapper.host, compilerOptions, opts.TypingsLocation, opts.ProjectName)
var libs []string
- if compilerOptions.NoLib != core.TSTrue {
+ if compilerOptions.NoLib.IsFalseOrUnknown() {
if compilerOptions.Lib == nil {
name := tsoptions.GetDefaultLibFileName(compilerOptions)
libs = append(libs, loader.pathForLibFile(name))
From 55297631b88afb99464eb5f95b95c18d83938fbc Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Mon, 23 Jun 2025 12:47:10 -0700
Subject: [PATCH 6/7] Stick lib file resolutions into the resolvedModules cache
for watching
---
internal/compiler/fileloader.go | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go
index c49b66e789..d63bd8c10f 100644
--- a/internal/compiler/fileloader.go
+++ b/internal/compiler/fileloader.go
@@ -35,7 +35,8 @@ type fileLoader struct {
projectReferenceFileMapper *projectReferenceFileMapper
dtsDirectories collections.Set[tspath.Path]
- pathForLibFileCache collections.SyncMap[string, string]
+ pathForLibFileCache collections.SyncMap[string, string]
+ pathForLibFileResolutions collections.SyncMap[module.ModeAwareCacheKey, *module.ResolvedModule]
}
type processedFiles struct {
@@ -122,7 +123,7 @@ func processAllProgramFiles(
libFiles := make([]*ast.SourceFile, 0, totalFileCount) // totalFileCount here since we append files to it later to construct the final list
filesByPath := make(map[tspath.Path]*ast.SourceFile, totalFileCount)
- resolvedModules := make(map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule], totalFileCount)
+ resolvedModules := make(map[tspath.Path]module.ModeAwareCache[*module.ResolvedModule], totalFileCount+1)
typeResolutionsInFile := make(map[tspath.Path]module.ModeAwareCache[*module.ResolvedTypeReferenceDirective], totalFileCount)
sourceFileMetaDatas := make(map[tspath.Path]ast.SourceFileMetaData, totalFileCount)
var jsxRuntimeImportSpecifiers map[tspath.Path]*jsxRuntimeImportSpecifier
@@ -179,6 +180,12 @@ func processAllProgramFiles(
allFiles := append(libFiles, files...)
+ if loader.pathForLibFileResolutions.Size() > 0 {
+ // Hack: place lib file resolutions into the resolvedModules map as if they were
+ // resolved by the config file itself, letting the Project code watch these files.
+ resolvedModules[loader.toPath(compilerOptions.ConfigFilePath)] = loader.pathForLibFileResolutions.ToMap()
+ }
+
return processedFiles{
resolver: loader.resolver,
files: allFiles,
@@ -492,6 +499,7 @@ func (p *fileLoader) pathForLibFile(name string) string {
resolution := p.resolver.ResolveModuleName(libraryName, resolveFrom, core.ModuleKindCommonJS, nil)
if resolution.IsResolved() {
path = resolution.ResolvedFileName
+ p.pathForLibFileResolutions.LoadOrStore(module.ModeAwareCacheKey{Name: libraryName, Mode: core.ModuleKindCommonJS}, resolution)
}
}
From b59f4c38591169ff7953e36016704b0b5ac93a09 Mon Sep 17 00:00:00 2001
From: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
Date: Tue, 24 Jun 2025 09:47:21 -0700
Subject: [PATCH 7/7] Use a cache per resolveFrom
---
internal/compiler/fileloader.go | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/internal/compiler/fileloader.go b/internal/compiler/fileloader.go
index d63bd8c10f..4ea23d0218 100644
--- a/internal/compiler/fileloader.go
+++ b/internal/compiler/fileloader.go
@@ -36,7 +36,7 @@ type fileLoader struct {
dtsDirectories collections.Set[tspath.Path]
pathForLibFileCache collections.SyncMap[string, string]
- pathForLibFileResolutions collections.SyncMap[module.ModeAwareCacheKey, *module.ResolvedModule]
+ pathForLibFileResolutions collections.SyncMap[tspath.Path, module.ModeAwareCache[*module.ResolvedModule]]
}
type processedFiles struct {
@@ -180,11 +180,10 @@ func processAllProgramFiles(
allFiles := append(libFiles, files...)
- if loader.pathForLibFileResolutions.Size() > 0 {
- // Hack: place lib file resolutions into the resolvedModules map as if they were
- // resolved by the config file itself, letting the Project code watch these files.
- resolvedModules[loader.toPath(compilerOptions.ConfigFilePath)] = loader.pathForLibFileResolutions.ToMap()
- }
+ loader.pathForLibFileResolutions.Range(func(key tspath.Path, value module.ModeAwareCache[*module.ResolvedModule]) bool {
+ resolvedModules[key] = value
+ return true
+ })
return processedFiles{
resolver: loader.resolver,
@@ -499,7 +498,9 @@ func (p *fileLoader) pathForLibFile(name string) string {
resolution := p.resolver.ResolveModuleName(libraryName, resolveFrom, core.ModuleKindCommonJS, nil)
if resolution.IsResolved() {
path = resolution.ResolvedFileName
- p.pathForLibFileResolutions.LoadOrStore(module.ModeAwareCacheKey{Name: libraryName, Mode: core.ModuleKindCommonJS}, resolution)
+ p.pathForLibFileResolutions.LoadOrStore(p.toPath(resolveFrom), module.ModeAwareCache[*module.ResolvedModule]{
+ module.ModeAwareCacheKey{Name: libraryName, Mode: core.ModuleKindCommonJS}: resolution,
+ })
}
}