@@ -411,11 +411,9 @@ namespace ts {
411
411
oldProgram = undefined ;
412
412
oldState = undefined ;
413
413
414
- const result = createRedirectObject ( state . program ) as BuilderProgram ;
414
+ const result = createRedirectedBuilderProgram ( state , configFileParsingDiagnostics ) ;
415
415
result . getState = ( ) => state ;
416
- result . getProgram = ( ) => state . program ;
417
416
result . getAllDependencies = sourceFile => BuilderState . getAllDependencies ( state , state . program , sourceFile ) ;
418
- result . getConfigFileParsingDiagnostics = ( ) => configFileParsingDiagnostics ;
419
417
result . getSemanticDiagnostics = getSemanticDiagnostics ;
420
418
result . emit = emit ;
421
419
@@ -563,6 +561,25 @@ namespace ts {
563
561
return diagnostics || emptyArray ;
564
562
}
565
563
}
564
+
565
+ export function createRedirectedBuilderProgram ( state : { program : Program ; } , configFileParsingDiagnostics : ReadonlyArray < Diagnostic > ) : BuilderProgram {
566
+ return {
567
+ getState : notImplemented ,
568
+ getProgram : ( ) => state . program ,
569
+ getCompilerOptions : ( ) => state . program . getCompilerOptions ( ) ,
570
+ getSourceFile : fileName => state . program . getSourceFile ( fileName ) ,
571
+ getSourceFiles : ( ) => state . program . getSourceFiles ( ) ,
572
+ getOptionsDiagnostics : cancellationToken => state . program . getOptionsDiagnostics ( cancellationToken ) ,
573
+ getGlobalDiagnostics : cancellationToken => state . program . getGlobalDiagnostics ( cancellationToken ) ,
574
+ getConfigFileParsingDiagnostics : ( ) => configFileParsingDiagnostics ,
575
+ getSyntacticDiagnostics : ( sourceFile , cancellationToken ) => state . program . getSyntacticDiagnostics ( sourceFile , cancellationToken ) ,
576
+ getDeclarationDiagnostics : ( sourceFile , cancellationToken ) => state . program . getDeclarationDiagnostics ( sourceFile , cancellationToken ) ,
577
+ getSemanticDiagnostics : ( sourceFile , cancellationToken ) => state . program . getSemanticDiagnostics ( sourceFile , cancellationToken ) ,
578
+ emit : ( sourceFile , writeFile , cancellationToken , emitOnlyDts , customTransformers ) => state . program . emit ( sourceFile , writeFile , cancellationToken , emitOnlyDts , customTransformers ) ,
579
+ getAllDependencies : notImplemented ,
580
+ getCurrentDirectory : ( ) => state . program . getCurrentDirectory ( )
581
+ } ;
582
+ }
566
583
}
567
584
568
585
namespace ts {
@@ -587,20 +604,50 @@ namespace ts {
587
604
/**
588
605
* Builder to manage the program state changes
589
606
*/
590
- export interface BuilderProgram extends Program {
607
+ export interface BuilderProgram {
591
608
/*@internal */
592
609
getState ( ) : BuilderProgramState ;
593
610
/**
594
611
* Returns current program
595
612
*/
596
613
getProgram ( ) : Program ;
614
+ /**
615
+ * Get compiler options of the program
616
+ */
617
+ getCompilerOptions ( ) : CompilerOptions ;
618
+ /**
619
+ * Get the source file in the program with file name
620
+ */
621
+ getSourceFile ( fileName : string ) : SourceFile | undefined ;
622
+ /**
623
+ * Get a list of files in the program
624
+ */
625
+ getSourceFiles ( ) : ReadonlyArray < SourceFile > ;
626
+ /**
627
+ * Get the diagnostics for compiler options
628
+ */
629
+ getOptionsDiagnostics ( cancellationToken ?: CancellationToken ) : ReadonlyArray < Diagnostic > ;
630
+ /**
631
+ * Get the diagnostics that dont belong to any file
632
+ */
633
+ getGlobalDiagnostics ( cancellationToken ?: CancellationToken ) : ReadonlyArray < Diagnostic > ;
634
+ /**
635
+ * Get the diagnostics from config file parsing
636
+ */
637
+ getConfigFileParsingDiagnostics ( ) : ReadonlyArray < Diagnostic > ;
638
+ /**
639
+ * Get the syntax diagnostics, for all source files if source file is not supplied
640
+ */
641
+ getSyntacticDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : ReadonlyArray < Diagnostic > ;
642
+ /**
643
+ * Get the declaration diagnostics, for all source files if source file is not supplied
644
+ */
645
+ getDeclarationDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : ReadonlyArray < DiagnosticWithLocation > ;
597
646
/**
598
647
* Get all the dependencies of the file
599
648
*/
600
649
getAllDependencies ( sourceFile : SourceFile ) : ReadonlyArray < string > ;
601
650
602
- // These two are same signatures but because the doc comments are useful they are retained
603
-
604
651
/**
605
652
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
606
653
* The semantic diagnostics are cached and managed here
@@ -622,6 +669,10 @@ namespace ts {
622
669
* in that order would be used to write the files
623
670
*/
624
671
emit ( targetSourceFile ?: SourceFile , writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : EmitResult ;
672
+ /**
673
+ * Get the current directory of the program
674
+ */
675
+ getCurrentDirectory ( ) : string ;
625
676
}
626
677
627
678
/**
@@ -674,13 +725,6 @@ namespace ts {
674
725
export function createAbstractBuilder ( rootNames : ReadonlyArray < string > | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: ReadonlyArray < Diagnostic > , projectReferences ?: ReadonlyArray < ProjectReference > ) : BuilderProgram ;
675
726
export function createAbstractBuilder ( newProgramOrRootNames : Program | ReadonlyArray < string > | undefined , hostOrOptions : BuilderProgramHost | CompilerOptions | undefined , oldProgramOrHost ?: CompilerHost | BuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: ReadonlyArray < Diagnostic > | BuilderProgram , configFileParsingDiagnostics ?: ReadonlyArray < Diagnostic > , projectReferences ?: ReadonlyArray < ProjectReference > ) : BuilderProgram {
676
727
const { newProgram, configFileParsingDiagnostics : newConfigFileParsingDiagnostics } = getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ;
677
- const builderProgram = createRedirectObject ( newProgram ) as BuilderProgram ;
678
- builderProgram . getState = notImplemented ;
679
- builderProgram . getProgram = ( ) => newProgram ;
680
- builderProgram . getAllDependencies = notImplemented ;
681
-
682
- // Always return latest config file diagnostics
683
- builderProgram . getConfigFileParsingDiagnostics = ( ) => newConfigFileParsingDiagnostics ;
684
- return builderProgram ;
728
+ return createRedirectedBuilderProgram ( { program : newProgram } , newConfigFileParsingDiagnostics ) ;
685
729
}
686
730
}
0 commit comments