@@ -28,6 +28,7 @@ import {
28
28
createCompilerHost ,
29
29
createProgram ,
30
30
formatDiagnostics ,
31
+ isNgDiagnostic ,
31
32
readConfiguration ,
32
33
} from '@angular/compiler-cli' ;
33
34
import { ChildProcess , ForkOptions , fork } from 'child_process' ;
@@ -1010,19 +1011,57 @@ export class AngularCompilerPlugin {
1010
1011
const { emitResult, diagnostics } = this . _emit ( ) ;
1011
1012
timeEnd ( 'AngularCompilerPlugin._update._emit' ) ;
1012
1013
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
+ }
1018
1057
1019
- if ( errors . length > 0 ) {
1020
- const message = formatDiagnostics ( errors ) ;
1058
+ if ( ngErrors . length > 0 ) {
1059
+ const message = formatDiagnostics ( ngErrors ) ;
1021
1060
this . _errors . push ( new Error ( message ) ) ;
1022
1061
}
1023
1062
1024
- if ( warnings . length > 0 ) {
1025
- const message = formatDiagnostics ( warnings ) ;
1063
+ if ( ngWarnings . length > 0 ) {
1064
+ const message = formatDiagnostics ( ngWarnings ) ;
1026
1065
this . _warnings . push ( message ) ;
1027
1066
}
1028
1067
0 commit comments