@@ -240,7 +240,7 @@ function patchNodesInFile(file) {
240240
241241 var node = functionNodeTypes . indexOf ( this . type ) !== - 1 ?
242242 findFirstNodeInLine ( this ) : this ;
243- var res = findDocCommentBeforeNode ( node ) ;
243+ var res = findDocCommentBeforeNode ( node , this ) ;
244244
245245 this . _jsdoc = res ? jsdoc . createDocCommentByCommentNode ( res ) : null ;
246246
@@ -267,13 +267,25 @@ function patchNodesInFile(file) {
267267 * @param {?module:esprima/Node } node
268268 * @returns {?module:esprima/Node }
269269 */
270- function findDocCommentBeforeNode ( node ) {
270+ function findDocCommentBeforeNode ( node , self ) {
271271 var res = file . getPrevToken ( file . getFirstNodeToken ( node ) , { includeComments : true } ) ;
272- if ( res && res . type === 'Block' && res . value . charAt ( 0 ) === '*' &&
273- res . loc . start . column === node . loc . start . column ) {
274- return res ;
272+ if ( ! res || res . type !== 'Block' || res . value . charAt ( 0 ) !== '*' ) {
273+ return null ;
275274 }
276- return null ;
275+
276+ // Indent should be the same
277+ if ( res . loc . start . column !== node . loc . start . column ) {
278+ return null ;
279+ }
280+
281+ // IIFE should be on the next line to be sticked
282+ if ( ( self . type === 'FunctionExpression' || self . type === 'ArrowFunctionExpression' ) &&
283+ self . parentNode . type === 'CallExpression' &&
284+ ( self . loc . start . line > res . loc . end . line + 2 ) ) {
285+ return null ;
286+ }
287+
288+ return res ;
277289 }
278290
279291 // mark object as patched
0 commit comments