@@ -49,7 +49,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
49
49
: undefined ;
50
50
const fieldModifiers = isInClassLike ? getModifiers ( isJS , isStatic , SyntaxKind . PrivateKeyword ) : undefined ;
51
51
52
- updateFieldDeclaration ( changeTracker , file , declaration , fieldName , fieldModifiers , container ) ;
52
+ updateFieldDeclaration ( changeTracker , file , declaration , fieldName , fieldModifiers ) ;
53
53
54
54
const getAccessor = generateGetAccessor ( fieldName , accessorName , type , accessorModifiers , isStatic , container ) ;
55
55
const setAccessor = generateSetAccessor ( fieldName , accessorName , type , accessorModifiers , isStatic , container ) ;
@@ -60,7 +60,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
60
60
const edits = changeTracker . getChanges ( ) ;
61
61
const renameFilename = file . fileName ;
62
62
const renameLocationOffset = isIdentifier ( fieldName ) ? 0 : - 1 ;
63
- const renameLocation = renameLocationOffset + getRenameLocation ( edits , renameFilename , fieldName . text , /*isDeclaredBeforeUse */ false ) ;
63
+ const renameLocation = renameLocationOffset + getRenameLocation ( edits , renameFilename , fieldName . text , /*preferLastLocation */ isParameter ( declaration ) ) ;
64
64
return { renameFilename, renameLocation, edits } ;
65
65
}
66
66
@@ -163,34 +163,21 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
163
163
changeTracker . replaceNode ( file , declaration , property ) ;
164
164
}
165
165
166
- function updateParameterPropertyDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : ParameterDeclaration , fieldName : AcceptedNameType , modifiers : ModifiersArray | undefined , classLikeContainer : ClassLikeDeclaration ) {
167
- const property = createProperty (
168
- declaration . decorators ,
169
- modifiers ,
170
- fieldName ,
171
- declaration . questionToken ,
172
- declaration . type ,
173
- declaration . initializer
174
- ) ;
175
-
176
- changeTracker . insertNodeAtClassStart ( file , classLikeContainer , property ) ;
177
- changeTracker . deleteNodeInList ( file , declaration ) ;
178
- }
179
-
180
- function updatePropertyAssignmentDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : PropertyAssignment , fieldName : AcceptedNameType ) {
166
+ function updatePropertyAssignmentDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : PropertyAssignment , fieldName : AcceptedNameType ) {
181
167
const assignment = updatePropertyAssignment ( declaration , fieldName , declaration . initializer ) ;
182
168
changeTracker . replacePropertyAssignment ( file , declaration , assignment ) ;
183
169
}
184
170
185
- function updateFieldDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : AcceptedDeclaration , fieldName : AcceptedNameType , modifiers : ModifiersArray | undefined , container : ContainerDeclaration ) {
171
+ function updateFieldDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : AcceptedDeclaration , fieldName : AcceptedNameType , modifiers : ModifiersArray | undefined ) {
186
172
if ( isPropertyDeclaration ( declaration ) ) {
187
173
updatePropertyDeclaration ( changeTracker , file , declaration , fieldName , modifiers ) ;
188
174
}
189
175
else if ( isPropertyAssignment ( declaration ) ) {
190
176
updatePropertyAssignmentDeclaration ( changeTracker , file , declaration , fieldName ) ;
191
177
}
192
178
else {
193
- updateParameterPropertyDeclaration ( changeTracker , file , declaration , fieldName , modifiers , < ClassLikeDeclaration > container ) ;
179
+ changeTracker . replaceNode ( file , declaration ,
180
+ updateParameter ( declaration , declaration . decorators , modifiers , declaration . dotDotDotToken , cast ( fieldName , isIdentifier ) , declaration . questionToken , declaration . type , declaration . initializer ) ) ;
194
181
}
195
182
}
196
183
0 commit comments