Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit db5b76c

Browse files
committed
[Fix] Error fixes
1 parent affa854 commit db5b76c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/errors.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,24 +302,33 @@ Errors.getPosition = function(element, offset) {
302302

303303
var pos = loc.start;
304304

305+
if (offset === 0) {
306+
return pos;
307+
}
308+
305309
var newlineCount = element.getNewlineCount();
306310
if (newlineCount > 0) {
307311
var code = element.getSourceCode();
308312
LINE_SEPARATOR.lastIndex = 0;
309313
var lineOffset = 0;
310314
var match;
315+
var previousOffset = 0;
316+
var firstLineColumnOffset = pos.column;
311317
while ((match = LINE_SEPARATOR.exec(code)) !== null) {
312318
var currentOffset = match.index;
313319
if (offset <= currentOffset) {
314320
return {
315321
line: pos.line + lineOffset,
316-
column: currentOffset - offset
322+
column: firstLineColumnOffset + offset - previousOffset
317323
};
318324
}
325+
previousOffset = currentOffset + match[0].length;
326+
firstLineColumnOffset = 0;
327+
lineOffset++;
319328
}
320329
return {
321330
line: pos.line + newlineCount,
322-
column: code.length - offset
331+
column: offset - previousOffset
323332
};
324333
} else {
325334
pos = {

0 commit comments

Comments
 (0)