@@ -402,7 +402,7 @@ namespace ts.codefix {
402402 }
403403
404404 // 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 > {
406406
407407 const hasPrevArgName = prevArgName && prevArgName . identifier . text . length > 0 ;
408408 const hasArgName = argName && argName . identifier . text . length > 0 ;
@@ -429,15 +429,15 @@ namespace ts.codefix {
429429 prevArgName ! . types . push ( returnType ! ) ;
430430 return varDeclOrAssignment ;
431431
432- case SyntaxKind . FunctionDeclaration :
433432 case SyntaxKind . FunctionExpression :
434- case SyntaxKind . ArrowFunction :
433+ case SyntaxKind . ArrowFunction : {
434+ const funcBody = ( func as FunctionExpression | ArrowFunction ) . body ;
435435 // 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 ) ) {
437437 let refactoredStmts : Statement [ ] = [ ] ;
438438 let seenReturnStatement = false ;
439439
440- for ( const statement of func . body . statements ) {
440+ for ( const statement of funcBody . statements ) {
441441 if ( isReturnStatement ( statement ) ) {
442442 seenReturnStatement = true ;
443443 }
@@ -454,8 +454,7 @@ namespace ts.codefix {
454454 removeReturns ( createNodeArray ( refactoredStmts ) , prevArgName ! . identifier , transformer . constIdentifiers , seenReturnStatement ) ;
455455 }
456456 else {
457- const funcBody = ( < ArrowFunction > func ) . body ;
458- const innerRetStmts = getReturnStatementsWithPromiseHandlers ( createReturn ( funcBody as Expression ) ) ;
457+ const innerRetStmts = getReturnStatementsWithPromiseHandlers ( createReturn ( funcBody ) ) ;
459458 const innerCbBody = getInnerTransformationBody ( transformer , innerRetStmts , prevArgName ) ;
460459
461460 if ( innerCbBody . length > 0 ) {
@@ -465,14 +464,15 @@ namespace ts.codefix {
465464 if ( hasPrevArgName && ! shouldReturn ) {
466465 const type = transformer . checker . getTypeAtLocation ( func ) ;
467466 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 ) ;
469468 prevArgName ! . types . push ( returnType ) ;
470469 return varDeclOrAssignment ;
471470 }
472471 else {
473- return createNodeArray ( [ createReturn ( getSynthesizedDeepClone ( funcBody ) as Expression ) ] ) ;
472+ return createNodeArray ( [ createReturn ( getSynthesizedDeepClone ( funcBody ) ) ] ) ;
474473 }
475474 }
475+ }
476476 default :
477477 // We've found a transformation body we don't know how to handle, so the refactoring should no-op to avoid deleting code.
478478 codeActionSucceeded = false ;
0 commit comments