@@ -4,6 +4,17 @@ var jsdoc = require('../jsdoc');
44var esprimaHelpers = require ( '../esprima-helpers' ) ;
55var validators = require ( './validate-jsdoc/index' ) ;
66
7+ /** @type {string[] } - list of function node types */
8+ var functionNodeTypes = [
9+ 'FunctionDeclaration' ,
10+ 'FunctionExpression' ,
11+ 'ArrowFunctionExpression' ,
12+ ] ;
13+
14+ /** @type {string[] } - list of node types with jsdocs */
15+ var jsdocableTypes = [ ]
16+ . concat ( functionNodeTypes ) ;
17+
718/**
819 * Rule constructor
920 *
@@ -81,10 +92,7 @@ module.exports.prototype = {
8192
8293 var _this = this ;
8394 var scopes = {
84- 'function' : [
85- 'FunctionDeclaration' ,
86- 'FunctionExpression'
87- ]
95+ 'function' : functionNodeTypes ,
8896 } ;
8997
9098 // classic checker
@@ -213,9 +221,7 @@ function patchNodesInFile(file) {
213221 }
214222
215223 // jsdoc property for nodes
216- file . iterateNodesByType ( [
217- 'FunctionDeclaration' , 'FunctionExpression'
218- ] , function ( node ) {
224+ file . iterateNodesByType ( jsdocableTypes , function ( node ) {
219225 Object . defineProperty ( node , 'jsdoc' , {
220226 get : getJsdoc
221227 } ) ;
@@ -228,12 +234,16 @@ function patchNodesInFile(file) {
228234 * @returns {DocComment }
229235 */
230236 function getJsdoc ( ) {
231- if ( ! this . hasOwnProperty ( '_jsdoc' ) ) {
232- var node = this . type === 'FunctionExpression' || this . type === 'FunctionDeclaration' ?
233- findFirstNodeInLine ( this ) : this ;
234- var res = findDocCommentBeforeNode ( node ) ;
235- this . _jsdoc = res ? jsdoc . createDocCommentByCommentNode ( res ) : null ;
237+ if ( this . hasOwnProperty ( '_jsdoc' ) ) {
238+ return this . _jsdoc ;
236239 }
240+
241+ var node = functionNodeTypes . indexOf ( this . type ) !== - 1 ?
242+ findFirstNodeInLine ( this ) : this ;
243+ var res = findDocCommentBeforeNode ( node ) ;
244+
245+ this . _jsdoc = res ? jsdoc . createDocCommentByCommentNode ( res ) : null ;
246+
237247 return this . _jsdoc ;
238248 }
239249
0 commit comments