Skip to content

Commit 1cde40e

Browse files
crisbetoalan-agius4
authored andcommitted
fix(@angular/build): correctly remap Angular diagnostics
The esbuild builder has some logic that re-map diagnostics coming from the compiler, depending on their `source` and `code`. Currently this is incorrect, because it assumed that a value of `ngtsc` for `source` always means that the error is from the Angular compiler, but what it actually means is that it comes from an Angular template diagnostics. Furthermore, we can't rely on a `source` always being defined. These changes align the logic to a similar one we already have in the compiler where we assume the diagnostic comes from Angular if it starts with `-99`.
1 parent d96a093 commit 1cde40e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/angular/build/src/tools/esbuild/angular/diagnostics.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,13 @@ export function convertTypeScriptDiagnostic(
7575
): PartialMessage {
7676
let codePrefix = 'TS';
7777
let code = `${diagnostic.code}`;
78-
if (diagnostic.source === 'ngtsc') {
78+
79+
// Custom ngtsc diagnostics are prefixed with -99 which isn't a valid TypeScript diagnostic code.
80+
// Strip it and mark the diagnostic as coming from Angular. Note that we can't rely on
81+
// `diagnostic.source`, because it isn't always produced. This is identical to:
82+
// https://github.com/angular/angular/blob/main/packages/compiler-cli/src/ngtsc/diagnostics/src/util.ts
83+
if (code.startsWith('-99')) {
7984
codePrefix = 'NG';
80-
// Remove `-99` Angular prefix from diagnostic code
8185
code = code.slice(3);
8286
}
8387

0 commit comments

Comments
 (0)