@@ -251,7 +251,7 @@ namespace ts.JsDoc {
251251 * @param position The (character-indexed) position in the file where the check should
252252 * be performed.
253253 */
254- export function getDocCommentTemplateAtPosition ( newLine : string , sourceFile : SourceFile , position : number ) : TextInsertion | undefined {
254+ export function getDocCommentTemplateAtPosition ( newLine : string , sourceFile : SourceFile , position : number , options ?: DocCommentTemplateOptions ) : TextInsertion | undefined {
255255 const tokenAtPos = getTokenAtPosition ( sourceFile , position ) ;
256256 const existingDocComment = findAncestor ( tokenAtPos , isJSDoc ) ;
257257 if ( existingDocComment && ( existingDocComment . comment !== undefined || length ( existingDocComment . tags ) ) ) {
@@ -265,7 +265,7 @@ namespace ts.JsDoc {
265265 return undefined ;
266266 }
267267
268- const commentOwnerInfo = getCommentOwnerInfo ( tokenAtPos ) ;
268+ const commentOwnerInfo = getCommentOwnerInfo ( tokenAtPos , options ) ;
269269 if ( ! commentOwnerInfo ) {
270270 return undefined ;
271271 }
@@ -325,10 +325,10 @@ namespace ts.JsDoc {
325325 readonly parameters ?: readonly ParameterDeclaration [ ] ;
326326 readonly hasReturn ?: boolean ;
327327 }
328- function getCommentOwnerInfo ( tokenAtPos : Node ) : CommentOwnerInfo | undefined {
329- return forEachAncestor ( tokenAtPos , getCommentOwnerInfoWorker ) ;
328+ function getCommentOwnerInfo ( tokenAtPos : Node , options : DocCommentTemplateOptions | undefined ) : CommentOwnerInfo | undefined {
329+ return forEachAncestor ( tokenAtPos , n => getCommentOwnerInfoWorker ( n , options ) ) ;
330330 }
331- function getCommentOwnerInfoWorker ( commentOwner : Node ) : CommentOwnerInfo | undefined | "quit" {
331+ function getCommentOwnerInfoWorker ( commentOwner : Node , options : DocCommentTemplateOptions | undefined ) : CommentOwnerInfo | undefined | "quit" {
332332 switch ( commentOwner . kind ) {
333333 case SyntaxKind . FunctionDeclaration :
334334 case SyntaxKind . FunctionExpression :
@@ -337,10 +337,10 @@ namespace ts.JsDoc {
337337 case SyntaxKind . MethodSignature :
338338 case SyntaxKind . ArrowFunction :
339339 const host = commentOwner as ArrowFunction | FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | MethodSignature ;
340- return { commentOwner, parameters : host . parameters , hasReturn : hasReturn ( host ) } ;
340+ return { commentOwner, parameters : host . parameters , hasReturn : hasReturn ( host , options ) } ;
341341
342342 case SyntaxKind . PropertyAssignment :
343- return getCommentOwnerInfoWorker ( ( commentOwner as PropertyAssignment ) . initializer ) ;
343+ return getCommentOwnerInfoWorker ( ( commentOwner as PropertyAssignment ) . initializer , options ) ;
344344
345345 case SyntaxKind . ClassDeclaration :
346346 case SyntaxKind . InterfaceDeclaration :
@@ -357,7 +357,7 @@ namespace ts.JsDoc {
357357 ? getRightHandSideOfAssignment ( varDeclarations [ 0 ] . initializer )
358358 : undefined ;
359359 return host
360- ? { commentOwner, parameters : host . parameters , hasReturn : hasReturn ( host ) }
360+ ? { commentOwner, parameters : host . parameters , hasReturn : hasReturn ( host , options ) }
361361 : { commentOwner } ;
362362 }
363363
@@ -371,27 +371,28 @@ namespace ts.JsDoc {
371371 return commentOwner . parent . kind === SyntaxKind . ModuleDeclaration ? undefined : { commentOwner } ;
372372
373373 case SyntaxKind . ExpressionStatement :
374- return getCommentOwnerInfoWorker ( ( commentOwner as ExpressionStatement ) . expression ) ;
374+ return getCommentOwnerInfoWorker ( ( commentOwner as ExpressionStatement ) . expression , options ) ;
375375 case SyntaxKind . BinaryExpression : {
376376 const be = commentOwner as BinaryExpression ;
377377 if ( getAssignmentDeclarationKind ( be ) === AssignmentDeclarationKind . None ) {
378378 return "quit" ;
379379 }
380380 return isFunctionLike ( be . right )
381- ? { commentOwner, parameters : be . right . parameters , hasReturn : hasReturn ( be . right ) }
381+ ? { commentOwner, parameters : be . right . parameters , hasReturn : hasReturn ( be . right , options ) }
382382 : { commentOwner } ;
383383 }
384384 case SyntaxKind . PropertyDeclaration :
385385 const init = ( commentOwner as PropertyDeclaration ) . initializer ;
386386 if ( init && ( isFunctionExpression ( init ) || isArrowFunction ( init ) ) ) {
387- return { commentOwner, parameters : init . parameters , hasReturn : hasReturn ( init ) } ;
387+ return { commentOwner, parameters : init . parameters , hasReturn : hasReturn ( init , options ) } ;
388388 }
389389 }
390390 }
391391
392- function hasReturn ( node : Node ) {
393- return isArrowFunction ( node ) && isExpression ( node . body )
394- || isFunctionLikeDeclaration ( node ) && node . body && isBlock ( node . body ) && ! ! forEachReturnStatement ( node . body , n => n ) ;
392+ function hasReturn ( node : Node , options : DocCommentTemplateOptions | undefined ) {
393+ return ! ! options ?. generateReturnInDocTemplate &&
394+ ( isArrowFunction ( node ) && isExpression ( node . body )
395+ || isFunctionLikeDeclaration ( node ) && node . body && isBlock ( node . body ) && ! ! forEachReturnStatement ( node . body , n => n ) ) ;
395396 }
396397
397398 function getRightHandSideOfAssignment ( rightHandSide : Expression ) : FunctionExpression | ArrowFunction | ConstructorDeclaration | undefined {
0 commit comments