@@ -402,7 +402,7 @@ namespace ts.codefix {
402
402
}
403
403
404
404
// should be kept up to date with isFixablePromiseArgument in suggestionDiagnostics.ts
405
- function getTransformationBody ( func : Node , prevArgName : SynthIdentifier | undefined , argName : SynthIdentifier , parent : CallExpression , transformer : Transformer ) : NodeArray < Statement > {
405
+ function getTransformationBody ( func : Expression , prevArgName : SynthIdentifier | undefined , argName : SynthIdentifier , parent : CallExpression , transformer : Transformer ) : NodeArray < Statement > {
406
406
407
407
const hasPrevArgName = prevArgName && prevArgName . identifier . text . length > 0 ;
408
408
const hasArgName = argName && argName . identifier . text . length > 0 ;
@@ -429,15 +429,15 @@ namespace ts.codefix {
429
429
prevArgName ! . types . push ( returnType ! ) ;
430
430
return varDeclOrAssignment ;
431
431
432
- case SyntaxKind . FunctionDeclaration :
433
432
case SyntaxKind . FunctionExpression :
434
- case SyntaxKind . ArrowFunction :
433
+ case SyntaxKind . ArrowFunction : {
434
+ const funcBody = ( func as FunctionExpression | ArrowFunction ) . body ;
435
435
// Arrow functions with block bodies { } will enter this control flow
436
- if ( isFunctionLikeDeclaration ( func ) && func . body && isBlock ( func . body ) && func . body . statements ) {
436
+ if ( isBlock ( funcBody ) ) {
437
437
let refactoredStmts : Statement [ ] = [ ] ;
438
438
let seenReturnStatement = false ;
439
439
440
- for ( const statement of func . body . statements ) {
440
+ for ( const statement of funcBody . statements ) {
441
441
if ( isReturnStatement ( statement ) ) {
442
442
seenReturnStatement = true ;
443
443
}
@@ -454,8 +454,7 @@ namespace ts.codefix {
454
454
removeReturns ( createNodeArray ( refactoredStmts ) , prevArgName ! . identifier , transformer . constIdentifiers , seenReturnStatement ) ;
455
455
}
456
456
else {
457
- const funcBody = ( < ArrowFunction > func ) . body ;
458
- const innerRetStmts = getReturnStatementsWithPromiseHandlers ( createReturn ( funcBody as Expression ) ) ;
457
+ const innerRetStmts = getReturnStatementsWithPromiseHandlers ( createReturn ( funcBody ) ) ;
459
458
const innerCbBody = getInnerTransformationBody ( transformer , innerRetStmts , prevArgName ) ;
460
459
461
460
if ( innerCbBody . length > 0 ) {
@@ -465,14 +464,15 @@ namespace ts.codefix {
465
464
if ( hasPrevArgName && ! shouldReturn ) {
466
465
const type = transformer . checker . getTypeAtLocation ( func ) ;
467
466
const returnType = getLastCallSignature ( type , transformer . checker ) ! . getReturnType ( ) ;
468
- const varDeclOrAssignment = createVariableDeclarationOrAssignment ( prevArgName ! , getSynthesizedDeepClone ( funcBody ) as Expression , transformer ) ;
467
+ const varDeclOrAssignment = createVariableDeclarationOrAssignment ( prevArgName ! , getSynthesizedDeepClone ( funcBody ) , transformer ) ;
469
468
prevArgName ! . types . push ( returnType ) ;
470
469
return varDeclOrAssignment ;
471
470
}
472
471
else {
473
- return createNodeArray ( [ createReturn ( getSynthesizedDeepClone ( funcBody ) as Expression ) ] ) ;
472
+ return createNodeArray ( [ createReturn ( getSynthesizedDeepClone ( funcBody ) ) ] ) ;
474
473
}
475
474
}
475
+ }
476
476
default :
477
477
// We've found a transformation body we don't know how to handle, so the refactoring should no-op to avoid deleting code.
478
478
codeActionSucceeded = false ;
0 commit comments