1- import * as ts from "./_namespaces/ts" ;
1+ import {
2+ BuilderProgramKind , createBuilderProgram , createRedirectedBuilderProgram , getBuilderCreationParameters ,
3+ ReusableBuilderProgramState ,
4+ } from "./builder" ;
5+ import {
6+ CancellationToken , CompilerHost , CompilerOptions , CustomTransformers , Diagnostic , DiagnosticWithLocation ,
7+ EmitResult , Program , ProjectReference , SourceFile , WriteFileCallback ,
8+ } from "./types" ;
29
3- export type AffectedFileResult < T > = { result : T ; affected : ts . SourceFile | ts . Program ; } | undefined ;
10+ export type AffectedFileResult < T > = { result : T ; affected : SourceFile | Program ; } | undefined ;
411
512export interface BuilderProgramHost {
613 /**
@@ -15,7 +22,7 @@ export interface BuilderProgramHost {
1522 * When emit or emitNextAffectedFile are called without writeFile,
1623 * this callback if present would be used to write files
1724 */
18- writeFile ?: ts . WriteFileCallback ;
25+ writeFile ?: WriteFileCallback ;
1926 /**
2027 * disable using source file version as signature for testing
2128 */
@@ -33,20 +40,20 @@ export interface BuilderProgramHost {
3340 */
3441export interface BuilderProgram {
3542 /*@internal */
36- getState ( ) : ts . ReusableBuilderProgramState ;
43+ getState ( ) : ReusableBuilderProgramState ;
3744 /*@internal */
3845 backupState ( ) : void ;
3946 /*@internal */
4047 restoreState ( ) : void ;
4148 /**
4249 * Returns current program
4350 */
44- getProgram ( ) : ts . Program ;
51+ getProgram ( ) : Program ;
4552 /**
4653 * Returns current program that could be undefined if the program was released
4754 */
4855 /*@internal */
49- getProgramOrUndefined ( ) : ts . Program | undefined ;
56+ getProgramOrUndefined ( ) : Program | undefined ;
5057 /**
5158 * Releases reference to the program, making all the other operations that need program to fail.
5259 */
@@ -55,39 +62,39 @@ export interface BuilderProgram {
5562 /**
5663 * Get compiler options of the program
5764 */
58- getCompilerOptions ( ) : ts . CompilerOptions ;
65+ getCompilerOptions ( ) : CompilerOptions ;
5966 /**
6067 * Get the source file in the program with file name
6168 */
62- getSourceFile ( fileName : string ) : ts . SourceFile | undefined ;
69+ getSourceFile ( fileName : string ) : SourceFile | undefined ;
6370 /**
6471 * Get a list of files in the program
6572 */
66- getSourceFiles ( ) : readonly ts . SourceFile [ ] ;
73+ getSourceFiles ( ) : readonly SourceFile [ ] ;
6774 /**
6875 * Get the diagnostics for compiler options
6976 */
70- getOptionsDiagnostics ( cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
77+ getOptionsDiagnostics ( cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
7178 /**
7279 * Get the diagnostics that dont belong to any file
7380 */
74- getGlobalDiagnostics ( cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
81+ getGlobalDiagnostics ( cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
7582 /**
7683 * Get the diagnostics from config file parsing
7784 */
78- getConfigFileParsingDiagnostics ( ) : readonly ts . Diagnostic [ ] ;
85+ getConfigFileParsingDiagnostics ( ) : readonly Diagnostic [ ] ;
7986 /**
8087 * Get the syntax diagnostics, for all source files if source file is not supplied
8188 */
82- getSyntacticDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
89+ getSyntacticDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
8390 /**
8491 * Get the declaration diagnostics, for all source files if source file is not supplied
8592 */
86- getDeclarationDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . DiagnosticWithLocation [ ] ;
93+ getDeclarationDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly DiagnosticWithLocation [ ] ;
8794 /**
8895 * Get all the dependencies of the file
8996 */
90- getAllDependencies ( sourceFile : ts . SourceFile ) : readonly string [ ] ;
97+ getAllDependencies ( sourceFile : SourceFile ) : readonly string [ ] ;
9198
9299 /**
93100 * Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
@@ -97,7 +104,7 @@ export interface BuilderProgram {
97104 * In case of SemanticDiagnosticsBuilderProgram if the source file is not provided,
98105 * it will iterate through all the affected files, to ensure that cache stays valid and yet provide a way to get all semantic diagnostics
99106 */
100- getSemanticDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
107+ getSemanticDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
101108 /**
102109 * Emits the JavaScript and declaration files.
103110 * When targetSource file is specified, emits the files corresponding to that source file,
@@ -109,9 +116,9 @@ export interface BuilderProgram {
109116 * The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host
110117 * in that order would be used to write the files
111118 */
112- emit ( targetSourceFile ?: ts . SourceFile , writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: ts . CustomTransformers ) : ts . EmitResult ;
119+ emit ( targetSourceFile ?: SourceFile , writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : EmitResult ;
113120 /*@internal */
114- emitBuildInfo ( writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken ) : ts . EmitResult ;
121+ emitBuildInfo ( writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken ) : EmitResult ;
115122 /**
116123 * Get the current directory of the program
117124 */
@@ -128,7 +135,7 @@ export interface SemanticDiagnosticsBuilderProgram extends BuilderProgram {
128135 * Gets the semantic diagnostics from the program for the next affected file and caches it
129136 * Returns undefined if the iteration is complete
130137 */
131- getSemanticDiagnosticsOfNextAffectedFile ( cancellationToken ?: ts . CancellationToken , ignoreSourceFile ?: ( sourceFile : ts . SourceFile ) => boolean ) : AffectedFileResult < readonly ts . Diagnostic [ ] > ;
138+ getSemanticDiagnosticsOfNextAffectedFile ( cancellationToken ?: CancellationToken , ignoreSourceFile ?: ( sourceFile : SourceFile ) => boolean ) : AffectedFileResult < readonly Diagnostic [ ] > ;
132139}
133140
134141/**
@@ -141,34 +148,34 @@ export interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagno
141148 * The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host
142149 * in that order would be used to write the files
143150 */
144- emitNextAffectedFile ( writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: ts . CustomTransformers ) : AffectedFileResult < ts . EmitResult > ;
151+ emitNextAffectedFile ( writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : AffectedFileResult < EmitResult > ;
145152}
146153
147154/**
148155 * Create the builder to manage semantic diagnostics and cache them
149156 */
150- export function createSemanticDiagnosticsBuilderProgram ( newProgram : ts . Program , host : BuilderProgramHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] ) : SemanticDiagnosticsBuilderProgram ;
151- export function createSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : ts . CompilerOptions | undefined , host ?: ts . CompilerHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : SemanticDiagnosticsBuilderProgram ;
152- export function createSemanticDiagnosticsBuilderProgram ( newProgramOrRootNames : ts . Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | ts . CompilerOptions | undefined , oldProgramOrHost ?: ts . CompilerHost | SemanticDiagnosticsBuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly ts . Diagnostic [ ] | SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) {
153- return ts . createBuilderProgram ( ts . BuilderProgramKind . SemanticDiagnosticsBuilderProgram , ts . getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
157+ export function createSemanticDiagnosticsBuilderProgram ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : SemanticDiagnosticsBuilderProgram ;
158+ export function createSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : SemanticDiagnosticsBuilderProgram ;
159+ export function createSemanticDiagnosticsBuilderProgram ( newProgramOrRootNames : Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | CompilerOptions | undefined , oldProgramOrHost ?: CompilerHost | SemanticDiagnosticsBuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly Diagnostic [ ] | SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) {
160+ return createBuilderProgram ( BuilderProgramKind . SemanticDiagnosticsBuilderProgram , getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
154161}
155162
156163/**
157164 * Create the builder that can handle the changes in program and iterate through changed files
158165 * to emit the those files and manage semantic diagnostics cache as well
159166 */
160- export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgram : ts . Program , host : BuilderProgramHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
161- export function createEmitAndSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : ts . CompilerOptions | undefined , host ?: ts . CompilerHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
162- export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgramOrRootNames : ts . Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | ts . CompilerOptions | undefined , oldProgramOrHost ?: ts . CompilerHost | EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly ts . Diagnostic [ ] | EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) {
163- return ts . createBuilderProgram ( ts . BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram , ts . getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
167+ export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
168+ export function createEmitAndSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
169+ export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgramOrRootNames : Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | CompilerOptions | undefined , oldProgramOrHost ?: CompilerHost | EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly Diagnostic [ ] | EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) {
170+ return createBuilderProgram ( BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram , getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
164171}
165172
166173/**
167174 * Creates a builder thats just abstraction over program and can be used with watch
168175 */
169- export function createAbstractBuilder ( newProgram : ts . Program , host : BuilderProgramHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] ) : BuilderProgram ;
170- export function createAbstractBuilder ( rootNames : readonly string [ ] | undefined , options : ts . CompilerOptions | undefined , host ?: ts . CompilerHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : BuilderProgram ;
171- export function createAbstractBuilder ( newProgramOrRootNames : ts . Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | ts . CompilerOptions | undefined , oldProgramOrHost ?: ts . CompilerHost | BuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly ts . Diagnostic [ ] | BuilderProgram , configFileParsingDiagnostics ?: readonly ts . Diagnostic [ ] , projectReferences ?: readonly ts . ProjectReference [ ] ) : BuilderProgram {
172- const { newProgram, configFileParsingDiagnostics : newConfigFileParsingDiagnostics } = ts . getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ;
173- return ts . createRedirectedBuilderProgram ( ( ) => ( { program : newProgram , compilerOptions : newProgram . getCompilerOptions ( ) } ) , newConfigFileParsingDiagnostics ) ;
176+ export function createAbstractBuilder ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : BuilderProgram ;
177+ export function createAbstractBuilder ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : BuilderProgram ;
178+ export function createAbstractBuilder ( newProgramOrRootNames : Program | readonly string [ ] | undefined , hostOrOptions : BuilderProgramHost | CompilerOptions | undefined , oldProgramOrHost ?: CompilerHost | BuilderProgram , configFileParsingDiagnosticsOrOldProgram ?: readonly Diagnostic [ ] | BuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : BuilderProgram {
179+ const { newProgram, configFileParsingDiagnostics : newConfigFileParsingDiagnostics } = getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ;
180+ return createRedirectedBuilderProgram ( ( ) => ( { program : newProgram , compilerOptions : newProgram . getCompilerOptions ( ) } ) , newConfigFileParsingDiagnostics ) ;
174181}
0 commit comments