Skip to content

Commit 86a9480

Browse files
committed
Free preProgram early in the test harness
1 parent 87aa917 commit 86a9480

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/harness/compilerImpl.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ export class CompilationResult {
241241
}
242242
}
243243

244+
function getProgramErrors(program: ts.Program, captureSuggestions?: boolean) {
245+
const preEmitErrors = ts.getPreEmitDiagnostics(program);
246+
return captureSuggestions ? ts.concatenate(preEmitErrors, ts.flatMap(program.getSourceFiles(), f => program.getSuggestionDiagnostics(f))) : preEmitErrors;
247+
}
248+
244249
export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | undefined, compilerOptions: ts.CompilerOptions, typeScriptVersion?: string, captureSuggestions?: boolean): CompilationResult {
245250
if (compilerOptions.project || !rootFiles || rootFiles.length === 0) {
246251
const project = readProject(host.parseConfigHost, compilerOptions.project, compilerOptions);
@@ -264,18 +269,13 @@ export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | und
264269
// pre-emit/post-emit error comparison requires declaration emit twice, which can be slow. If it's unlikely to flag any error consistency issues
265270
// and if the test is running `skipLibCheck` - an indicator that we want the tets to run quickly - skip the before/after error comparison, too
266271
const skipErrorComparison = ts.length(rootFiles) >= 100 || (!!compilerOptions.skipLibCheck && !!compilerOptions.declaration);
267-
const preProgram = !skipErrorComparison ? ts.createProgram({ rootNames: rootFiles || [], options: { ...compilerOptions, configFile: compilerOptions.configFile, traceResolution: false }, host, typeScriptVersion }) : undefined;
268-
let preErrors = preProgram && ts.getPreEmitDiagnostics(preProgram);
269-
if (preProgram && captureSuggestions) {
270-
preErrors = ts.concatenate(preErrors, ts.flatMap(preProgram.getSourceFiles(), f => preProgram.getSuggestionDiagnostics(f)));
271-
}
272+
let preProgram = !skipErrorComparison ? ts.createProgram({ rootNames: rootFiles || [], options: { ...compilerOptions, configFile: compilerOptions.configFile, traceResolution: false }, host, typeScriptVersion }) : undefined;
273+
const preErrors = preProgram && getProgramErrors(preProgram, captureSuggestions);
274+
preProgram = undefined; // free memory early
272275

273276
const program = ts.createProgram({ rootNames: rootFiles || [], options: compilerOptions, host, typeScriptVersion });
274277
const emitResult = program.emit();
275-
let postErrors = ts.getPreEmitDiagnostics(program);
276-
if (captureSuggestions) {
277-
postErrors = ts.concatenate(postErrors, ts.flatMap(program.getSourceFiles(), f => program.getSuggestionDiagnostics(f)));
278-
}
278+
const postErrors = getProgramErrors(program, captureSuggestions);
279279
const longerErrors = ts.length(preErrors) > postErrors.length ? preErrors : postErrors;
280280
const shorterErrors = longerErrors === preErrors ? postErrors : preErrors;
281281
const errors = preErrors && (preErrors.length !== postErrors.length) ? [

0 commit comments

Comments
 (0)