Skip to content

Commit 36ac0c8

Browse files
Add additional asserts to ensure we don't create diagnostics with bogus positions.
1 parent b38743c commit 36ac0c8

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/compiler/core.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,12 @@ module ts {
269269

270270
export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic;
271271
export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage): Diagnostic {
272+
var end = start + length;
273+
272274
Debug.assert(start >= 0, "start must be non-negative, is " + start);
273275
Debug.assert(length >= 0, "length must be non-negative, is " + length);
276+
Debug.assert(start <= file.text.length, `start must be within the bounds of the file. ${ start } > ${ file.text.length }`);
277+
Debug.assert(end <= file.text.length, `end must be the bounds of the file. ${ end } > ${ file.text.length }`);
274278

275279
var text = getLocaleSpecificMessage(message.key);
276280

0 commit comments

Comments
 (0)