@@ -21,6 +21,7 @@ import (
2121 "github.com/microsoft/typescript-go/internal/collections"
2222 "github.com/microsoft/typescript-go/internal/compiler"
2323 "github.com/microsoft/typescript-go/internal/core"
24+ "github.com/microsoft/typescript-go/internal/execute/incremental"
2425 "github.com/microsoft/typescript-go/internal/outputpaths"
2526 "github.com/microsoft/typescript-go/internal/parser"
2627 "github.com/microsoft/typescript-go/internal/repo"
@@ -687,13 +688,13 @@ func compileFilesWithHost(
687688 }
688689 emitResult := program .Emit (ctx , compiler.EmitOptions {})
689690
690- return newCompilationResult (config .CompilerOptions (), program , emitResult , diagnostics , harnessOptions )
691+ return newCompilationResult (host , config .CompilerOptions (), program , emitResult , diagnostics , harnessOptions )
691692}
692693
693694type CompilationResult struct {
694695 Diagnostics []* ast.Diagnostic
695696 Result * compiler.EmitResult
696- Program * compiler.Program
697+ Program compiler.ProgramLike
697698 Options * core.CompilerOptions
698699 HarnessOptions * HarnessOptions
699700 JS collections.OrderedMap [string , * TestFile ]
@@ -705,6 +706,7 @@ type CompilationResult struct {
705706 inputs []* TestFile
706707 inputsAndOutputs collections.OrderedMap [string , * CompilationOutput ]
707708 Trace string
709+ Host compiler.CompilerHost
708710}
709711
710712type CompilationOutput struct {
@@ -715,8 +717,9 @@ type CompilationOutput struct {
715717}
716718
717719func newCompilationResult (
720+ host compiler.CompilerHost ,
718721 options * core.CompilerOptions ,
719- program * compiler.Program ,
722+ program compiler.ProgramLike ,
720723 result * compiler.EmitResult ,
721724 diagnostics []* ast.Diagnostic ,
722725 harnessOptions * HarnessOptions ,
@@ -731,9 +734,10 @@ func newCompilationResult(
731734 Program : program ,
732735 Options : options ,
733736 HarnessOptions : harnessOptions ,
737+ Host : host ,
734738 }
735739
736- fs := program . Host () .FS ().(* OutputRecorderFS )
740+ fs := host .FS ().(* OutputRecorderFS )
737741 if fs != nil && program != nil {
738742 // Corsa, unlike Strada, can use multiple threads for emit. As a result, the order of outputs is non-deterministic.
739743 // To make the order deterministic, we sort the outputs by the order of the inputs.
@@ -803,7 +807,7 @@ func compareTestFiles(a *TestFile, b *TestFile) int {
803807}
804808
805809func (c * CompilationResult ) getOutputPath (path string , ext string ) string {
806- path = tspath .ResolvePath (c .Program .GetCurrentDirectory (), path )
810+ path = tspath .ResolvePath (c .Host .GetCurrentDirectory (), path )
807811 var outDir string
808812 if ext == ".d.ts" || ext == ".d.mts" || ext == ".d.cts" || (strings .HasSuffix (ext , ".ts" ) && strings .Contains (ext , ".d." )) {
809813 outDir = c .Options .DeclarationDir
@@ -817,17 +821,17 @@ func (c *CompilationResult) getOutputPath(path string, ext string) string {
817821 common := c .Program .CommonSourceDirectory ()
818822 if common != "" {
819823 path = tspath .GetRelativePathFromDirectory (common , path , tspath.ComparePathsOptions {
820- UseCaseSensitiveFileNames : c .Program .UseCaseSensitiveFileNames (),
821- CurrentDirectory : c .Program .GetCurrentDirectory (),
824+ UseCaseSensitiveFileNames : c .Host . FS () .UseCaseSensitiveFileNames (),
825+ CurrentDirectory : c .Host .GetCurrentDirectory (),
822826 })
823- path = tspath .CombinePaths (tspath .ResolvePath (c .Program .GetCurrentDirectory (), c .Options .OutDir ), path )
827+ path = tspath .CombinePaths (tspath .ResolvePath (c .Host .GetCurrentDirectory (), c .Options .OutDir ), path )
824828 }
825829 }
826830 return tspath .ChangeExtension (path , ext )
827831}
828832
829833func (r * CompilationResult ) FS () vfs.FS {
830- return r .Program . Host () .FS ()
834+ return r .Host .FS ()
831835}
832836
833837func (r * CompilationResult ) GetNumberOfJSFiles (includeJson bool ) int {
@@ -852,7 +856,7 @@ func (c *CompilationResult) Outputs() []*TestFile {
852856}
853857
854858func (c * CompilationResult ) GetInputsAndOutputsForFile (path string ) * CompilationOutput {
855- return c .inputsAndOutputs .GetOrZero (tspath .ResolvePath (c .Program .GetCurrentDirectory (), path ))
859+ return c .inputsAndOutputs .GetOrZero (tspath .ResolvePath (c .Host .GetCurrentDirectory (), path ))
856860}
857861
858862func (c * CompilationResult ) GetInputsForFile (path string ) []* TestFile {
@@ -915,7 +919,24 @@ func (c *CompilationResult) GetSourceMapRecord() string {
915919 return sourceMapRecorder .String ()
916920}
917921
918- func createProgram (host compiler.CompilerHost , config * tsoptions.ParsedCommandLine ) * compiler.Program {
922+ type testBuildInfoReader struct {
923+ inner incremental.BuildInfoReader
924+ }
925+
926+ func (t * testBuildInfoReader ) ReadBuildInfo (config * tsoptions.ParsedCommandLine ) * incremental.BuildInfo {
927+ r := t .inner .ReadBuildInfo (config )
928+ if r == nil {
929+ return nil
930+ }
931+ r .Version = core .Version ()
932+ return r
933+ }
934+
935+ func getTestBuildInfoReader (host compiler.CompilerHost ) * testBuildInfoReader {
936+ return & testBuildInfoReader {inner : incremental .NewBuildInfoReader (host )}
937+ }
938+
939+ func createProgram (host compiler.CompilerHost , config * tsoptions.ParsedCommandLine ) compiler.ProgramLike {
919940 var singleThreaded core.Tristate
920941 if testutil .TestProgramIsSingleThreaded () {
921942 singleThreaded = core .TSTrue
@@ -927,6 +948,11 @@ func createProgram(host compiler.CompilerHost, config *tsoptions.ParsedCommandLi
927948 SingleThreaded : singleThreaded ,
928949 }
929950 program := compiler .NewProgram (programOptions )
951+ if config .CompilerOptions ().Incremental .IsTrue () {
952+ oldProgram := incremental .ReadBuildInfoProgram (config , getTestBuildInfoReader (host ), host )
953+ incrementalProgram := incremental .NewProgram (program , oldProgram , incremental .CreateHost (host ), false )
954+ return incrementalProgram
955+ }
930956 return program
931957}
932958
0 commit comments