Skip to content

Decorate callbacks #818

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions __tests__/fixture/simple-callback.input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* This takes a number and a callback and calls the callback with the number
* plus 3.
*
* @param {Number} n - The number.
* @param {simpleCallback} cb - The callback.
*/
function takesSimpleCallback(n, cb) {
cb(null, n + 3);
}

/**
* This callback takes an error and a number.
*
* @callback simpleCallback
* @param {?Error} err - The error.
* @param {Number} n - The number.
*/
13 changes: 11 additions & 2 deletions src/default_theme/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ var fs = require('fs'),
LinkerStack = require('../').util.LinkerStack,
hljs = require('highlight.js');

function isFunction(section) {
return (
section.kind === 'function' ||
(section.kind === 'typedef' &&
section.type.type === 'NameExpression' &&
section.type.name === 'Function')
);
}

module.exports = function(
comments: Array<Comment>,
config: DocumentationConfig
Expand All @@ -34,7 +43,7 @@ module.exports = function(
var prefix = '';
if (section.kind === 'class') {
prefix = 'new ';
} else if (section.kind !== 'function') {
} else if (!isFunction(section)) {
return section.name;
}
return prefix + section.name + formatters.parameters(section, true);
Expand All @@ -44,7 +53,7 @@ module.exports = function(
var prefix = '';
if (section.kind === 'class') {
prefix = 'new ';
} else if (section.kind !== 'function') {
} else if (!isFunction(section)) {
return section.name;
}
if (section.returns.length) {
Expand Down