diff --git a/packages/angular/build/src/tools/angular/compilation/diagnostics.ts b/packages/angular/build/src/tools/angular/compilation/diagnostics.ts
index bf85b69f707c..41563b90ebbd 100644
--- a/packages/angular/build/src/tools/angular/compilation/diagnostics.ts
+++ b/packages/angular/build/src/tools/angular/compilation/diagnostics.ts
@@ -37,7 +37,7 @@ function convertTypeScriptDiagnosticInfo(
};
// Calculate the line/column location and extract the full line text that has the diagnostic
- if (info.start) {
+ if (info.start !== undefined) {
const { line, character } = typescript.getLineAndCharacterOfPosition(info.file, info.start);
note.location.line = line + 1;
note.location.column = character;
@@ -50,7 +50,7 @@ function convertTypeScriptDiagnosticInfo(
// will error if a nonexistent line is passed).
const { line: lastLineOfFile } = typescript.getLineAndCharacterOfPosition(
info.file,
- info.file.text.length - 1,
+ Math.max(0, info.file.text.length - 1),
);
const lineEndPosition =
line < lastLineOfFile
diff --git a/packages/angular/build/src/tools/angular/compilation/diagnostics_spec.ts b/packages/angular/build/src/tools/angular/compilation/diagnostics_spec.ts
new file mode 100644
index 000000000000..8ea79c20ba43
--- /dev/null
+++ b/packages/angular/build/src/tools/angular/compilation/diagnostics_spec.ts
@@ -0,0 +1,111 @@
+/**
+ * @license
+ * Copyright Google LLC All Rights Reserved.
+ *
+ * Use of this source code is governed by an MIT-style license that can be
+ * found in the LICENSE file at https://angular.dev/license
+ */
+
+import ts from 'typescript';
+import { convertTypeScriptDiagnostic } from './diagnostics';
+
+describe('convertTypeScriptDiagnostic', () => {
+ it('populates line, column, and lineText when diagnostic or relatedInformation starts at offset 0', () => {
+ const sourceFile = ts.createSourceFile(
+ '/src/app/app.component.ts',
+ 'const invalid: number = "string";\nconst secondLine = 2;\n',
+ ts.ScriptTarget.Latest,
+ );
+ const templateFile = ts.createSourceFile(
+ '/src/app/app.component.html',
+ '