vendor tsgo

This commit is contained in:
2026-07-09 16:50:43 -04:00
parent c06ea2e5a4
commit 98978e4930
5804 changed files with 1556156 additions and 101 deletions

View File

@@ -0,0 +1,56 @@
package incremental
import (
"github.com/microsoft/typescript-go/internal/compiler"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/tsoptions"
)
type BuildInfoReader interface {
ReadBuildInfo(config *tsoptions.ParsedCommandLine) *BuildInfo
}
var _ BuildInfoReader = (*buildInfoReader)(nil)
type buildInfoReader struct {
host compiler.CompilerHost
}
func (r *buildInfoReader) ReadBuildInfo(config *tsoptions.ParsedCommandLine) *BuildInfo {
buildInfoFileName := config.GetBuildInfoFileName()
if buildInfoFileName == "" {
return nil
}
// Read build info file
data, ok := r.host.FS().ReadFile(buildInfoFileName)
if !ok {
return nil
}
var buildInfo BuildInfo
err := json.Unmarshal([]byte(data), &buildInfo)
if err != nil {
return nil
}
return &buildInfo
}
func NewBuildInfoReader(
host compiler.CompilerHost,
) BuildInfoReader {
return &buildInfoReader{host: host}
}
func ReadBuildInfoProgram(config *tsoptions.ParsedCommandLine, reader BuildInfoReader, host compiler.CompilerHost) *Program {
// Read buildInfo file
buildInfo := reader.ReadBuildInfo(config)
if buildInfo == nil || !buildInfo.IsValidVersion() || !buildInfo.IsIncremental() {
return nil
}
// Convert to information that can be used to create incremental program
incrementalProgram := &Program{
snapshot: buildInfoToSnapshot(buildInfo, config, host),
}
return incrementalProgram
}