mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 04:43:37 -05:00
Use correct state when getting it from redirected program (#44275)
Eg. program can backup and restore state changing the state object and we want to release program on the correct one This ensure program is released correctly when there are declaration emit errors during tsc --build
This commit is contained in:
@@ -976,8 +976,9 @@ namespace ts {
|
||||
oldProgram = undefined;
|
||||
oldState = undefined;
|
||||
|
||||
const builderProgram = createRedirectedBuilderProgram(state, configFileParsingDiagnostics);
|
||||
builderProgram.getState = () => state;
|
||||
const getState = () => state;
|
||||
const builderProgram = createRedirectedBuilderProgram(getState, configFileParsingDiagnostics);
|
||||
builderProgram.getState = getState;
|
||||
builderProgram.backupState = () => {
|
||||
Debug.assert(backupState === undefined);
|
||||
backupState = cloneBuilderProgramState(state);
|
||||
@@ -1306,15 +1307,15 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function createRedirectedBuilderProgram(state: { program: Program | undefined; compilerOptions: CompilerOptions; }, configFileParsingDiagnostics: readonly Diagnostic[]): BuilderProgram {
|
||||
export function createRedirectedBuilderProgram(getState: () => { program: Program | undefined; compilerOptions: CompilerOptions; }, configFileParsingDiagnostics: readonly Diagnostic[]): BuilderProgram {
|
||||
return {
|
||||
getState: notImplemented,
|
||||
backupState: noop,
|
||||
restoreState: noop,
|
||||
getProgram,
|
||||
getProgramOrUndefined: () => state.program,
|
||||
releaseProgram: () => state.program = undefined,
|
||||
getCompilerOptions: () => state.compilerOptions,
|
||||
getProgramOrUndefined: () => getState().program,
|
||||
releaseProgram: () => getState().program = undefined,
|
||||
getCompilerOptions: () => getState().compilerOptions,
|
||||
getSourceFile: fileName => getProgram().getSourceFile(fileName),
|
||||
getSourceFiles: () => getProgram().getSourceFiles(),
|
||||
getOptionsDiagnostics: cancellationToken => getProgram().getOptionsDiagnostics(cancellationToken),
|
||||
@@ -1331,7 +1332,7 @@ namespace ts {
|
||||
};
|
||||
|
||||
function getProgram() {
|
||||
return Debug.checkDefined(state.program);
|
||||
return Debug.checkDefined(getState().program);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +164,6 @@ namespace ts {
|
||||
export function createAbstractBuilder(rootNames: readonly string[] | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: readonly Diagnostic[], projectReferences?: readonly ProjectReference[]): BuilderProgram;
|
||||
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 {
|
||||
const { newProgram, configFileParsingDiagnostics: newConfigFileParsingDiagnostics } = getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics, projectReferences);
|
||||
return createRedirectedBuilderProgram({ program: newProgram, compilerOptions: newProgram.getCompilerOptions() }, newConfigFileParsingDiagnostics);
|
||||
return createRedirectedBuilderProgram(() => ({ program: newProgram, compilerOptions: newProgram.getCompilerOptions() }), newConfigFileParsingDiagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ Output::
|
||||
|
||||
Program root files: ["/user/username/projects/solution/app/fileWithError.ts","/user/username/projects/solution/app/fileWithoutError.ts"]
|
||||
Program options: {"composite":true,"watch":true,"configFilePath":"/user/username/projects/solution/app/tsconfig.json"}
|
||||
Program structureReused: Completely
|
||||
Program structureReused: Not
|
||||
Program files::
|
||||
/a/lib/lib.d.ts
|
||||
/user/username/projects/solution/app/fileWithError.ts
|
||||
|
||||
@@ -213,7 +213,7 @@ Output::
|
||||
|
||||
Program root files: ["/user/username/projects/solution/app/fileWithError.ts","/user/username/projects/solution/app/fileWithoutError.ts"]
|
||||
Program options: {"composite":true,"watch":true,"configFilePath":"/user/username/projects/solution/app/tsconfig.json"}
|
||||
Program structureReused: Completely
|
||||
Program structureReused: Not
|
||||
Program files::
|
||||
/a/lib/lib.d.ts
|
||||
/user/username/projects/solution/app/fileWithError.ts
|
||||
|
||||
@@ -91,7 +91,7 @@ Output::
|
||||
|
||||
Program root files: ["/user/username/projects/solution/app/fileWithError.ts","/user/username/projects/solution/app/fileWithoutError.ts"]
|
||||
Program options: {"composite":true,"watch":true,"configFilePath":"/user/username/projects/solution/app/tsconfig.json"}
|
||||
Program structureReused: Completely
|
||||
Program structureReused: Not
|
||||
Program files::
|
||||
/a/lib/lib.d.ts
|
||||
/user/username/projects/solution/app/fileWithError.ts
|
||||
|
||||
@@ -89,7 +89,7 @@ Output::
|
||||
|
||||
Program root files: ["/user/username/projects/solution/app/fileWithError.ts","/user/username/projects/solution/app/fileWithoutError.ts"]
|
||||
Program options: {"composite":true,"watch":true,"configFilePath":"/user/username/projects/solution/app/tsconfig.json"}
|
||||
Program structureReused: Completely
|
||||
Program structureReused: Not
|
||||
Program files::
|
||||
/a/lib/lib.d.ts
|
||||
/user/username/projects/solution/app/fileWithError.ts
|
||||
|
||||
Reference in New Issue
Block a user