Skip to content

Commit

Permalink
fix token offset computation
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed May 6, 2016
1 parent fb6be60 commit 2716b49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
7 changes: 2 additions & 5 deletions lib/parser/scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ var Scanner = function(source, initBlockMode, initLine, initColumn) {

this.pos = source.charCodeAt(0) === 0xFEFF ? 1 : 0;
this.eof = this.pos === this.source.length;
this.lastPos = this.pos;
this.line = typeof initLine === 'undefined' ? 1 : initLine;
this.lineStartPos = typeof initColumn === 'undefined' ? -1 : -initColumn;

Expand Down Expand Up @@ -152,7 +151,7 @@ Scanner.prototype = {
var code = this.source.charCodeAt(this.pos);
var line = this.line;
var column = this.pos - this.lineStartPos;
var lastPos;
var offset = this.pos;
var next;
var type;
var value;
Expand Down Expand Up @@ -225,15 +224,13 @@ Scanner.prototype = {
this.urlMode = this.urlMode || value === 'url';
}

lastPos = this.lastPos === 0 ? this.lastPos : this.lastPos - 1;
this.lastPos = this.pos;
this.eof = this.pos === this.source.length;

return {
type: type,
value: value,

offset: lastPos,
offset: offset,
line: line,
column: column
};
Expand Down
10 changes: 5 additions & 5 deletions test/fixture/stringify.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"type": "Block",
"info": {
"source": "<unknown>",
"offset": 2,
"offset": 3,
"line": 2,
"column": 1
},
Expand All @@ -60,15 +60,15 @@
"type": "Declaration",
"info": {
"source": "<unknown>",
"offset": 4,
"offset": 5,
"line": 3,
"column": 1
},
"property": {
"type": "Property",
"info": {
"source": "<unknown>",
"offset": 4,
"offset": 5,
"line": 3,
"column": 1
},
Expand All @@ -78,7 +78,7 @@
"type": "Value",
"info": {
"source": "<unknown>",
"offset": 10,
"offset": 11,
"line": 3,
"column": 7
},
Expand All @@ -88,7 +88,7 @@
"type": "Identifier",
"info": {
"source": "<unknown>",
"offset": 12,
"offset": 13,
"line": 4,
"column": 1
},
Expand Down

0 comments on commit 2716b49

Please sign in to comment.