From cf9aa4fd14a4e69ec5c95ba851748b4a5a90b23c Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Tue, 12 Nov 2019 13:38:23 -0800 Subject: [PATCH] test(ivy): driveDiagnostics() works incrementally (#33862) PR Close #33862 --- packages/compiler-cli/src/main.ts | 25 ++++++++++++++++++++++--- packages/compiler-cli/test/ngtsc/env.ts | 19 ++++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/packages/compiler-cli/src/main.ts b/packages/compiler-cli/src/main.ts index aad3add832..2ec68243c8 100644 --- a/packages/compiler-cli/src/main.ts +++ b/packages/compiler-cli/src/main.ts @@ -56,14 +56,33 @@ export function main( } export function mainDiagnosticsForTest( - args: string[], config?: NgcParsedConfiguration): ReadonlyArray { + args: string[], config?: NgcParsedConfiguration, + programReuse?: {program: api.Program | undefined}, + modifiedResourceFiles?: Set| null): ReadonlyArray { let {project, rootNames, options, errors: configErrors, watch, emitFlags} = config || readNgcCommandLineAndConfiguration(args); if (configErrors.length) { return configErrors; } - const {diagnostics: compileDiags} = performCompilation( - {rootNames, options, emitFlags, emitCallback: createEmitCallback(options)}); + + let oldProgram: api.Program|undefined; + if (programReuse !== undefined) { + oldProgram = programReuse.program; + } + + const {diagnostics: compileDiags, program} = performCompilation({ + rootNames, + options, + emitFlags, + oldProgram, + modifiedResourceFiles, + emitCallback: createEmitCallback(options), + }); + + if (programReuse !== undefined) { + programReuse.program = program; + } + return compileDiags; } diff --git a/packages/compiler-cli/test/ngtsc/env.ts b/packages/compiler-cli/test/ngtsc/env.ts index 0eb391b783..66b242fa7e 100644 --- a/packages/compiler-cli/test/ngtsc/env.ts +++ b/packages/compiler-cli/test/ngtsc/env.ts @@ -54,6 +54,7 @@ export class NgtscTestEnvironment { "experimentalDecorators": true, "skipLibCheck": true, "noImplicitAny": true, + "noEmitOnError": true, "strictNullChecks": true, "outDir": "built", "baseUrl": ".", @@ -199,7 +200,23 @@ export class NgtscTestEnvironment { */ driveDiagnostics(): ReadonlyArray { // ngtsc only produces ts.Diagnostic messages. - return mainDiagnosticsForTest(['-p', this.basePath]) as ts.Diagnostic[]; + let reuseProgram: {program: Program | undefined}|undefined = undefined; + if (this.multiCompileHostExt !== null) { + reuseProgram = { + program: this.oldProgram || undefined, + }; + } + + const diags = mainDiagnosticsForTest( + ['-p', this.basePath], undefined, reuseProgram, this.changedResources); + + + if (this.multiCompileHostExt !== null) { + this.oldProgram = reuseProgram !.program !; + } + + // In ngtsc, only `ts.Diagnostic`s are produced. + return diags as ReadonlyArray; } async driveDiagnosticsAsync(): Promise> {