From a469c2c41202cff6850e411cc04a94df788c0e4a Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Thu, 23 Aug 2018 14:33:38 -0700 Subject: [PATCH] feat(ivy): produce contextual diagnostics in ngtsc mode (#25647) TypeScript has a more modern diagnostic emit function which produces contextually annotated error information, using colors in the console to indicate where in the code the error occurs. This commit swiches ngtsc to use this format for diagnostics when emitting them after a failed compilation. PR Close #25647 --- packages/compiler-cli/BUILD.bazel | 1 + packages/compiler-cli/src/main.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/BUILD.bazel b/packages/compiler-cli/BUILD.bazel index 484a2f6303..d88a524840 100644 --- a/packages/compiler-cli/BUILD.bazel +++ b/packages/compiler-cli/BUILD.bazel @@ -26,6 +26,7 @@ ts_library( deps = [ "//packages/compiler", "//packages/compiler-cli/src/ngtsc/annotations", + "//packages/compiler-cli/src/ngtsc/diagnostics", "//packages/compiler-cli/src/ngtsc/factories", "//packages/compiler-cli/src/ngtsc/metadata", "//packages/compiler-cli/src/ngtsc/transform", diff --git a/packages/compiler-cli/src/main.ts b/packages/compiler-cli/src/main.ts index 4210b715f1..f7c29cfa4f 100644 --- a/packages/compiler-cli/src/main.ts +++ b/packages/compiler-cli/src/main.ts @@ -12,6 +12,8 @@ import 'reflect-metadata'; import * as ts from 'typescript'; import * as tsickle from 'tsickle'; + +import {replaceTsWithNgInErrors} from './ngtsc/diagnostics'; import * as api from './transformers/api'; import {GENERATED_FILES} from './transformers/util'; @@ -160,7 +162,15 @@ function reportErrorsAndExit( getCanonicalFileName: fileName => fileName, getNewLine: () => ts.sys.newLine }; - consoleError(formatDiagnostics(errorsAndWarnings, formatHost)); + if (options && (options.enableIvy === true || options.enableIvy === 'ngtsc')) { + const ngDiagnostics = errorsAndWarnings.filter(api.isNgDiagnostic); + const tsDiagnostics = errorsAndWarnings.filter(api.isTsDiagnostic); + consoleError(replaceTsWithNgInErrors( + ts.formatDiagnosticsWithColorAndContext(tsDiagnostics, formatHost))); + consoleError(formatDiagnostics(ngDiagnostics, formatHost)); + } else { + consoleError(formatDiagnostics(errorsAndWarnings, formatHost)); + } } return exitCodeFromResult(allDiagnostics); }