From 33cd4c5fbb5201fabc125f0ba7c9dd63d8274f98 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Thu, 29 Jan 2015 14:43:40 -0800 Subject: [PATCH] minor cleanup --- lib/jsdoc/doclet.js | 14 ++++---------- lib/jsdoc/src/astnode.js | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/jsdoc/doclet.js b/lib/jsdoc/doclet.js index 2c08b300..28212895 100644 --- a/lib/jsdoc/doclet.js +++ b/lib/jsdoc/doclet.js @@ -41,21 +41,15 @@ function applyTag(doclet, tag) { // use the meta info about the source code to guess what the doclet kind should be function codeToKind(code) { - var parent; - var isFunction = jsdoc.src.astnode.isFunction; - - // default var kind = 'member'; + var node = code.node; - if (code.type === Syntax.FunctionDeclaration || code.type === Syntax.FunctionExpression) { + if ( isFunction(code.type) ) { kind = 'function'; } - else if (code.node && code.node.parent) { - parent = code.node.parent; - if ( isFunction(parent) ) { - kind = 'param'; - } + else if ( code.node && code.node.parent && isFunction(code.node.parent) ) { + kind = 'param'; } return kind; diff --git a/lib/jsdoc/src/astnode.js b/lib/jsdoc/src/astnode.js index 339d75a7..a8279921 100644 --- a/lib/jsdoc/src/astnode.js +++ b/lib/jsdoc/src/astnode.js @@ -12,11 +12,24 @@ var uid = 100000000; * Check whether an AST node represents a function. * * @alias module:jsdoc/src/astnode.isFunction - * @param {Object} node - The AST node to check. + * @param {(Object|string)} node - The AST node to check, or the `type` property of a node. * @return {boolean} Set to `true` if the node is a function or `false` in all other cases. */ var isFunction = exports.isFunction = function(node) { - return node.type === Syntax.FunctionDeclaration || node.type === Syntax.FunctionExpression; + var type; + + if (!node) { + return false; + } + + if (typeof node === 'string') { + type = node; + } + else { + type = node.type; + } + + return type === Syntax.FunctionDeclaration || type === Syntax.FunctionExpression; }; /**