From 42ad44fff3d154ef436139193ad7ce94af279cbb Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Fri, 21 Aug 2026 14:52:54 -0700 Subject: [PATCH] Fix binder race --- tsc/internal/project/compilerhost.go | 3 +++ tsc/internal/project/parsecache.go | 2 ++ tsc/internal/project/refcountcache_test.go | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/tsc/internal/project/compilerhost.go b/tsc/internal/project/compilerhost.go index 47b17ee75d826..cba0bebfc5c2a 100644 --- a/tsc/internal/project/compilerhost.go +++ b/tsc/internal/project/compilerhost.go @@ -4,6 +4,7 @@ import ( "sync" "github.com/microsoft/TypeScript/tsc/internal/ast" + "github.com/microsoft/TypeScript/tsc/internal/binder" "github.com/microsoft/TypeScript/tsc/internal/compiler" "github.com/microsoft/TypeScript/tsc/internal/contentmapper" "github.com/microsoft/TypeScript/tsc/internal/diagnostics" @@ -135,8 +136,10 @@ func (c *compilerHost) GetContentMappedSourceFiles(parseOptions ast.SourceFilePa return contentmapper.SourceFiles{}, transformErr } files.Canonical.Hash = key.Hash + binder.BindSourceFile(files.Canonical) for _, supplemental := range files.Supplemental { supplemental.Hash = key.Hash + binder.BindSourceFile(supplemental) } return files, nil }) diff --git a/tsc/internal/project/parsecache.go b/tsc/internal/project/parsecache.go index b686a9168e96c..2fdd67e590963 100644 --- a/tsc/internal/project/parsecache.go +++ b/tsc/internal/project/parsecache.go @@ -4,6 +4,7 @@ import ( "encoding/binary" "github.com/microsoft/TypeScript/tsc/internal/ast" + "github.com/microsoft/TypeScript/tsc/internal/binder" "github.com/microsoft/TypeScript/tsc/internal/compiler" "github.com/microsoft/TypeScript/tsc/internal/contentmapper" "github.com/microsoft/TypeScript/tsc/internal/core" @@ -76,6 +77,7 @@ func NewParseCache(options RefCountCacheOptions) *ParseCache { func(key ParseCacheKey, fh FileHandle) *ast.SourceFile { file := parser.ParseSourceFile(key.SourceFileParseOptions, fh.Content(), key.ScriptKind) file.Hash = fh.Hash() + binder.BindSourceFile(file) return file }, ) diff --git a/tsc/internal/project/refcountcache_test.go b/tsc/internal/project/refcountcache_test.go index d488b47535de0..99e94063975b9 100644 --- a/tsc/internal/project/refcountcache_test.go +++ b/tsc/internal/project/refcountcache_test.go @@ -69,6 +69,25 @@ func TestContentMappedParseCacheKeyReconstruction(t *testing.T) { assert.DeepEqual(t, contentMappedParseCacheKeyForDuplicate(duplicate), expected) } +func TestParseCacheBindsBeforePublishing(t *testing.T) { + t.Parallel() + + const fileName = "/index.js" + fileHandle := newOverlay(fileName, "module.exports = 0;", 1, core.ScriptKindJS) + parseOptions := ast.SourceFileParseOptions{ + FileName: fileName, + Path: tspath.Path(fileName), + } + key := NewParseCacheKey(parseOptions, fileHandle.Hash(), fileHandle.Kind()) + cache := NewParseCache(RefCountCacheOptions{}) + + file := cache.Acquire(key, fileHandle) + defer cache.Deref(key) + + assert.Assert(t, file.IsBound()) + assert.Assert(t, file.CommonJSModuleIndicator != nil) +} + func TestRefCountingCaches(t *testing.T) { t.Parallel()