fix(compiler): switch to modern diagnostic formatting (#34234)

The compiler exports a `formatDiagnostics` function which consumers can use
to print both ts and ng diagnostics. However, this function was previously
using the "old" style TypeScript diagnostics, as opposed to the modern
diagnostic printer which uses terminal colors and prints additional context
information.

This commit updates `formatDiagnostics` to use the modern formatter, plus to
update Ivy's negative error codes to Angular 'NG' errors.

The Angular CLI needs a little more work to use this function for printing
TS diagnostics, but this commit alone should fix Bazel builds as ngc-wrapped
goes through `formatDiagnostics`.

PR Close #34234
This commit is contained in:
Alex Rickabaugh
2019-12-04 10:44:32 -08:00
committed by Andrew Kushnir
parent 13c2fad240
commit 9fa2c398e7
5 changed files with 35 additions and 28 deletions

View File

@ -8,7 +8,10 @@
import {Position, isSyntaxError} from '@angular/compiler';
import * as ts from 'typescript';
import {AbsoluteFsPath, absoluteFrom, getFileSystem, relative, resolve} from '../src/ngtsc/file_system';
import {replaceTsWithNgInErrors} from './ngtsc/diagnostics';
import * as api from './transformers/api';
import * as ng from './transformers/entry_points';
import {createMessageDiagnostic} from './transformers/util';
@ -94,7 +97,8 @@ export function formatDiagnostics(
return diags
.map(diagnostic => {
if (api.isTsDiagnostic(diagnostic)) {
return ts.formatDiagnostics([diagnostic], host);
return replaceTsWithNgInErrors(
ts.formatDiagnosticsWithColorAndContext([diagnostic], host));
} else {
return formatDiagnostic(diagnostic, host);
}