1
- import * as ts from "./ts" ;
1
+ import { BuilderProgramKind , createBuilderProgram , createRedirectedBuilderProgram , getBuilderCreationParameters ,
2
+ ReusableBuilderProgramState } from "./builder" ;
3
+ import { CancellationToken , CompilerHost , CompilerOptions , CustomTransformers , Diagnostic , DiagnosticWithLocation ,
4
+ EmitResult , Program , ProjectReference , SourceFile , WriteFileCallback } from "./types" ;
2
5
3
- export type AffectedFileResult < T > = { result : T ; affected : ts . SourceFile | ts . Program ; } | undefined ;
6
+ export type AffectedFileResult < T > = { result : T ; affected : SourceFile | Program ; } | undefined ;
4
7
5
8
export interface BuilderProgramHost {
6
9
/**
@@ -15,7 +18,7 @@ export interface BuilderProgramHost {
15
18
* When emit or emitNextAffectedFile are called without writeFile,
16
19
* this callback if present would be used to write files
17
20
*/
18
- writeFile ?: ts . WriteFileCallback ;
21
+ writeFile ?: WriteFileCallback ;
19
22
/**
20
23
* disable using source file version as signature for testing
21
24
*/
@@ -33,20 +36,20 @@ export interface BuilderProgramHost {
33
36
*/
34
37
export interface BuilderProgram {
35
38
/*@internal */
36
- getState ( ) : ts . ReusableBuilderProgramState ;
39
+ getState ( ) : ReusableBuilderProgramState ;
37
40
/*@internal */
38
41
backupState ( ) : void ;
39
42
/*@internal */
40
43
restoreState ( ) : void ;
41
44
/**
42
45
* Returns current program
43
46
*/
44
- getProgram ( ) : ts . Program ;
47
+ getProgram ( ) : Program ;
45
48
/**
46
49
* Returns current program that could be undefined if the program was released
47
50
*/
48
51
/*@internal */
49
- getProgramOrUndefined ( ) : ts . Program | undefined ;
52
+ getProgramOrUndefined ( ) : Program | undefined ;
50
53
/**
51
54
* Releases reference to the program, making all the other operations that need program to fail.
52
55
*/
@@ -55,39 +58,39 @@ export interface BuilderProgram {
55
58
/**
56
59
* Get compiler options of the program
57
60
*/
58
- getCompilerOptions ( ) : ts . CompilerOptions ;
61
+ getCompilerOptions ( ) : CompilerOptions ;
59
62
/**
60
63
* Get the source file in the program with file name
61
64
*/
62
- getSourceFile ( fileName : string ) : ts . SourceFile | undefined ;
65
+ getSourceFile ( fileName : string ) : SourceFile | undefined ;
63
66
/**
64
67
* Get a list of files in the program
65
68
*/
66
- getSourceFiles ( ) : readonly ts . SourceFile [ ] ;
69
+ getSourceFiles ( ) : readonly SourceFile [ ] ;
67
70
/**
68
71
* Get the diagnostics for compiler options
69
72
*/
70
- getOptionsDiagnostics ( cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
73
+ getOptionsDiagnostics ( cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
71
74
/**
72
75
* Get the diagnostics that dont belong to any file
73
76
*/
74
- getGlobalDiagnostics ( cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
77
+ getGlobalDiagnostics ( cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
75
78
/**
76
79
* Get the diagnostics from config file parsing
77
80
*/
78
- getConfigFileParsingDiagnostics ( ) : readonly ts . Diagnostic [ ] ;
81
+ getConfigFileParsingDiagnostics ( ) : readonly Diagnostic [ ] ;
79
82
/**
80
83
* Get the syntax diagnostics, for all source files if source file is not supplied
81
84
*/
82
- getSyntacticDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
85
+ getSyntacticDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
83
86
/**
84
87
* Get the declaration diagnostics, for all source files if source file is not supplied
85
88
*/
86
- getDeclarationDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . DiagnosticWithLocation [ ] ;
89
+ getDeclarationDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly DiagnosticWithLocation [ ] ;
87
90
/**
88
91
* Get all the dependencies of the file
89
92
*/
90
- getAllDependencies ( sourceFile : ts . SourceFile ) : readonly string [ ] ;
93
+ getAllDependencies ( sourceFile : SourceFile ) : readonly string [ ] ;
91
94
92
95
/**
93
96
* Gets the semantic diagnostics from the program corresponding to this state of file (if provided) or whole program
@@ -97,7 +100,7 @@ export interface BuilderProgram {
97
100
* In case of SemanticDiagnosticsBuilderProgram if the source file is not provided,
98
101
* it will iterate through all the affected files, to ensure that cache stays valid and yet provide a way to get all semantic diagnostics
99
102
*/
100
- getSemanticDiagnostics ( sourceFile ?: ts . SourceFile , cancellationToken ?: ts . CancellationToken ) : readonly ts . Diagnostic [ ] ;
103
+ getSemanticDiagnostics ( sourceFile ?: SourceFile , cancellationToken ?: CancellationToken ) : readonly Diagnostic [ ] ;
101
104
/**
102
105
* Emits the JavaScript and declaration files.
103
106
* When targetSource file is specified, emits the files corresponding to that source file,
@@ -109,9 +112,9 @@ export interface BuilderProgram {
109
112
* The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host
110
113
* in that order would be used to write the files
111
114
*/
112
- emit ( targetSourceFile ?: ts . SourceFile , writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: ts . CustomTransformers ) : ts . EmitResult ;
115
+ emit ( targetSourceFile ?: SourceFile , writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : EmitResult ;
113
116
/*@internal */
114
- emitBuildInfo ( writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken ) : ts . EmitResult ;
117
+ emitBuildInfo ( writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken ) : EmitResult ;
115
118
/**
116
119
* Get the current directory of the program
117
120
*/
@@ -128,7 +131,7 @@ export interface SemanticDiagnosticsBuilderProgram extends BuilderProgram {
128
131
* Gets the semantic diagnostics from the program for the next affected file and caches it
129
132
* Returns undefined if the iteration is complete
130
133
*/
131
- getSemanticDiagnosticsOfNextAffectedFile ( cancellationToken ?: ts . CancellationToken , ignoreSourceFile ?: ( sourceFile : ts . SourceFile ) => boolean ) : AffectedFileResult < readonly ts . Diagnostic [ ] > ;
134
+ getSemanticDiagnosticsOfNextAffectedFile ( cancellationToken ?: CancellationToken , ignoreSourceFile ?: ( sourceFile : SourceFile ) => boolean ) : AffectedFileResult < readonly Diagnostic [ ] > ;
132
135
}
133
136
134
137
/**
@@ -141,34 +144,34 @@ export interface EmitAndSemanticDiagnosticsBuilderProgram extends SemanticDiagno
141
144
* The first of writeFile if provided, writeFile of BuilderProgramHost if provided, writeFile of compiler host
142
145
* in that order would be used to write the files
143
146
*/
144
- emitNextAffectedFile ( writeFile ?: ts . WriteFileCallback , cancellationToken ?: ts . CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: ts . CustomTransformers ) : AffectedFileResult < ts . EmitResult > ;
147
+ emitNextAffectedFile ( writeFile ?: WriteFileCallback , cancellationToken ?: CancellationToken , emitOnlyDtsFiles ?: boolean , customTransformers ?: CustomTransformers ) : AffectedFileResult < EmitResult > ;
145
148
}
146
149
147
150
/**
148
151
* Create the builder to manage semantic diagnostics and cache them
149
152
*/
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 ) ) ;
153
+ export function createSemanticDiagnosticsBuilderProgram ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : SemanticDiagnosticsBuilderProgram ;
154
+ export function createSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: SemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : SemanticDiagnosticsBuilderProgram ;
155
+ 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 [ ] ) {
156
+ return createBuilderProgram ( BuilderProgramKind . SemanticDiagnosticsBuilderProgram , getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
154
157
}
155
158
156
159
/**
157
160
* Create the builder that can handle the changes in program and iterate through changed files
158
161
* to emit the those files and manage semantic diagnostics cache as well
159
162
*/
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 ) ) ;
163
+ export function createEmitAndSemanticDiagnosticsBuilderProgram ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
164
+ export function createEmitAndSemanticDiagnosticsBuilderProgram ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: EmitAndSemanticDiagnosticsBuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : EmitAndSemanticDiagnosticsBuilderProgram ;
165
+ 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 [ ] ) {
166
+ return createBuilderProgram ( BuilderProgramKind . EmitAndSemanticDiagnosticsBuilderProgram , getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ) ;
164
167
}
165
168
166
169
/**
167
170
* Creates a builder thats just abstraction over program and can be used with watch
168
171
*/
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 ) ;
172
+ export function createAbstractBuilder ( newProgram : Program , host : BuilderProgramHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] ) : BuilderProgram ;
173
+ export function createAbstractBuilder ( rootNames : readonly string [ ] | undefined , options : CompilerOptions | undefined , host ?: CompilerHost , oldProgram ?: BuilderProgram , configFileParsingDiagnostics ?: readonly Diagnostic [ ] , projectReferences ?: readonly ProjectReference [ ] ) : BuilderProgram ;
174
+ 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 {
175
+ const { newProgram, configFileParsingDiagnostics : newConfigFileParsingDiagnostics } = getBuilderCreationParameters ( newProgramOrRootNames , hostOrOptions , oldProgramOrHost , configFileParsingDiagnosticsOrOldProgram , configFileParsingDiagnostics , projectReferences ) ;
176
+ return createRedirectedBuilderProgram ( ( ) => ( { program : newProgram , compilerOptions : newProgram . getCompilerOptions ( ) } ) , newConfigFileParsingDiagnostics ) ;
174
177
}
0 commit comments