Skip to content

Commit

Permalink
Merge pull request #61 from cbou/multiline-in-singleline
Browse files Browse the repository at this point in the history
Single line comment make trouble.
  • Loading branch information
tj committed Jul 5, 2012
2 parents 9c81b77 + b754db4 commit 1b9e8d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/dox.js
Expand Up @@ -30,12 +30,13 @@ exports.parseComments = function(js, options){
, comment
, buf = ''
, ignore
, within
, withinMultiline = false
, withinSignle = false
, code;

for (var i = 0, len = js.length; i < len; ++i) {
// start comment
if (!within && '/' == js[i] && '*' == js[i+1]) {
if (!withinMultiline && !withinSignle && '/' == js[i] && '*' == js[i+1]) {
// code following previous comment
if (buf.trim().length) {
comment = comments[comments.length - 1];
Expand All @@ -46,17 +47,24 @@ exports.parseComments = function(js, options){
buf = '';
}
i += 2;
within = true;
withinMultiline = true;
ignore = '!' == js[i];
// end comment
} else if (within && '*' == js[i] && '/' == js[i+1]) {
} else if (withinMultiline && !withinSignle && '*' == js[i] && '/' == js[i+1]) {
i += 2;
buf = buf.replace(/^ *\* ?/gm, '');
var comment = exports.parseComment(buf, options);
comment.ignore = ignore;
comments.push(comment);
within = ignore = false;
withinMultiline = ignore = false;
buf = '';
} else if (!withinSignle && !withinMultiline && '/' == js[i] && '/' == js[i+1]) {
i += 2;
withinSignle = true;
buf += js[i];
} else if (withinSignle && !withinMultiline && '\n' == js[i]) {
withinSignle = false;
buf += js[i];
// buffer comment or code
} else {
buf += js[i];
Expand Down
9 changes: 9 additions & 0 deletions test/dox.test.js
Expand Up @@ -110,6 +110,15 @@ module.exports = {
parseComment.description.full.should.equal('<p>Parse the given comment <code>str</code>.</p>\n\n<h2>The comment object returned contains the following</h2>\n\n<ul>\n<li><code>tags</code> array of tag objects</li>\n<li><code>description</code> the first line of the comment</li>\n<li><code>body</code> lines following the description</li>\n<li><code>content</code> both the description and the body</li>\n<li><code>isPrivate</code> true when "@api private" is used</li>\n</ul>');
parseComment.description.body.should.equal('<h2>The comment object returned contains the following</h2>\n\n<ul>\n<li><code>tags</code> array of tag objects</li>\n<li><code>description</code> the first line of the comment</li>\n<li><code>body</code> lines following the description</li>\n<li><code>content</code> both the description and the body</li>\n<li><code>isPrivate</code> true when "@api private" is used</li>\n</ul>');

var parseTag = comments.shift();

// Should be the comment be parsed ?
var shouldNotFail = comments.shift();

var parseTagTypes = comments.shift();
parseTagTypes.tags.should.have.length(3);
parseTagTypes.description.full.should.equal('<p>Parse tag type string \"{Array|Object}\" etc.</p>');

var escape = comments.pop();
escape.tags.should.have.length(3);
escape.description.full.should.equal('<p>Escape the given <code>html</code>.</p>');
Expand Down

0 comments on commit 1b9e8d0

Please sign in to comment.