Skip to content
This repository
Browse code

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 July 05, 2012
18  lib/dox.js
@@ -30,12 +30,13 @@ exports.parseComments = function(js, options){
30 30
     , comment
31 31
     , buf = ''
32 32
     , ignore
33  
-    , within
  33
+    , withinMultiline = false
  34
+    , withinSignle = false
34 35
     , code;
35 36
 
36 37
   for (var i = 0, len = js.length; i < len; ++i) {
37 38
     // start comment
38  
-    if (!within && '/' == js[i] && '*' == js[i+1]) {
  39
+    if (!withinMultiline && !withinSignle && '/' == js[i] && '*' == js[i+1]) {
39 40
       // code following previous comment
40 41
       if (buf.trim().length) {
41 42
         comment = comments[comments.length - 1];
@@ -46,17 +47,24 @@ exports.parseComments = function(js, options){
46 47
         buf = '';
47 48
       }
48 49
       i += 2;
49  
-      within = true;
  50
+      withinMultiline = true;
50 51
       ignore = '!' == js[i];
51 52
     // end comment
52  
-    } else if (within && '*' == js[i] && '/' == js[i+1]) {
  53
+    } else if (withinMultiline && !withinSignle && '*' == js[i] && '/' == js[i+1]) {
53 54
       i += 2;
54 55
       buf = buf.replace(/^ *\* ?/gm, '');
55 56
       var comment = exports.parseComment(buf, options);
56 57
       comment.ignore = ignore;
57 58
       comments.push(comment);
58  
-      within = ignore = false;
  59
+      withinMultiline = ignore = false;
59 60
       buf = '';
  61
+    } else if (!withinSignle && !withinMultiline && '/' == js[i] && '/' == js[i+1]) {
  62
+      i += 2;
  63
+      withinSignle = true;
  64
+      buf += js[i];
  65
+    } else if (withinSignle && !withinMultiline && '\n' == js[i]) {
  66
+      withinSignle = false;
  67
+      buf += js[i];
60 68
     // buffer comment or code
61 69
     } else {
62 70
       buf += js[i];
9  test/dox.test.js
@@ -110,6 +110,15 @@ module.exports = {
110 110
       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>');
111 111
       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>');
112 112
 
  113
+      var parseTag = comments.shift();
  114
+      
  115
+      // Should be the comment be parsed ?
  116
+      var shouldNotFail = comments.shift();
  117
+
  118
+      var parseTagTypes = comments.shift();
  119
+      parseTagTypes.tags.should.have.length(3);
  120
+      parseTagTypes.description.full.should.equal('<p>Parse tag type string \"{Array|Object}\" etc.</p>');
  121
+      
113 122
       var escape = comments.pop();
114 123
       escape.tags.should.have.length(3);
115 124
       escape.description.full.should.equal('<p>Escape the given <code>html</code>.</p>');

0 notes on commit 1b9e8d0

Please sign in to comment.
Something went wrong with that request. Please try again.