@@ -16,7 +16,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
16
16
readonly declaration : AcceptedDeclaration ;
17
17
readonly fieldName : AcceptedNameType ;
18
18
readonly accessorName : AcceptedNameType ;
19
- readonly originalName : AcceptedNameType ;
19
+ readonly originalName : string ;
20
20
readonly renameAccessor : boolean ;
21
21
}
22
22
@@ -69,7 +69,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
69
69
// readonly modifier only existed in classLikeDeclaration
70
70
const constructor = getFirstConstructorWithBody ( < ClassLikeDeclaration > container ) ;
71
71
if ( constructor ) {
72
- updateReadonlyPropertyInitializerStatementConstructor ( changeTracker , context , constructor , fieldName , originalName ) ;
72
+ updateReadonlyPropertyInitializerStatementConstructor ( changeTracker , file , constructor , fieldName . text , originalName ) ;
73
73
}
74
74
}
75
75
else {
@@ -135,7 +135,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
135
135
isReadonly : hasReadonlyModifier ( declaration ) ,
136
136
type : getTypeAnnotationNode ( declaration ) ,
137
137
container : declaration . kind === SyntaxKind . Parameter ? declaration . parent . parent : declaration . parent ,
138
- originalName : < AcceptedNameType > declaration . name ,
138
+ originalName : ( < AcceptedNameType > declaration . name ) . text ,
139
139
declaration,
140
140
fieldName,
141
141
accessorName,
@@ -221,22 +221,22 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
221
221
: changeTracker . insertNodeAfter ( file , declaration , accessor ) ;
222
222
}
223
223
224
- function updateReadonlyPropertyInitializerStatementConstructor ( changeTracker : textChanges . ChangeTracker , context : RefactorContext , constructor : ConstructorDeclaration , fieldName : AcceptedNameType , originalName : AcceptedNameType ) {
224
+ function updateReadonlyPropertyInitializerStatementConstructor ( changeTracker : textChanges . ChangeTracker , file : SourceFile , constructor : ConstructorDeclaration , fieldName : string , originalName : string ) {
225
225
if ( ! constructor . body ) return ;
226
- const { file , program , cancellationToken } = context ;
227
-
228
- const referenceEntries = mapDefined ( FindAllReferences . getReferenceEntriesForNode ( originalName . parent . pos , originalName , program , [ file ] , cancellationToken ! ) , entry => // TODO: GH#18217
229
- ( entry . kind !== FindAllReferences . EntryKind . Span && rangeContainsRange ( constructor , entry . node ) && isIdentifier ( entry . node ) && isWriteAccess ( entry . node ) ) ? entry . node : undefined ) ;
230
-
231
- forEach ( referenceEntries , entry => {
232
- const parent = entry . parent ;
233
- const accessorName = createIdentifier ( fieldName . text ) ;
234
- const node = isBinaryExpression ( parent )
235
- ? updateBinary ( parent , accessorName , parent . right , parent . operatorToken )
236
- : isPropertyAccessExpression ( parent )
237
- ? updatePropertyAccess ( parent , parent . expression , accessorName )
238
- : Debug . fail ( "Unexpected write access token" ) ;
239
- changeTracker . replaceNode ( file , parent , node ) ;
226
+ constructor . body . forEachChild ( function recur ( node ) {
227
+ if ( isElementAccessExpression ( node ) &&
228
+ node . expression . kind === SyntaxKind . ThisKeyword &&
229
+ isStringLiteral ( node . argumentExpression ) &&
230
+ node . argumentExpression . text === originalName &&
231
+ isWriteAccess ( node ) ) {
232
+ changeTracker . replaceNode ( file , node . argumentExpression , createStringLiteral ( fieldName ) ) ;
233
+ }
234
+ if ( isPropertyAccessExpression ( node ) && node . expression . kind === SyntaxKind . ThisKeyword && node . name . text === originalName && isWriteAccess ( node ) ) {
235
+ changeTracker . replaceNode ( file , node . name , createIdentifier ( fieldName ) ) ;
236
+ }
237
+ if ( ! isFunctionLike ( node ) && ! isClassLike ( node ) ) {
238
+ node . forEachChild ( recur ) ;
239
+ }
240
240
} ) ;
241
241
}
242
242
}
0 commit comments