Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #61 from cbou/multiline-in-singleline

Single line comment make trouble.
  • Loading branch information...
commit 1b9e8d07aebedd054d79afe9e651c2b0d1cecfe6 2 parents 9c81b77 + b754db4
TJ Holowaychuk authored
Showing with 22 additions and 5 deletions.
  1. +13 −5 lib/dox.js
  2. +9 −0 test/dox.test.js
18 lib/dox.js
View
@@ -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];
@@ -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];
9 test/dox.test.js
View
@@ -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>');
Please sign in to comment.
Something went wrong with that request. Please try again.