Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tsc/internal/project/compilerhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
})
Expand Down
2 changes: 2 additions & 0 deletions tsc/internal/project/parsecache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
},
)
Expand Down
19 changes: 19 additions & 0 deletions tsc/internal/project/refcountcache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Loading