fix(compiler-cli): don't report emit diagnostics when --noEmitOnError is off (#20063)
This commit is contained in:
parent
17ed14faea
commit
5b16ce9302
|
@ -22,3 +22,5 @@ export * from './src/perform_compile';
|
||||||
// and usages in G3 are changed to `CompilerOptions`.
|
// and usages in G3 are changed to `CompilerOptions`.
|
||||||
export {CompilerOptions as AngularCompilerOptions} from './src/transformers/api';
|
export {CompilerOptions as AngularCompilerOptions} from './src/transformers/api';
|
||||||
export {NgTools_InternalApi_NG_2 as __NGTOOLS_PRIVATE_API_2} from './src/ngtools_api';
|
export {NgTools_InternalApi_NG_2 as __NGTOOLS_PRIVATE_API_2} from './src/ngtools_api';
|
||||||
|
|
||||||
|
export {ngToTsDiagnostic} from './src/transformers/util';
|
||||||
|
|
|
@ -300,10 +300,16 @@ class AngularCompilerProgram implements Program {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.emittedSourceFiles = emittedSourceFiles;
|
this.emittedSourceFiles = emittedSourceFiles;
|
||||||
|
|
||||||
|
// Match behavior of tsc: only produce emit diagnostics if it would block
|
||||||
|
// emit. If noEmitOnError is false, the emit will happen in spite of any
|
||||||
|
// errors, so we should not report them.
|
||||||
|
if (this.options.noEmitOnError === true) {
|
||||||
// translate the diagnostics in the emitResult as well.
|
// translate the diagnostics in the emitResult as well.
|
||||||
const translatedEmitDiags = translateDiagnostics(this.hostAdapter, emitResult.diagnostics);
|
const translatedEmitDiags = translateDiagnostics(this.hostAdapter, emitResult.diagnostics);
|
||||||
emitResult.diagnostics = translatedEmitDiags.ts.concat(
|
emitResult.diagnostics = translatedEmitDiags.ts.concat(
|
||||||
this.structuralDiagnostics.concat(translatedEmitDiags.ng).map(ngToTsDiagnostic));
|
this.structuralDiagnostics.concat(translatedEmitDiags.ng).map(ngToTsDiagnostic));
|
||||||
|
}
|
||||||
|
|
||||||
if (!outSrcMapping.length) {
|
if (!outSrcMapping.length) {
|
||||||
// if no files were emitted by TypeScript, also don't emit .json files
|
// if no files were emitted by TypeScript, also don't emit .json files
|
||||||
|
|
|
@ -893,6 +893,19 @@ describe('ng program', () => {
|
||||||
`src/main.html(1,1): error TS100: Property 'nonExistent' does not exist on type 'MyComp'.`);
|
`src/main.html(1,1): error TS100: Property 'nonExistent' does not exist on type 'MyComp'.`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not report emit errors with noEmitOnError=false', () => {
|
||||||
|
testSupport.writeFiles({
|
||||||
|
'src/main.ts': `
|
||||||
|
@NgModule()
|
||||||
|
`
|
||||||
|
});
|
||||||
|
const options = testSupport.createCompilerOptions({noEmitOnError: false});
|
||||||
|
const host = ng.createCompilerHost({options});
|
||||||
|
const program1 = ng.createProgram(
|
||||||
|
{rootNames: [path.resolve(testSupport.basePath, 'src/main.ts')], options, host});
|
||||||
|
expect(program1.emit().diagnostics.length).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
describe('errors', () => {
|
describe('errors', () => {
|
||||||
const fileWithStructuralError = `
|
const fileWithStructuralError = `
|
||||||
import {NgModule} from '@angular/core';
|
import {NgModule} from '@angular/core';
|
||||||
|
|
Loading…
Reference in New Issue