Skip to content

Commit d6068f4

Browse files
author
Alexej Yaroshevich
committed
core: parsing whitespaces in description correctly
1 parent 2598d6d commit d6068f4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/jsdoc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ function DocComment(value, loc) {
6262
this.valid = _parsed.hasOwnProperty('line');
6363

6464
// doc parsed data
65-
this.description = _parsed.description || null;
65+
this.description = _parsed.source && _parsed.description ?
66+
_parsed.source.substr(0, _parsed.source.indexOf('\n@')) : null;
67+
6668
this.tags = (_parsed.tags || []).map(function(tag) {
6769
return new DocTag(tag, new DocLocation(tag.line, 3, loc.start));
6870
});

test/lib/jsdoc.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ describe('jsdoc', function() {
127127
'/**\n' +
128128
' * Description\n' +
129129
' * with a new line\n' +
130+
' *\n' +
130131
' * @tag1 value\n' +
131132
' * @param {Type} some long\n' +
132133
' * description of param\n' +
@@ -138,25 +139,26 @@ describe('jsdoc', function() {
138139
});
139140

140141
it('should parses comment and create all tags and types', function() {
142+
expect(c1.description).to.eq('Description\n with a new line\n');
141143
expect(c1.tags.length).to.eq(4);
142144

143145
var tag1 = c1.tags[0];
144146
expect(tag1.id).to.eq('tag1');
145-
expect(tag1.loc).to.eql(new Location(8, 5));
147+
expect(tag1.loc).to.eql(new Location(9, 5));
146148
expect(tag1.name.value).to.eq('value');
147-
expect(tag1.name.loc).to.eql(new Location(8, 11));
149+
expect(tag1.name.loc).to.eql(new Location(9, 11));
148150

149151
var param = c1.tags[1];
150152
expect(param.id).to.eq('param');
151-
expect(param.loc).to.eql(new Location(9, 5));
153+
expect(param.loc).to.eql(new Location(10, 5));
152154
expect(param.type.value).to.eq('Type');
153-
expect(param.type.loc).to.eql(new Location(9, 13));
155+
expect(param.type.loc).to.eql(new Location(10, 13));
154156
expect(param.name.value).to.eq('some');
155-
expect(param.name.loc).to.eql(new Location(9, 19));
157+
expect(param.name.loc).to.eql(new Location(10, 19));
156158

157159
var abs = c1.tags[2];
158160
expect(abs.id).to.eq('abstract');
159-
expect(abs.loc).to.eql(new Location(11, 5));
161+
expect(abs.loc).to.eql(new Location(12, 5));
160162

161163
var example = c1.tags[3];
162164
expect(example.id).to.eq('example');

0 commit comments

Comments
 (0)