Skip to content

Commit

Permalink
Fixing issue where input was not consumed via advance() but was skipp…
Browse files Browse the repository at this point in the history
…ed when parsing tags resulting in sometimes incorrect reported lineNumber.

(fixes eslint#138)
  • Loading branch information
TEHEK committed Nov 24, 2015
1 parent b393828 commit c5e71b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/doctrine.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@
while (last < length) {
ch = source.charCodeAt(last);
if (esutils.code.isLineTerminator(ch) && !(ch === 0x0D /* '\r' */ && source.charCodeAt(last + 1) === 0x0A /* '\n' */)) {
lineNumber += 1;
waiting = true;
} else if (waiting) {
if (ch === 0x40 /* '@' */) {
Expand Down Expand Up @@ -709,13 +708,11 @@
}
}

// Seek global index to end of this tag.
index = this._last;
return this._tag;
};

function parseTag(options) {
var title, parser;
var title, parser, tag;

// skip to tag
if (!skipToTag()) {
Expand All @@ -727,7 +724,13 @@

// construct tag parser
parser = new TagParser(options, title);
return parser.parse();
tag = parser.parse();

// Seek global index to end of this tag.
while (index < parser._last) {
advance();
}
return tag;
}

//
Expand Down
4 changes: 3 additions & 1 deletion test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1947,6 +1947,7 @@ describe('optional params', function() {
var res = doctrine.parse(
[
"/**",
" * @constructor",
" * @param {string} foo",
" * @returns {string}",
" *",
Expand All @@ -1959,7 +1960,8 @@ describe('optional params', function() {

res.tags[0].should.have.property('lineNumber', 1);
res.tags[1].should.have.property('lineNumber', 2);
res.tags[2].should.have.property('lineNumber', 4);
res.tags[2].should.have.property('lineNumber', 3);
res.tags[3].should.have.property('lineNumber', 5);
});

it('should handle \\r\\n line endings correctly', function() {
Expand Down

0 comments on commit c5e71b5

Please sign in to comment.