@@ -28,6 +28,7 @@ import {
2828 createCompilerHost ,
2929 createProgram ,
3030 formatDiagnostics ,
31+ isNgDiagnostic ,
3132 readConfiguration ,
3233} from '@angular/compiler-cli' ;
3334import { ChildProcess , ForkOptions , fork } from 'child_process' ;
@@ -1010,19 +1011,57 @@ export class AngularCompilerPlugin {
10101011 const { emitResult, diagnostics } = this . _emit ( ) ;
10111012 timeEnd ( 'AngularCompilerPlugin._update._emit' ) ;
10121013
1013- // Report diagnostics.
1014- const errors = diagnostics
1015- . filter ( ( diag ) => diag . category === ts . DiagnosticCategory . Error ) ;
1016- const warnings = diagnostics
1017- . filter ( ( diag ) => diag . category === ts . DiagnosticCategory . Warning ) ;
1014+ // Report Diagnostics
1015+ const tsErrors = [ ] ;
1016+ const tsWarnings = [ ] ;
1017+ const ngErrors = [ ] ;
1018+ const ngWarnings = [ ] ;
1019+
1020+ for ( const diagnostic of diagnostics ) {
1021+ switch ( diagnostic . category ) {
1022+ case ts . DiagnosticCategory . Error :
1023+ if ( isNgDiagnostic ( diagnostic ) ) {
1024+ ngErrors . push ( diagnostic ) ;
1025+ } else {
1026+ tsErrors . push ( diagnostic ) ;
1027+ }
1028+ break ;
1029+ case ts . DiagnosticCategory . Message :
1030+ case ts . DiagnosticCategory . Suggestion :
1031+ // Warnings?
1032+ case ts . DiagnosticCategory . Warning :
1033+ if ( isNgDiagnostic ( diagnostic ) ) {
1034+ ngWarnings . push ( diagnostic ) ;
1035+ } else {
1036+ tsWarnings . push ( diagnostic ) ;
1037+ }
1038+ break ;
1039+ }
1040+ }
1041+
1042+ if ( tsErrors . length > 0 ) {
1043+ const message = ts . formatDiagnosticsWithColorAndContext (
1044+ tsErrors ,
1045+ this . _compilerHost ,
1046+ ) ;
1047+ this . _errors . push ( new Error ( message ) ) ;
1048+ }
1049+
1050+ if ( tsWarnings . length > 0 ) {
1051+ const message = ts . formatDiagnosticsWithColorAndContext (
1052+ tsWarnings ,
1053+ this . _compilerHost ,
1054+ ) ;
1055+ this . _warnings . push ( message ) ;
1056+ }
10181057
1019- if ( errors . length > 0 ) {
1020- const message = formatDiagnostics ( errors ) ;
1058+ if ( ngErrors . length > 0 ) {
1059+ const message = formatDiagnostics ( ngErrors ) ;
10211060 this . _errors . push ( new Error ( message ) ) ;
10221061 }
10231062
1024- if ( warnings . length > 0 ) {
1025- const message = formatDiagnostics ( warnings ) ;
1063+ if ( ngWarnings . length > 0 ) {
1064+ const message = formatDiagnostics ( ngWarnings ) ;
10261065 this . _warnings . push ( message ) ;
10271066 }
10281067
0 commit comments