diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index 13f05133e9247..6940a65e7c182 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -510,21 +510,25 @@ class AngularCompilerProgram implements Program { if (isSyntaxError(e)) { const parserErrors = getParseErrors(e); if (parserErrors && parserErrors.length) { - this._structuralDiagnostics = - parserErrors.map(e => ({ - messageText: e.contextualMessage(), - category: ts.DiagnosticCategory.Error, - span: e.span, - source: SOURCE, - code: DEFAULT_ERROR_CODE - })); + this._structuralDiagnostics = [ + ...(this._structuralDiagnostics || []), + ...parserErrors.map(e => ({ + messageText: e.contextualMessage(), + category: ts.DiagnosticCategory.Error, + span: e.span, + source: SOURCE, + code: DEFAULT_ERROR_CODE + })) + ]; } else { - this._structuralDiagnostics = [{ - messageText: e.message, - category: ts.DiagnosticCategory.Error, - source: SOURCE, - code: DEFAULT_ERROR_CODE - }]; + this._structuralDiagnostics = [ + ...(this._structuralDiagnostics || []), { + messageText: e.message, + category: ts.DiagnosticCategory.Error, + source: SOURCE, + code: DEFAULT_ERROR_CODE + } + ]; } return null; } diff --git a/packages/compiler-cli/test/ngc_spec.ts b/packages/compiler-cli/test/ngc_spec.ts index 8aef235c519bb..68aa809ad9383 100644 --- a/packages/compiler-cli/test/ngc_spec.ts +++ b/packages/compiler-cli/test/ngc_spec.ts @@ -1391,5 +1391,44 @@ describe('ngc transformer command-line', () => { main(['-p', path.join(basePath, 'src/tsconfig.json')], message => messages.push(message)); expect(exitCode).toBe(0, 'Compile failed unexpectedly.\n ' + messages.join('\n ')); }); + + it('should emit all structural errors', () => { + write('src/tsconfig.json', `{ + "extends": "../tsconfig-base.json", + "files": ["test-module.ts"] + }`); + write('src/lib/indirect2.ts', ` + declare var f: any; + export const t2 = f\`

hello

\`; + `); + write('src/lib/indirect1.ts', ` + import {t2} from './indirect2'; + export const t1 = t2 + ' '; + `); + write('src/lib/test.component.ts', ` + import {Component} from '@angular/core'; + import {t1} from './indirect1'; + + @Component({ + template: t1 + }) + export class TestComponent {} + `); + write('src/test-module.ts', ` + import {NgModule} from '@angular/core'; + import {TestComponent} from './lib/test.component'; + + @NgModule({declarations: [TestComponent]}) + export class TestModule {} + `); + const messages: string[] = []; + const exitCode = + main(['-p', path.join(basePath, 'src/tsconfig.json')], message => messages.push(message)); + expect(exitCode).toBe(1, 'Compile was expected to fail'); + expect(messages).toEqual([ + 'Error: Error: Error encountered resolving symbol values statically. Tagged template expressions are not supported in metadata (position 3:27 in the original .ts file)\n' + + 'Error: No template specified for component TestComponent\n' + ]); + }); }); });