@@ -14,7 +14,7 @@ namespace ts.refactor.extractMethod {
14
14
15
15
/** Compute the associated code actions */
16
16
function getAvailableActions ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
17
- const rangeToExtract = getRangeToExtract ( context . file , { start : context . startPosition , length : context . endPosition - context . startPosition } ) ;
17
+ const rangeToExtract = getRangeToExtract ( context . file , { start : context . startPosition , length : getRefactorContextLength ( context ) } ) ;
18
18
19
19
const targetRange : TargetRange = rangeToExtract . targetRange ;
20
20
if ( targetRange === undefined ) {
@@ -66,8 +66,7 @@ namespace ts.refactor.extractMethod {
66
66
}
67
67
68
68
function getEditsForAction ( context : RefactorContext , actionName : string ) : RefactorEditInfo | undefined {
69
- const length = context . endPosition === undefined ? 0 : context . endPosition - context . startPosition ;
70
- const rangeToExtract = getRangeToExtract ( context . file , { start : context . startPosition , length } ) ;
69
+ const rangeToExtract = getRangeToExtract ( context . file , { start : context . startPosition , length : getRefactorContextLength ( context ) } ) ;
71
70
const targetRange : TargetRange = rangeToExtract . targetRange ;
72
71
73
72
const parsedIndexMatch = / ^ s c o p e _ ( \d + ) $ / . exec ( actionName ) ;
@@ -148,7 +147,7 @@ namespace ts.refactor.extractMethod {
148
147
*/
149
148
// exported only for tests
150
149
export function getRangeToExtract ( sourceFile : SourceFile , span : TextSpan ) : RangeToExtract {
151
- const length = span . length || 0 ;
150
+ const { length } = span ;
152
151
153
152
if ( length === 0 ) {
154
153
return { errors : [ createFileDiagnostic ( sourceFile , span . start , length , Messages . StatementOrExpressionExpected ) ] } ;
0 commit comments