@@ -411,21 +411,13 @@ namespace ts {
411
411
oldProgram = undefined ;
412
412
oldState = undefined ;
413
413
414
- const result : BuilderProgram = {
415
- getState : ( ) => state ,
416
- getProgram : ( ) => state . program ,
417
- getCompilerOptions : ( ) => state . program . getCompilerOptions ( ) ,
418
- getSourceFile : fileName => state . program . getSourceFile ( fileName ) ,
419
- getSourceFiles : ( ) => state . program . getSourceFiles ( ) ,
420
- getOptionsDiagnostics : cancellationToken => state . program . getOptionsDiagnostics ( cancellationToken ) ,
421
- getGlobalDiagnostics : cancellationToken => state . program . getGlobalDiagnostics ( cancellationToken ) ,
422
- getConfigFileParsingDiagnostics : ( ) => configFileParsingDiagnostics || state . program . getConfigFileParsingDiagnostics ( ) ,
423
- getSyntacticDiagnostics : ( sourceFile , cancellationToken ) => state . program . getSyntacticDiagnostics ( sourceFile , cancellationToken ) ,
424
- getSemanticDiagnostics,
425
- emit,
426
- getAllDependencies : sourceFile => BuilderState . getAllDependencies ( state , state . program , sourceFile ) ,
427
- getCurrentDirectory : ( ) => state . program . getCurrentDirectory ( )
428
- } ;
414
+ const result = createRedirectObject ( state . program ) as BuilderProgram ;
415
+ result . getState = ( ) => state ;
416
+ result . getProgram = ( ) => state . program ;
417
+ result . getAllDependencies = sourceFile => BuilderState . getAllDependencies ( state , state . program , sourceFile ) ;
418
+ result . getConfigFileParsingDiagnostics = ( ) => configFileParsingDiagnostics ;
419
+ result . getSemanticDiagnostics = getSemanticDiagnostics ;
420
+ result . emit = emit ;
429
421
430
422
if ( kind === BuilderProgramKind . SemanticDiagnosticsBuilderProgram ) {
431
423
( result as SemanticDiagnosticsBuilderProgram ) . getSemanticDiagnosticsOfNextAffectedFile = getSemanticDiagnosticsOfNextAffectedFile ;
@@ -595,45 +587,20 @@ namespace ts {
595
587
/**
596
588
* Builder to manage the program state changes
597
589
*/
598
- export interface BuilderProgram {
590
+ export interface BuilderProgram extends Program {
599
591
/*@internal */
600
592
getState ( ) : BuilderProgramState ;
601
593
/**
602
594
* Returns current program
603
595
*/
604
596
getProgram ( ) : Program ;
605
- /**
606
- * Get compiler options of the program
607
- */
608
- getCompilerOptions ( ) : CompilerOptions ;
609
- /**
610
- * Get the source file in the program with file name
611
- */
612
- getSourceFile ( fileName : string ) : SourceFile | undefined ;
613
- /**
614
- * Get a list of files in the program
615
- */
616
- getSourceFiles ( ) : ReadonlyArray < SourceFile > ;
617
- /**
618
- * Get the diagnostics for compiler options
619
- */
620
- getOptionsDiagnostics ( cancellationToken ?: CancellationToken ) : ReadonlyArray < Diagnostic > ;
621
- /**
622
- * Get the diagnostics that dont belong to any file
623
- */
624
- getGlobalDiagnostics ( cancellationToken ?: CancellationToken ) : ReadonlyArray < Diagnostic > ;
625
- /**
626
- * Get the diagnostics from config file parsing
627
- */
628
- getConfigFileParsingDiagnostics ( ) : ReadonlyArray < Diagnostic > ;
629
- /**
630
- * Get the syntax diagnostics, for all source files if source file is not supplied
631
- */
632
- getSyntacticDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : ReadonlyArray < Diagnostic > ;
633
597
/**
634
598
* Get all the dependencies of the file
635
599
*/
636
600
getAllDependencies ( sourceFile : SourceFile ) : ReadonlyArray < string > ;
601
+
602
+ // These two are same signatures but because the doc comments are useful they are retained
603
+
637
604
/**
638
605
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
639
606
* The semantic diagnostics are cached and managed here
@@ -655,10 +622,6 @@ namespace ts {
655
622
* in that order would be used to write the files
656
623
*/
657
624
emit ( targetSourceFile ?: SourceFile , writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : EmitResult ;
658
- /**
659
- * Get the current directory of the program
660
- */
661
- getCurrentDirectory ( ) : string ;
662
625
}
663
626
664
627
/**
@@ -710,22 +673,14 @@ namespace ts {
710
673
export function createAbstractBuilder ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: ReadonlyArray < Diagnostic > ) : BuilderProgram ;
711
674
export function createAbstractBuilder ( rootNames : ReadonlyArray < string > | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: ReadonlyArray < Diagnostic > , projectReferences ?: ReadonlyArray < ProjectReference > ) : BuilderProgram ;
712
675
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 {
713
- const { newProgram : program } = getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ;
714
- return {
715
- // Only return program, all other methods are not implemented
716
- getProgram : ( ) => program ,
717
- getState : notImplemented ,
718
- getCompilerOptions : notImplemented ,
719
- getSourceFile : notImplemented ,
720
- getSourceFiles : notImplemented ,
721
- getOptionsDiagnostics : notImplemented ,
722
- getGlobalDiagnostics : notImplemented ,
723
- getConfigFileParsingDiagnostics : notImplemented ,
724
- getSyntacticDiagnostics : notImplemented ,
725
- getSemanticDiagnostics : notImplemented ,
726
- emit : notImplemented ,
727
- getAllDependencies : notImplemented ,
728
- getCurrentDirectory : notImplemented
729
- } ;
676
+ 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 ;
730
685
}
731
686
}
0 commit comments