@@ -240,7 +240,7 @@ function patchNodesInFile(file) {
240
240
241
241
var node = functionNodeTypes . indexOf ( this . type ) !== - 1 ?
242
242
findFirstNodeInLine ( this ) : this ;
243
- var res = findDocCommentBeforeNode ( node ) ;
243
+ var res = findDocCommentBeforeNode ( node , this ) ;
244
244
245
245
this . _jsdoc = res ? jsdoc . createDocCommentByCommentNode ( res ) : null ;
246
246
@@ -267,13 +267,25 @@ function patchNodesInFile(file) {
267
267
* @param {?module:esprima/Node } node
268
268
* @returns {?module:esprima/Node }
269
269
*/
270
- function findDocCommentBeforeNode ( node ) {
270
+ function findDocCommentBeforeNode ( node , self ) {
271
271
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 ;
275
274
}
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 ;
277
289
}
278
290
279
291
// mark object as patched
0 commit comments