@@ -10,7 +10,8 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
10
10
11
11
interface Info {
12
12
func : ArrowFunction ;
13
- expression : Expression ;
13
+ expression : Expression | undefined ;
14
+ returnStatement ?: ReturnStatement ;
14
15
addBraces : boolean ;
15
16
}
16
17
@@ -40,23 +41,23 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
40
41
const info = getConvertibleArrowFunctionAtPosition ( file , startPosition ) ;
41
42
if ( ! info ) return undefined ;
42
43
43
- const { expression, func } = info ;
44
+ const { expression, returnStatement , func } = info ;
44
45
45
46
let body : ConciseBody ;
46
47
if ( actionName === addBracesActionName ) {
47
48
const returnStatement = createReturn ( expression ) ;
48
49
body = createBlock ( [ returnStatement ] , /* multiLine */ true ) ;
49
50
suppressLeadingAndTrailingTrivia ( body ) ;
50
- copyComments ( expression , returnStatement , file , SyntaxKind . MultiLineCommentTrivia , true , true ) ;
51
+ copyComments ( expression ! , returnStatement , file , SyntaxKind . MultiLineCommentTrivia , /* explicitHtnl */ true ) ;
51
52
}
52
- else if ( actionName === removeBracesActionName ) {
53
- const returnStatement = < ReturnStatement > expression . parent ;
54
- body = needsParentheses ( expression ) ? createParen ( expression ) : expression ;
53
+ else if ( actionName === removeBracesActionName && returnStatement ) {
54
+ const actualExpression = expression || createVoidZero ( ) ;
55
+ body = needsParentheses ( actualExpression ) ? createParen ( actualExpression ) : actualExpression ;
55
56
suppressLeadingAndTrailingTrivia ( body ) ;
56
- copyComments ( returnStatement , body , file , SyntaxKind . MultiLineCommentTrivia , false ) ;
57
+ copyComments ( returnStatement , body , file , SyntaxKind . MultiLineCommentTrivia , /* explicitHtnl */ false ) ;
57
58
}
58
59
else {
59
- Debug . fail ( ' invalid action' ) ;
60
+ Debug . fail ( " invalid action" ) ;
60
61
}
61
62
62
63
const edits = textChanges . ChangeTracker . with ( context , t => updateBody ( t , file , func , body ) ) ;
@@ -89,7 +90,8 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
89
90
return {
90
91
func,
91
92
addBraces : false ,
92
- expression : firstStatement . expression
93
+ expression : firstStatement . expression ,
94
+ returnStatement : firstStatement
93
95
} ;
94
96
}
95
97
}
0 commit comments