@@ -4,20 +4,20 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
4
4
const actionDescription = Diagnostics . Generate_get_and_set_accessors . message ;
5
5
registerRefactor ( actionName , { getEditsForAction, getAvailableActions } ) ;
6
6
7
- type AccepedDeclaration = ParameterDeclaration | PropertyDeclaration | PropertyAssignment ;
8
- type AccepedNameType = Identifier | StringLiteral ;
9
- type ContainerDeclation = ClassLikeDeclaration | ObjectLiteralExpression ;
7
+ type AcceptedDeclaration = ParameterDeclaration | PropertyDeclaration | PropertyAssignment ;
8
+ type AcceptedNameType = Identifier | StringLiteral ;
9
+ type ContainerDeclaration = ClassLikeDeclaration | ObjectLiteralExpression ;
10
10
11
11
interface DeclarationInfo {
12
- container : ContainerDeclation ;
12
+ container : ContainerDeclaration ;
13
13
isStatic : boolean ;
14
14
type : TypeNode | undefined ;
15
15
}
16
16
17
17
interface Info extends DeclarationInfo {
18
- declaration : AccepedDeclaration ;
19
- fieldName : AccepedNameType ;
20
- accessorName : AccepedNameType ;
18
+ declaration : AcceptedDeclaration ;
19
+ fieldName : AcceptedNameType ;
20
+ accessorName : AcceptedNameType ;
21
21
}
22
22
23
23
function getAvailableActions ( context : RefactorContext ) : ApplicableRefactorInfo [ ] | undefined {
@@ -65,20 +65,24 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
65
65
return { renameFilename, renameLocation, edits } ;
66
66
}
67
67
68
- function isConvertableName ( name : DeclarationName ) : name is AccepedNameType {
68
+ function isConvertableName ( name : DeclarationName ) : name is AcceptedNameType {
69
69
return isIdentifier ( name ) || isStringLiteral ( name ) ;
70
70
}
71
71
72
- function createPropertyName ( name : string , originalName : AccepedNameType ) {
72
+ function isAcceptedDeclaration ( node : Node ) : node is AcceptedDeclaration {
73
+ return isParameterPropertyDeclaration ( node ) || isPropertyDeclaration ( node ) || isPropertyAssignment ( node ) ;
74
+ }
75
+
76
+ function createPropertyName ( name : string , originalName : AcceptedNameType ) {
73
77
return isIdentifier ( originalName ) ? createIdentifier ( name ) : createLiteral ( name ) ;
74
78
}
75
79
76
- function createAccessorAccessExpression ( fieldName : AccepedNameType , isStatic : boolean , container : ContainerDeclation ) {
80
+ function createAccessorAccessExpression ( fieldName : AcceptedNameType , isStatic : boolean , container : ContainerDeclaration ) {
77
81
const leftHead = isStatic ? ( < ClassLikeDeclaration > container ) . name : createThis ( ) ;
78
82
return isIdentifier ( fieldName ) ? createPropertyAccess ( leftHead , fieldName ) : createElementAccess ( leftHead , createLiteral ( fieldName ) ) ;
79
83
}
80
84
81
- function getAccessorModifiers ( isJS : boolean , declaration : AccepedDeclaration , isStatic : boolean , isClassLike : boolean ) : NodeArray < Modifier > | undefined {
85
+ function getAccessorModifiers ( isJS : boolean , declaration : AcceptedDeclaration , isStatic : boolean , isClassLike : boolean ) : NodeArray < Modifier > | undefined {
82
86
if ( ! isClassLike ) return undefined ;
83
87
84
88
if ( ! declaration . modifiers || getModifierFlags ( declaration ) & ModifierFlags . Private ) {
@@ -129,7 +133,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
129
133
} ;
130
134
}
131
135
132
- function getDeclarationInfo ( declaration : AccepedDeclaration ) {
136
+ function getDeclarationInfo ( declaration : AcceptedDeclaration ) {
133
137
if ( isPropertyDeclaration ( declaration ) ) {
134
138
return getPropertyDeclarationInfo ( declaration ) ;
135
139
}
@@ -143,7 +147,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
143
147
144
148
function getConvertibleFieldAtPosition ( file : SourceFile , startPosition : number ) : Info | undefined {
145
149
const node = getTokenAtPosition ( file , startPosition , /*includeJsDocComment*/ false ) ;
146
- const declaration = < AccepedDeclaration > findAncestor ( node . parent , or ( isParameterPropertyDeclaration , isPropertyDeclaration , isPropertyAssignment ) ) ;
150
+ const declaration = findAncestor ( node . parent , isAcceptedDeclaration ) ;
147
151
// make sure propertyDeclaration have AccessibilityModifier or Static Modifier
148
152
const meaning = ModifierFlags . AccessibilityModifier | ModifierFlags . Static ;
149
153
if ( ! declaration || ! isConvertableName ( declaration . name ) || ( getModifierFlags ( declaration ) | meaning ) !== meaning ) return undefined ;
@@ -160,7 +164,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
160
164
} ;
161
165
}
162
166
163
- function generateGetAccessor ( fieldName : AccepedNameType , accessorName : AccepedNameType , type : TypeNode , modifiers : ModifiersArray | undefined , isStatic : boolean , container : ContainerDeclation ) {
167
+ function generateGetAccessor ( fieldName : AcceptedNameType , accessorName : AcceptedNameType , type : TypeNode , modifiers : ModifiersArray | undefined , isStatic : boolean , container : ContainerDeclaration ) {
164
168
return createGetAccessor (
165
169
/*decorators*/ undefined ,
166
170
modifiers ,
@@ -175,7 +179,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
175
179
) ;
176
180
}
177
181
178
- function generateSetAccessor ( fieldName : AccepedNameType , accessorName : AccepedNameType , type : TypeNode , modifiers : ModifiersArray | undefined , isStatic : boolean , container : ContainerDeclation ) {
182
+ function generateSetAccessor ( fieldName : AcceptedNameType , accessorName : AcceptedNameType , type : TypeNode , modifiers : ModifiersArray | undefined , isStatic : boolean , container : ContainerDeclaration ) {
179
183
return createSetAccessor (
180
184
/*decorators*/ undefined ,
181
185
modifiers ,
@@ -199,7 +203,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
199
203
) ;
200
204
}
201
205
202
- function updatePropertyDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : PropertyDeclaration , fieldName : AccepedNameType , modifiers : ModifiersArray | undefined ) {
206
+ function updatePropertyDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : PropertyDeclaration , fieldName : AcceptedNameType , modifiers : ModifiersArray | undefined ) {
203
207
const property = updateProperty (
204
208
declaration ,
205
209
declaration . decorators ,
@@ -213,7 +217,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
213
217
changeTracker . replaceNode ( file , declaration , property ) ;
214
218
}
215
219
216
- function updateParameterPropertyDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : ParameterDeclaration , fieldName : AccepedNameType , modifiers : ModifiersArray | undefined , classLikeContainer : ClassLikeDeclaration ) {
220
+ function updateParameterPropertyDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : ParameterDeclaration , fieldName : AcceptedNameType , modifiers : ModifiersArray | undefined , classLikeContainer : ClassLikeDeclaration ) {
217
221
const property = createProperty (
218
222
declaration . decorators ,
219
223
modifiers ,
@@ -227,12 +231,12 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
227
231
changeTracker . deleteNodeInList ( file , declaration ) ;
228
232
}
229
233
230
- function updatePropertyAssignmentDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : PropertyAssignment , fieldName : AccepedNameType ) {
234
+ function updatePropertyAssignmentDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : PropertyAssignment , fieldName : AcceptedNameType ) {
231
235
const assignment = updatePropertyAssignment ( declaration , fieldName , declaration . initializer ) ;
232
236
changeTracker . replacePropertyAssignment ( file , declaration , assignment ) ;
233
237
}
234
238
235
- function updateFieldDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : AccepedDeclaration , fieldName : AccepedNameType , modifiers : ModifiersArray | undefined , container : ContainerDeclation ) {
239
+ function updateFieldDeclaration ( changeTracker : textChanges . ChangeTracker , file : SourceFile , declaration : AcceptedDeclaration , fieldName : AcceptedNameType , modifiers : ModifiersArray | undefined , container : ContainerDeclaration ) {
236
240
if ( isPropertyDeclaration ( declaration ) ) {
237
241
updatePropertyDeclaration ( changeTracker , file , declaration , fieldName , modifiers ) ;
238
242
}
@@ -244,7 +248,7 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
244
248
}
245
249
}
246
250
247
- function insertAccessor ( changeTracker : textChanges . ChangeTracker , file : SourceFile , accessor : AccessorDeclaration , declaration : AccepedDeclaration , container : ContainerDeclation ) {
251
+ function insertAccessor ( changeTracker : textChanges . ChangeTracker , file : SourceFile , accessor : AccessorDeclaration , declaration : AcceptedDeclaration , container : ContainerDeclaration ) {
248
252
isParameterPropertyDeclaration ( declaration )
249
253
? changeTracker . insertNodeAtClassStart ( file , < ClassLikeDeclaration > container , accessor )
250
254
: changeTracker . insertNodeAfter ( file , declaration , accessor ) ;
0 commit comments