Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Prevent error when using --api & comments have no example code. #80

Merged
merged 1 commit into from

4 participants

@timoxley

Output if trying to use --api flag on anything that doesn't have example code in the comments:

/usr/local/share/npm/lib/node_modules/dox/lib/api.js:25
  code.forEach(function(block){
       ^
TypeError: Cannot call method 'forEach' of null
    at Object.module.exports [as api] (/usr/local/share/npm/lib/node_modules/dox/lib/api.js:25:8)
    at Socket.<anonymous> (/usr/local/share/npm/lib/node_modules/dox/bin/dox:46:30)
    at Socket.EventEmitter.emit (events.js:93:17)
    at Pipe.onread (net.js:418:51)

The offending line:

var code = buf.match(/^( {4}[^\n]+\n*)+/gm); // this may return null

code.forEach(function(block){
  var code = block.replace(/^ {4}/gm, '');
  buf = buf.replace(block, '```js\n' + code.trimRight() + '\n```\n');
});

Simply needs to ensure code is an array before doing the forEach. Patch includes previously failing test.

@tj tj merged commit fbd74c2 into tj:master
@tj
Owner
tj commented

doh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 2 deletions.
  1. +1 −1  lib/api.js
  2. +9 −1 test/dox.test.js
View
2  lib/api.js
@@ -20,7 +20,7 @@ module.exports = function(comments){
.join('\n')
.replace(/^ *#/gm, '')
- var code = buf.match(/^( {4}[^\n]+\n*)+/gm);
+ var code = buf.match(/^( {4}[^\n]+\n*)+/gm) || [];
code.forEach(function(block){
var code = block.replace(/^ {4}/gm, '');
View
10 test/dox.test.js
@@ -311,4 +311,12 @@ module.exports = {
done();
});
},
-};
+ 'test .api() without inline code in comments': function(done) {
+ fixture('a.js', function(err, str){
+ var comments = dox.parseComments(str);
+ var apiDocs = dox.api(comments);
+ apiDocs.should.equal(" - [exports.version](#exportsversion)\n\n## exports.version\n\n <p>Library version.</p>\n");
+ done();
+ });
+ }
+};
Something went wrong with that request. Please try again.