Skip to content

Commit

Permalink
add offset to parse error details
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed May 6, 2016
1 parent 2716b49 commit a46e072
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,19 @@ var blockMode = {

function parseError(message) {
var error = new Error(message);
var offset = 0;
var line = 1;
var column = 1;
var lines;

if (scanner.token !== null) {
offset = scanner.token.offset;
line = scanner.token.line;
column = scanner.token.column;
} else if (scanner.prevToken !== null) {
lines = scanner.prevToken.value.trimRight().split(/\n|\r\n?|\f/);
lines = scanner.prevToken.value.trimRight();
offset = scanner.prevToken.offset + lines.length;
lines = lines.split(/\n|\r\n?|\f/);
line = scanner.prevToken.line + lines.length - 1;
column = lines.length > 1
? lines[lines.length - 1].length + 1
Expand All @@ -61,6 +65,7 @@ function parseError(message) {

error.name = 'CssSyntaxError';
error.parseError = {
offset: offset,
line: line,
column: column
};
Expand Down
Loading

0 comments on commit a46e072

Please sign in to comment.