@@ -223,7 +223,7 @@ func CompileFilesEx(
223223 Errors : errors ,
224224 }, harnessOptions )
225225 result .Symlinks = symlinks
226- result .Trace = host .tracer .string ()
226+ result .Trace = host .tracer .String ()
227227 result .Repeat = func (testConfig TestConfiguration ) * CompilationResult {
228228 newHarnessOptions := * harnessOptions
229229 newCompilerOptions := compilerOptions .Clone ()
@@ -474,7 +474,7 @@ func getOptionValue(t *testing.T, option *tsoptions.CommandLineOption, value str
474474
475475type cachedCompilerHost struct {
476476 compiler.CompilerHost
477- tracer * tracer
477+ tracer * TracerForBaselining
478478}
479479
480480var sourceFileCache collections.SyncMap [SourceFileCacheKey , * ast.SourceFile ]
@@ -515,26 +515,33 @@ func (h *cachedCompilerHost) GetSourceFile(opts ast.SourceFileParseOptions) *ast
515515 return result
516516}
517517
518- type tracer struct {
519- fs vfs.FS
520- currentDirectory string
518+ type TracerForBaselining struct {
519+ opts tspath.ComparePathsOptions
521520 packageJsonCache map [tspath.Path ]bool
522- builder strings.Builder
521+ builder * strings.Builder
523522}
524523
525- func (t * tracer ) trace (msg string ) {
526- fmt .Fprintln (& t .builder , t .sanitizeTrace (msg ))
524+ func NewTracerForBaselining (opts tspath.ComparePathsOptions , builder * strings.Builder ) * TracerForBaselining {
525+ return & TracerForBaselining {
526+ opts : opts ,
527+ packageJsonCache : make (map [tspath.Path ]bool ),
528+ builder : builder ,
529+ }
530+ }
531+
532+ func (t * TracerForBaselining ) Trace (msg string ) {
533+ fmt .Fprintln (t .builder , t .sanitizeTrace (msg ))
527534}
528535
529- func (t * tracer ) sanitizeTrace (msg string ) string {
536+ func (t * TracerForBaselining ) sanitizeTrace (msg string ) string {
530537 // Version
531538 if str := strings .Replace (msg , "'" + core .Version ()+ "'" , "'" + FakeTSVersion + "'" , 1 ); str != msg {
532539 return str
533540 }
534541 // caching of fs in trace to be replaces with non caching version
535542 if str := strings .TrimSuffix (msg , "' does not exist according to earlier cached lookups." ); str != msg {
536543 file := strings .TrimPrefix (str , "File '" )
537- filePath := tspath .ToPath (file , t .currentDirectory , t .fs .UseCaseSensitiveFileNames () )
544+ filePath := tspath .ToPath (file , t .opts . CurrentDirectory , t .opts .UseCaseSensitiveFileNames )
538545 if _ , has := t .packageJsonCache [filePath ]; has {
539546 return msg
540547 } else {
@@ -544,7 +551,7 @@ func (t *tracer) sanitizeTrace(msg string) string {
544551 }
545552 if str := strings .TrimSuffix (msg , "' does not exist." ); str != msg {
546553 file := strings .TrimPrefix (str , "File '" )
547- filePath := tspath .ToPath (file , t .currentDirectory , t .fs .UseCaseSensitiveFileNames () )
554+ filePath := tspath .ToPath (file , t .opts . CurrentDirectory , t .opts .UseCaseSensitiveFileNames )
548555 if _ , has := t .packageJsonCache [filePath ]; ! has {
549556 t .packageJsonCache [filePath ] = false
550557 return msg
@@ -554,7 +561,7 @@ func (t *tracer) sanitizeTrace(msg string) string {
554561 }
555562 if str := strings .TrimSuffix (msg , "' exists according to earlier cached lookups." ); str != msg {
556563 file := strings .TrimPrefix (str , "File '" )
557- filePath := tspath .ToPath (file , t .currentDirectory , t .fs .UseCaseSensitiveFileNames () )
564+ filePath := tspath .ToPath (file , t .opts . CurrentDirectory , t .opts .UseCaseSensitiveFileNames )
558565 if _ , has := t .packageJsonCache [filePath ]; has {
559566 return msg
560567 } else {
@@ -564,7 +571,7 @@ func (t *tracer) sanitizeTrace(msg string) string {
564571 }
565572 if str := strings .TrimPrefix (msg , "Found 'package.json' at '" ); str != msg {
566573 file := strings .TrimSuffix (str , "'." )
567- filePath := tspath .ToPath (file , t .currentDirectory , t .fs .UseCaseSensitiveFileNames () )
574+ filePath := tspath .ToPath (file , t .opts . CurrentDirectory , t .opts .UseCaseSensitiveFileNames )
568575 if _ , has := t .packageJsonCache [filePath ]; ! has {
569576 t .packageJsonCache [filePath ] = true
570577 return msg
@@ -575,15 +582,22 @@ func (t *tracer) sanitizeTrace(msg string) string {
575582 return msg
576583}
577584
578- func (t * tracer ) string () string {
585+ func (t * TracerForBaselining ) String () string {
579586 return t .builder .String ()
580587}
581588
589+ func (t * TracerForBaselining ) Reset () {
590+ t .packageJsonCache = make (map [tspath.Path ]bool )
591+ }
592+
582593func createCompilerHost (fs vfs.FS , defaultLibraryPath string , currentDirectory string ) * cachedCompilerHost {
583- tracer := tracer {fs : fs , currentDirectory : currentDirectory , packageJsonCache : make (map [tspath.Path ]bool )}
594+ tracer := NewTracerForBaselining (tspath.ComparePathsOptions {
595+ UseCaseSensitiveFileNames : fs .UseCaseSensitiveFileNames (),
596+ CurrentDirectory : currentDirectory ,
597+ }, & strings.Builder {})
584598 return & cachedCompilerHost {
585- CompilerHost : compiler .NewCompilerHost (currentDirectory , fs , defaultLibraryPath , nil , tracer .trace ),
586- tracer : & tracer ,
599+ CompilerHost : compiler .NewCompilerHost (currentDirectory , fs , defaultLibraryPath , nil , tracer .Trace ),
600+ tracer : tracer ,
587601 }
588602}
589603
0 commit comments