Skip to content

Commit

Permalink
Merge pull request #151 from ChadKillingsworth/linenum-bug
Browse files Browse the repository at this point in the history
Fix line number calculation bug
  • Loading branch information
inikulin authored Sep 1, 2016
2 parents ee55e85 + b9872c4 commit bfcd250
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/location_info/tokenizer_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ exports.assign = function (tokenizer) {

tokenizer._unconsume = function () {
tokenizerProto._unconsume.call(this);
isEol = false;

while (lineStartPos > this.preprocessor.pos && lineStartPosStack.length > 1) {
lineStartPos = lineStartPosStack.pop();
Expand Down
25 changes: 25 additions & 0 deletions test/fixtures/location_info_parser_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,29 @@ testUtils.generateTestsForEachTreeAdapter(module.exports, function (_test, treeA

assert.ok(fragment.childNodes[0].__location.attrs['test-attr']);
};

exports['Regression - location line incorrect when a character is unconsumed (GH-151)'] = function () {
var html = ['<html><body>',
'<script>',
' var x = window.scrollY <',
' 100;',
'</script>',
'</body></html>'].join('\n'),
opts = {
treeAdapter: treeAdapter,
locationInfo: true
};

var doc = parse5.parse(html, opts),
foundScript = false;

walkTree(doc, treeAdapter, function (node) {
if (node.name === 'script') {
foundScript = true;
assert.equal(node.__location.endTag.line, 5);
}
});

assert.ok(foundScript);
};
});

0 comments on commit bfcd250

Please sign in to comment.