Skip to content

Commit 1a91256

Browse files
committed
Make before and after program create callbacks optional
1 parent 471c83b commit 1a91256

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

src/compiler/watch.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ namespace ts {
165165
/** FS system to use */
166166
system: System;
167167

168-
/** Custom action before creating the program */
169-
beforeProgramCreate(compilerOptions: CompilerOptions): void;
170-
/** Custom action after new program creation is successful */
171-
afterProgramCreate(host: DirectoryStructureHost, program: Program): void;
168+
/** If provided, callback to invoke before each program creation */
169+
beforeProgramCreate?(compilerOptions: CompilerOptions): void;
170+
/** If provided, callback to invoke after every new program creation */
171+
afterProgramCreate?(host: DirectoryStructureHost, program: Program): void;
172172

173173
/** Optional module name resolver */
174174
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[]): ResolvedModule[];
@@ -239,7 +239,6 @@ namespace ts {
239239
export function createWatchOfConfigFile(configFileName: string, optionsToExtend?: CompilerOptions, system = sys, reportDiagnostic?: DiagnosticReporter): WatchOfConfigFile {
240240
return createWatch({
241241
system,
242-
beforeProgramCreate: noop,
243242
afterProgramCreate: createProgramCompilerWithBuilderState(system, reportDiagnostic),
244243
onConfigFileDiagnostic: reportDiagnostic || createDiagnosticReporter(system),
245244
configFileName,
@@ -253,7 +252,6 @@ namespace ts {
253252
export function createWatchOfFilesAndCompilerOptions(rootFiles: string[], options: CompilerOptions, system = sys, reportDiagnostic?: DiagnosticReporter): WatchOfFilesAndCompilerOptions {
254253
return createWatch({
255254
system,
256-
beforeProgramCreate: noop,
257255
afterProgramCreate: createProgramCompilerWithBuilderState(system, reportDiagnostic),
258256
rootFiles,
259257
options
@@ -286,7 +284,9 @@ namespace ts {
286284
let hasChangedCompilerOptions = false; // True if the compiler options have changed between compilations
287285
let hasChangedAutomaticTypeDirectiveNames = false; // True if the automatic type directives have changed
288286

289-
const { system, configFileName, onConfigFileDiagnostic, afterProgramCreate, beforeProgramCreate, optionsToExtend: optionsToExtendForConfigFile = {} } = host as WatchOfConfigFileHost;
287+
const { system, configFileName, onConfigFileDiagnostic, optionsToExtend: optionsToExtendForConfigFile = {} } = host as WatchOfConfigFileHost;
288+
const beforeProgramCreate: WatchHost["beforeProgramCreate"] = host.beforeProgramCreate ? host.beforeProgramCreate.bind(host) : noop;
289+
const afterProgramCreate: WatchHost["afterProgramCreate"] = host.afterProgramCreate ? host.afterProgramCreate.bind(host) : noop;
290290
let { rootFiles: rootFileNames, options: compilerOptions, configFileSpecs, configFileWildCardDirectories } = host as WatchOfConfigFileHost;
291291

292292
// From tsc we want to get already parsed result and hence check for rootFileNames

tests/baselines/reference/api/typescript.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3823,10 +3823,10 @@ declare namespace ts {
38233823
interface WatchHost {
38243824
/** FS system to use */
38253825
system: System;
3826-
/** Custom action before creating the program */
3827-
beforeProgramCreate(compilerOptions: CompilerOptions): void;
3828-
/** Custom action after new program creation is successful */
3829-
afterProgramCreate(host: DirectoryStructureHost, program: Program): void;
3826+
/** If provided, callback to invoke before each program creation */
3827+
beforeProgramCreate?(compilerOptions: CompilerOptions): void;
3828+
/** If provided, callback to invoke after every new program creation */
3829+
afterProgramCreate?(host: DirectoryStructureHost, program: Program): void;
38303830
/** Optional module name resolver */
38313831
resolveModuleNames?(moduleNames: string[], containingFile: string, reusedNames?: string[]): ResolvedModule[];
38323832
}

0 commit comments

Comments
 (0)