mirror of
https://github.com/documentationjs/documentation.git
synced 2026-01-25 14:26:29 +00:00
parent
fb5afc4428
commit
5c192845c9
21
index.js
21
index.js
@ -13,11 +13,26 @@ var externalModuleRegexp = process.platform === 'win32' ?
|
||||
/^(\.|\w:)/ :
|
||||
/^[\/.]/;
|
||||
|
||||
/**
|
||||
* Detect whether a comment is a JSDoc comment: it should start with
|
||||
* two asterisks, not any other number of asterisks.
|
||||
*
|
||||
* The code parser automatically strips out the first asterisk that's
|
||||
* required for the comment to be a comment at all, so we count the remaining
|
||||
* comments.
|
||||
* @param {String} comment
|
||||
* @return {boolean} whether it is valid
|
||||
*/
|
||||
function isJSDocComment(code) {
|
||||
var asterisks = code.match(/^(\*+)/);
|
||||
return asterisks && asterisks[ 1 ].length === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Comment-out a shebang line that may sit at the top of a file,
|
||||
* making it executable on linux-like systems.
|
||||
* @param {String} code
|
||||
* @return code
|
||||
* @return {String} code
|
||||
*/
|
||||
function commentShebang(code) {
|
||||
return (code[ 0 ] === '#' && code[ 1 ] === '!') ? '//' + code : code;
|
||||
@ -58,7 +73,9 @@ module.exports = function (index) {
|
||||
node.leadingComments.filter(function (c) {
|
||||
return c.type === 'Block';
|
||||
}).map(function (comment) {
|
||||
docs.push(doctrine.parse(comment.value, { unwrap: true }));
|
||||
if (isJSDocComment(comment.value)) {
|
||||
docs.push(doctrine.parse(comment.value, { unwrap: true }));
|
||||
}
|
||||
});
|
||||
}
|
||||
this.traverse(path);
|
||||
|
||||
8
test/fixture/simple-singlestar.js
Normal file
8
test/fixture/simple-singlestar.js
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
* This function returns the number one.
|
||||
* @return {Number} numberone
|
||||
*/
|
||||
module.exports = function () {
|
||||
// this returns 1
|
||||
return 1;
|
||||
};
|
||||
8
test/fixture/simple-triplestar.js
Normal file
8
test/fixture/simple-triplestar.js
Normal file
@ -0,0 +1,8 @@
|
||||
/***
|
||||
* This function returns the number one.
|
||||
* @return {Number} numberone
|
||||
*/
|
||||
module.exports = function () {
|
||||
// this returns 1
|
||||
return 1;
|
||||
};
|
||||
14
test/test.js
14
test/test.js
@ -13,6 +13,20 @@ test('documentation', function (t) {
|
||||
}));
|
||||
});
|
||||
|
||||
test('documentation - single star', function (t) {
|
||||
documentation(path.join(__dirname, 'fixture/simple-singlestar.js')).pipe(concat(function (data) {
|
||||
t.equal(data.length, 0, 'simple has no dependencies');
|
||||
t.end();
|
||||
}));
|
||||
});
|
||||
|
||||
test('documentation - triple star', function (t) {
|
||||
documentation(path.join(__dirname, 'fixture/simple-triplestar.js')).pipe(concat(function (data) {
|
||||
t.equal(data.length, 0, 'simple has no dependencies');
|
||||
t.end();
|
||||
}));
|
||||
});
|
||||
|
||||
test('documentation - hashbang', function (t) {
|
||||
documentation(path.join(__dirname, 'fixture/simple-hashbang.js')).pipe(concat(function (data) {
|
||||
t.equal(data.length, 1, 'simple has no dependencies');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user