vendor tsgo
This commit is contained in:
39
tools/tsgo/internal/project/parsecache.go
Normal file
39
tools/tsgo/internal/project/parsecache.go
Normal file
@@ -0,0 +1,39 @@
|
||||
package project
|
||||
|
||||
import (
|
||||
"github.com/microsoft/typescript-go/internal/ast"
|
||||
"github.com/microsoft/typescript-go/internal/core"
|
||||
"github.com/microsoft/typescript-go/internal/parser"
|
||||
"github.com/zeebo/xxh3"
|
||||
)
|
||||
|
||||
type ParseCacheKey struct {
|
||||
ast.SourceFileParseOptions
|
||||
ScriptKind core.ScriptKind
|
||||
Hash xxh3.Uint128
|
||||
}
|
||||
|
||||
func NewParseCacheKey(
|
||||
options ast.SourceFileParseOptions,
|
||||
hash xxh3.Uint128,
|
||||
scriptKind core.ScriptKind,
|
||||
) ParseCacheKey {
|
||||
return ParseCacheKey{
|
||||
SourceFileParseOptions: options,
|
||||
Hash: hash,
|
||||
ScriptKind: scriptKind,
|
||||
}
|
||||
}
|
||||
|
||||
type ParseCache = RefCountCache[ParseCacheKey, *ast.SourceFile, FileHandle]
|
||||
|
||||
func NewParseCache(options RefCountCacheOptions) *ParseCache {
|
||||
return NewRefCountCache(
|
||||
options,
|
||||
func(key ParseCacheKey, fh FileHandle) *ast.SourceFile {
|
||||
file := parser.ParseSourceFile(key.SourceFileParseOptions, fh.Content(), key.ScriptKind)
|
||||
file.Hash = fh.Hash()
|
||||
return file
|
||||
},
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user