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

Commit

Permalink
[Fix] Error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevils committed Apr 13, 2016
1 parent affa854 commit db5b76c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/errors.js
Expand Up @@ -302,24 +302,33 @@ Errors.getPosition = function(element, offset) {

var pos = loc.start;

if (offset === 0) {
return pos;
}

var newlineCount = element.getNewlineCount();
if (newlineCount > 0) {
var code = element.getSourceCode();
LINE_SEPARATOR.lastIndex = 0;
var lineOffset = 0;
var match;
var previousOffset = 0;
var firstLineColumnOffset = pos.column;
while ((match = LINE_SEPARATOR.exec(code)) !== null) {
var currentOffset = match.index;
if (offset <= currentOffset) {
return {
line: pos.line + lineOffset,
column: currentOffset - offset
column: firstLineColumnOffset + offset - previousOffset
};
}
previousOffset = currentOffset + match[0].length;
firstLineColumnOffset = 0;
lineOffset++;
}
return {
line: pos.line + newlineCount,
column: code.length - offset
column: offset - previousOffset
};
} else {
pos = {
Expand Down

0 comments on commit db5b76c

Please sign in to comment.