From edbffda091ba2744681acb0f27ff2433e7624f2a Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Sun, 26 Aug 2018 13:27:06 -0400 Subject: [PATCH] Cleanup getLineInfo (#8540) Removes an ignore control comment --- packages/babel-parser/src/util/location.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/babel-parser/src/util/location.js b/packages/babel-parser/src/util/location.js index 69df6d27a3..8e2ab59c5a 100644 --- a/packages/babel-parser/src/util/location.js +++ b/packages/babel-parser/src/util/location.js @@ -39,16 +39,14 @@ export class SourceLocation { // into. export function getLineInfo(input: string, offset: number): Position { - for (let line = 1, cur = 0; ; ) { - lineBreakG.lastIndex = cur; - const match = lineBreakG.exec(input); - if (match && match.index < offset) { - ++line; - cur = match.index + match[0].length; - } else { - return new Position(line, offset - cur); - } + let line = 1; + let lineStart = 0; + let match; + lineBreakG.lastIndex = 0; + while ((match = lineBreakG.exec(input)) && match.index < offset) { + line++; + lineStart = lineBreakG.lastIndex; } - // istanbul ignore next - throw new Error("Unreachable"); + + return new Position(line, offset - lineStart); }