From 7f71a867971311667e8a5fd3d4a63143bb967c9c Mon Sep 17 00:00:00 2001 From: David Halls Date: Sun, 18 Jun 2017 22:14:28 +0100 Subject: [PATCH 1/5] Show callback signatures --- src/default_theme/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/default_theme/index.js b/src/default_theme/index.js index 48ef6682a..83a08c719 100644 --- a/src/default_theme/index.js +++ b/src/default_theme/index.js @@ -9,6 +9,15 @@ var fs = require('fs'), LinkerStack = require('../').util.LinkerStack, hljs = require('highlight.js'); +function is_function(section) { + return ( + section.kind === 'function' || + (section.kind === 'typedef' && + section.type.type == 'NameExpression' && + section.type.name == 'Function') + ); +} + module.exports = function( comments: Array, config: DocumentationConfig @@ -34,7 +43,7 @@ module.exports = function( var prefix = ''; if (section.kind === 'class') { prefix = 'new '; - } else if (section.kind !== 'function') { + } else if (!is_function(section)) { return section.name; } return prefix + section.name + formatters.parameters(section, true); @@ -44,7 +53,7 @@ module.exports = function( var prefix = ''; if (section.kind === 'class') { prefix = 'new '; - } else if (section.kind !== 'function') { + } else if (!is_function(section)) { return section.name; } if (section.returns.length) { From 6233e267ab138abe07f40ce672598d01b9d65de5 Mon Sep 17 00:00:00 2001 From: David Halls Date: Sun, 18 Jun 2017 22:17:16 +0100 Subject: [PATCH 2/5] Add output test for callback --- __tests__/fixture/simple-callback.input.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 __tests__/fixture/simple-callback.input.js diff --git a/__tests__/fixture/simple-callback.input.js b/__tests__/fixture/simple-callback.input.js new file mode 100644 index 000000000..f96275827 --- /dev/null +++ b/__tests__/fixture/simple-callback.input.js @@ -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. + */ From 882353b5743f4e8c18df22b9792063ff8827cfb1 Mon Sep 17 00:00:00 2001 From: David Halls Date: Sun, 18 Jun 2017 22:20:16 +0100 Subject: [PATCH 3/5] Reformat is_function From 7ff962f360d5b710ceaac31d386fa817d154adfa Mon Sep 17 00:00:00 2001 From: David Halls Date: Sun, 18 Jun 2017 22:23:59 +0100 Subject: [PATCH 4/5] Fix comparator --- src/default_theme/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/default_theme/index.js b/src/default_theme/index.js index 83a08c719..7cf546cf6 100644 --- a/src/default_theme/index.js +++ b/src/default_theme/index.js @@ -13,8 +13,8 @@ function is_function(section) { return ( section.kind === 'function' || (section.kind === 'typedef' && - section.type.type == 'NameExpression' && - section.type.name == 'Function') + section.type.type === 'NameExpression' && + section.type.name === 'Function') ); } From 299bad4f27d32815e9f633af143d13224895cf4f Mon Sep 17 00:00:00 2001 From: David Halls Date: Tue, 20 Jun 2017 21:46:50 +0100 Subject: [PATCH 5/5] Use camelCase #818 --- src/default_theme/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/default_theme/index.js b/src/default_theme/index.js index 7cf546cf6..1cae8fdf7 100644 --- a/src/default_theme/index.js +++ b/src/default_theme/index.js @@ -9,7 +9,7 @@ var fs = require('fs'), LinkerStack = require('../').util.LinkerStack, hljs = require('highlight.js'); -function is_function(section) { +function isFunction(section) { return ( section.kind === 'function' || (section.kind === 'typedef' && @@ -43,7 +43,7 @@ module.exports = function( var prefix = ''; if (section.kind === 'class') { prefix = 'new '; - } else if (!is_function(section)) { + } else if (!isFunction(section)) { return section.name; } return prefix + section.name + formatters.parameters(section, true); @@ -53,7 +53,7 @@ module.exports = function( var prefix = ''; if (section.kind === 'class') { prefix = 'new '; - } else if (!is_function(section)) { + } else if (!isFunction(section)) { return section.name; } if (section.returns.length) {