From d6068f48cc460c7114329d678ca2c919611383b8 Mon Sep 17 00:00:00 2001 From: Alexej Yaroshevich Date: Mon, 4 May 2015 00:46:26 +0300 Subject: [PATCH] core: parsing whitespaces in description correctly --- lib/jsdoc.js | 4 +++- test/lib/jsdoc.js | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/jsdoc.js b/lib/jsdoc.js index 9e57319..761dc82 100644 --- a/lib/jsdoc.js +++ b/lib/jsdoc.js @@ -62,7 +62,9 @@ function DocComment(value, loc) { this.valid = _parsed.hasOwnProperty('line'); // doc parsed data - this.description = _parsed.description || null; + this.description = _parsed.source && _parsed.description ? + _parsed.source.substr(0, _parsed.source.indexOf('\n@')) : null; + this.tags = (_parsed.tags || []).map(function(tag) { return new DocTag(tag, new DocLocation(tag.line, 3, loc.start)); }); diff --git a/test/lib/jsdoc.js b/test/lib/jsdoc.js index 37903f1..682017c 100644 --- a/test/lib/jsdoc.js +++ b/test/lib/jsdoc.js @@ -127,6 +127,7 @@ describe('jsdoc', function() { '/**\n' + ' * Description\n' + ' * with a new line\n' + + ' *\n' + ' * @tag1 value\n' + ' * @param {Type} some long\n' + ' * description of param\n' + @@ -138,25 +139,26 @@ describe('jsdoc', function() { }); it('should parses comment and create all tags and types', function() { + expect(c1.description).to.eq('Description\n with a new line\n'); expect(c1.tags.length).to.eq(4); var tag1 = c1.tags[0]; expect(tag1.id).to.eq('tag1'); - expect(tag1.loc).to.eql(new Location(8, 5)); + expect(tag1.loc).to.eql(new Location(9, 5)); expect(tag1.name.value).to.eq('value'); - expect(tag1.name.loc).to.eql(new Location(8, 11)); + expect(tag1.name.loc).to.eql(new Location(9, 11)); var param = c1.tags[1]; expect(param.id).to.eq('param'); - expect(param.loc).to.eql(new Location(9, 5)); + expect(param.loc).to.eql(new Location(10, 5)); expect(param.type.value).to.eq('Type'); - expect(param.type.loc).to.eql(new Location(9, 13)); + expect(param.type.loc).to.eql(new Location(10, 13)); expect(param.name.value).to.eq('some'); - expect(param.name.loc).to.eql(new Location(9, 19)); + expect(param.name.loc).to.eql(new Location(10, 19)); var abs = c1.tags[2]; expect(abs.id).to.eq('abstract'); - expect(abs.loc).to.eql(new Location(11, 5)); + expect(abs.loc).to.eql(new Location(12, 5)); var example = c1.tags[3]; expect(example.id).to.eq('example');