Add additional asserts to ensure we don't create diagnostics with bogus positions.

This commit is contained in:
Cyrus Najmabadi 2015-03-12 10:16:28 -07:00
parent b38743c793
commit 36ac0c8f59

View File

@ -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);