From 36ac0c8f59c8488b017af132de2c71cbd911dd79 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Thu, 12 Mar 2015 10:16:28 -0700 Subject: [PATCH] Add additional asserts to ensure we don't create diagnostics with bogus positions. --- src/compiler/core.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 1fb73c9069..463473497c 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -269,8 +269,12 @@ module ts { export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage, ...args: any[]): Diagnostic; export function createFileDiagnostic(file: SourceFile, start: number, length: number, message: DiagnosticMessage): Diagnostic { + var end = start + length; + Debug.assert(start >= 0, "start must be non-negative, is " + start); Debug.assert(length >= 0, "length must be non-negative, is " + length); + Debug.assert(start <= file.text.length, `start must be within the bounds of the file. ${ start } > ${ file.text.length }`); + Debug.assert(end <= file.text.length, `end must be the bounds of the file. ${ end } > ${ file.text.length }`); var text = getLocaleSpecificMessage(message.key);