@@ -855,6 +855,7 @@ namespace ts.refactor.extractMethod {
855855 return { body : createBlock ( body . statements , /*multLine*/ true ) , returnValueProperty : undefined } ;
856856 }
857857 let returnValueProperty : string ;
858+ let ignoreReturns = false ;
858859 const statements = createNodeArray ( isBlock ( body ) ? body . statements . slice ( 0 ) : [ isStatement ( body ) ? body : createReturn ( < Expression > body ) ] ) ;
859860 // rewrite body if either there are writes that should be propagated back via return statements or there are substitutions
860861 if ( writes || substitutions . size ) {
@@ -877,7 +878,7 @@ namespace ts.refactor.extractMethod {
877878 }
878879
879880 function visitor ( node : Node ) : VisitResult < Node > {
880- if ( node . kind === SyntaxKind . ReturnStatement && writes ) {
881+ if ( ! ignoreReturns && node . kind === SyntaxKind . ReturnStatement && writes ) {
881882 const assignments : ObjectLiteralElementLike [ ] = getPropertyAssignmentsForWrites ( writes ) ;
882883 if ( ( < ReturnStatement > node ) . expression ) {
883884 if ( ! returnValueProperty ) {
@@ -893,8 +894,12 @@ namespace ts.refactor.extractMethod {
893894 }
894895 }
895896 else {
897+ const oldIgnoreReturns = ignoreReturns ;
898+ ignoreReturns = ignoreReturns || isFunctionLike ( node ) || isClassLike ( node ) ;
896899 const substitution = substitutions . get ( getNodeId ( node ) . toString ( ) ) ;
897- return substitution || visitEachChild ( node , visitor , nullTransformationContext ) ;
900+ const result = substitution || visitEachChild ( node , visitor , nullTransformationContext ) ;
901+ ignoreReturns = oldIgnoreReturns ;
902+ return result ;
898903 }
899904 }
900905 }
0 commit comments