@@ -21,8 +21,8 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
21
21
}
22
22
23
23
function getAvailableActions ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
24
- const { file, startPosition } = context ;
25
- if ( ! getConvertibleFieldAtPosition ( file , startPosition ) ) return undefined ;
24
+ const { file } = context ;
25
+ if ( ! getConvertibleFieldAtPosition ( context , file ) ) return undefined ;
26
26
27
27
return [ {
28
28
name : actionName ,
@@ -37,9 +37,9 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
37
37
}
38
38
39
39
function getEditsForAction ( context : RefactorContext , _actionName : string ) : RefactorEditInfo | undefined {
40
- const { file, startPosition } = context ;
40
+ const { file } = context ;
41
41
42
- const fieldInfo = getConvertibleFieldAtPosition ( file , startPosition ) ;
42
+ const fieldInfo = getConvertibleFieldAtPosition ( context , file ) ;
43
43
if ( ! fieldInfo ) return undefined ;
44
44
45
45
const isJS = isSourceFileJavaScript ( file ) ;
@@ -117,17 +117,15 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
117
117
return name . charCodeAt ( 0 ) === CharacterCodes . _ ;
118
118
}
119
119
120
- function getConvertibleFieldAtPosition ( file : SourceFile , startPosition : number ) : Info | undefined {
120
+ function getConvertibleFieldAtPosition ( context : RefactorContext , file : SourceFile ) : Info | undefined {
121
+ const { startPosition, endPosition } = context ;
122
+
121
123
const node = getTokenAtPosition ( file , startPosition , /*includeJsDocComment*/ false ) ;
122
- const declaration = < AcceptedDeclaration > findAncestor ( node . parent , n => {
123
- if ( isFunctionLikeDeclaration ( n ) ) {
124
- return "quit" ;
125
- }
126
- return isAcceptedDeclaration ( n ) ;
127
- } ) ;
124
+ const declaration = findAncestor ( node . parent , isAcceptedDeclaration ) ;
128
125
// make sure declaration have AccessibilityModifier or Static Modifier or Readonly Modifier
129
126
const meaning = ModifierFlags . AccessibilityModifier | ModifierFlags . Static | ModifierFlags . Readonly ;
130
- if ( ! declaration || ! isConvertableName ( declaration . name ) || ( getModifierFlags ( declaration ) | meaning ) !== meaning ) return undefined ;
127
+ if ( ! declaration || ! rangeOverlapsWithStartEnd ( declaration . name , startPosition , endPosition )
128
+ || ! isConvertableName ( declaration . name ) || ( getModifierFlags ( declaration ) | meaning ) !== meaning ) return undefined ;
131
129
132
130
const name = declaration . name . text ;
133
131
const startWithUnderscore = startsWithUnderscore ( name ) ;
0 commit comments