@@ -199,34 +199,13 @@ namespace ts.codefix {
199
199
preferences : UserPreferences ,
200
200
) : void {
201
201
const methodDeclaration = createMethodFromCallExpression ( callExpression , token . text , inJs , makeStatic , preferences ) ;
202
- const currentMethod = getNodeToInsertMethodAfter ( classDeclaration , callExpression ) ;
202
+ const containingMethodDeclaration = getAncestor ( callExpression , SyntaxKind . MethodDeclaration ) ;
203
203
204
- if ( currentMethod ) {
205
- changeTracker . insertNodeAfter ( classDeclarationSourceFile , currentMethod , methodDeclaration ) ;
204
+ if ( containingMethodDeclaration && containingMethodDeclaration . parent === classDeclaration ) {
205
+ changeTracker . insertNodeAfter ( classDeclarationSourceFile , containingMethodDeclaration , methodDeclaration ) ;
206
206
}
207
207
else {
208
208
changeTracker . insertNodeAtClassStart ( classDeclarationSourceFile , classDeclaration , methodDeclaration ) ;
209
209
}
210
210
}
211
-
212
- // Gets the MethodDeclaration of a method of the cls class that contains the node, or undefined if the node is not in a method or that method is not in the cls class.
213
- function getNodeToInsertMethodAfter ( cls : ClassLikeDeclaration , node : Node ) : MethodDeclaration | undefined {
214
- const nodeMethod = getParentMethodDeclaration ( node ) ;
215
- if ( nodeMethod ) {
216
- const isClsMethod = contains ( cls . members , nodeMethod ) ;
217
- if ( isClsMethod ) {
218
- return nodeMethod ;
219
- }
220
- }
221
- return undefined ;
222
- }
223
-
224
- // Gets the MethodDeclaration of the method that contains the node, or undefined if the node is not in a method.
225
- function getParentMethodDeclaration ( node : Node ) : MethodDeclaration | undefined {
226
- while ( node ) {
227
- if ( isMethodDeclaration ( node ) ) break ;
228
- node = node . parent ;
229
- }
230
- return node ;
231
- }
232
211
}
0 commit comments