From c5e71b594e39bef781f90d2ceb787ddd906da36e Mon Sep 17 00:00:00 2001 From: TEHEK Date: Sun, 22 Nov 2015 16:03:12 -0800 Subject: [PATCH] Fixing issue where input was not consumed via advance() but was skipped when parsing tags resulting in sometimes incorrect reported lineNumber. (fixes #138) --- lib/doctrine.js | 13 ++++++++----- test/parse.js | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/doctrine.js b/lib/doctrine.js index cbfadae..d7ba412 100644 --- a/lib/doctrine.js +++ b/lib/doctrine.js @@ -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 /* '@' */) { @@ -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()) { @@ -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; } // diff --git a/test/parse.js b/test/parse.js index 4ecbf8c..cd0f823 100644 --- a/test/parse.js +++ b/test/parse.js @@ -1947,6 +1947,7 @@ describe('optional params', function() { var res = doctrine.parse( [ "/**", + " * @constructor", " * @param {string} foo", " * @returns {string}", " *", @@ -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() {