mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-05 10:32:08 -05:00
Improve assertion in computePositionOfLineAndCharacter (#21361)
This commit is contained in:
@@ -340,6 +340,10 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function arraysEqual<T>(a: ReadonlyArray<T>, b: ReadonlyArray<T>, equalityComparer: EqualityComparer<T> = equateValues): boolean {
|
||||
return a.length === b.length && a.every((x, i) => equalityComparer(x, b[i]));
|
||||
}
|
||||
|
||||
export function indexOfAnyCharCode(text: string, charCodes: ReadonlyArray<number>, start?: number): number {
|
||||
for (let i = start || 0; i < text.length; i++) {
|
||||
if (contains(charCodes, text.charCodeAt(i))) {
|
||||
|
||||
@@ -335,7 +335,10 @@ namespace ts {
|
||||
|
||||
/* @internal */
|
||||
export function computePositionOfLineAndCharacter(lineStarts: ReadonlyArray<number>, line: number, character: number, debugText?: string): number {
|
||||
Debug.assert(line >= 0 && line < lineStarts.length);
|
||||
if (line < 0 || line >= lineStarts.length) {
|
||||
Debug.fail(`Bad line number. Line: ${line}, lineStarts.length: ${lineStarts.length} , line map is correct? ${debugText !== undefined ? arraysEqual(lineStarts, computeLineStarts(debugText)) : "unknown"}`);
|
||||
}
|
||||
|
||||
const res = lineStarts[line] + character;
|
||||
if (line < lineStarts.length - 1) {
|
||||
Debug.assert(res < lineStarts[line + 1]);
|
||||
|
||||
Reference in New Issue
Block a user