@@ -48,34 +48,30 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
4848 const returnStatement = createReturn ( expression ) ;
4949 body = createBlock ( [ returnStatement ] , /* multiLine */ true ) ;
5050 suppressLeadingAndTrailingTrivia ( body ) ;
51- copyComments ( expression ! , returnStatement , file , SyntaxKind . MultiLineCommentTrivia , /* explicitHtnl */ true ) ;
51+ copyComments ( expression ! , returnStatement , file , SyntaxKind . MultiLineCommentTrivia , /* hasTrailingNewLine */ true ) ;
5252 }
5353 else if ( actionName === removeBracesActionName && returnStatement ) {
5454 const actualExpression = expression || createVoidZero ( ) ;
5555 body = needsParentheses ( actualExpression ) ? createParen ( actualExpression ) : actualExpression ;
5656 suppressLeadingAndTrailingTrivia ( body ) ;
57- copyComments ( returnStatement , body , file , SyntaxKind . MultiLineCommentTrivia , /* explicitHtnl */ false ) ;
57+ copyComments ( returnStatement , body , file , SyntaxKind . MultiLineCommentTrivia , /* hasTrailingNewLine */ false ) ;
5858 }
5959 else {
6060 Debug . fail ( "invalid action" ) ;
6161 }
6262
63- const edits = textChanges . ChangeTracker . with ( context , t => updateBody ( t , file , func , body ) ) ;
63+ const edits = textChanges . ChangeTracker . with ( context , t => t . replaceNode ( file , func . body , body ) ) ;
6464 return { renameFilename : undefined , renameLocation : undefined , edits } ;
6565 }
6666
6767 function needsParentheses ( expression : Expression ) {
6868 return isBinaryExpression ( expression ) && expression . operatorToken . kind === SyntaxKind . CommaToken || isObjectLiteralExpression ( expression ) ;
6969 }
7070
71- function updateBody ( changeTracker : textChanges . ChangeTracker , file : SourceFile , container : ArrowFunction , body : ConciseBody ) {
72- changeTracker . replaceNode ( file , container . body , body ) ;
73- }
74-
7571 function getConvertibleArrowFunctionAtPosition ( file : SourceFile , startPosition : number ) : Info | undefined {
7672 const node = getTokenAtPosition ( file , startPosition , /*includeJsDocComment*/ false ) ;
7773 const func = getContainingFunction ( node ) ;
78- if ( ! func || ! isArrowFunction ( func ) ) return undefined ;
74+ if ( ! func || ! isArrowFunction ( func ) || ( ! rangeContainsRange ( func , node ) || rangeContainsRange ( func . body , node ) ) ) return undefined ;
7975
8076 if ( isExpression ( func . body ) ) {
8177 return {
0 commit comments