@@ -74,7 +74,7 @@ namespace ts.codefix {
74
74
}
75
75
else {
76
76
const typeNode = getTypeNode ( program . getTypeChecker ( ) , parentDeclaration , token ) ;
77
- addPropertyDeclaration ( changes , declSourceFile , parentDeclaration , token . text , typeNode , makeStatic ) ;
77
+ addPropertyDeclaration ( changes , declSourceFile , parentDeclaration , token . text , typeNode , makeStatic ? ModifierFlags . Static : 0 ) ;
78
78
}
79
79
}
80
80
}
@@ -211,8 +211,17 @@ namespace ts.codefix {
211
211
212
212
function getActionsForAddMissingMemberInTypeScriptFile ( context : CodeFixContext , declSourceFile : SourceFile , classDeclaration : ClassOrInterface , token : Identifier | PrivateIdentifier , makeStatic : boolean ) : CodeFixAction [ ] | undefined {
213
213
const typeNode = getTypeNode ( context . program . getTypeChecker ( ) , classDeclaration , token ) ;
214
- const addProp = createAddPropertyDeclarationAction ( context , declSourceFile , classDeclaration , makeStatic , token . text , typeNode ) ;
215
- return makeStatic || isPrivateIdentifier ( token ) ? [ addProp ] : [ addProp , createAddIndexSignatureAction ( context , declSourceFile , classDeclaration , token . text , typeNode ) ] ;
214
+ const actions : CodeFixAction [ ] = [ createAddPropertyDeclarationAction ( context , declSourceFile , classDeclaration , token . text , typeNode , makeStatic ? ModifierFlags . Static : 0 ) ] ;
215
+ if ( makeStatic || isPrivateIdentifier ( token ) ) {
216
+ return actions ;
217
+ }
218
+
219
+ if ( startsWithUnderscore ( token . text ) ) {
220
+ actions . unshift ( createAddPropertyDeclarationAction ( context , declSourceFile , classDeclaration , token . text , typeNode , ModifierFlags . Private ) ) ;
221
+ }
222
+
223
+ actions . push ( createAddIndexSignatureAction ( context , declSourceFile , classDeclaration , token . text , typeNode ) ) ;
224
+ return actions ;
216
225
}
217
226
218
227
function getTypeNode ( checker : TypeChecker , classDeclaration : ClassOrInterface , token : Node ) {
@@ -230,15 +239,18 @@ namespace ts.codefix {
230
239
return typeNode || createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
231
240
}
232
241
233
- function createAddPropertyDeclarationAction ( context : CodeFixContext , declSourceFile : SourceFile , classDeclaration : ClassOrInterface , makeStatic : boolean , tokenName : string , typeNode : TypeNode ) : CodeFixAction {
234
- const changes = textChanges . ChangeTracker . with ( context , t => addPropertyDeclaration ( t , declSourceFile , classDeclaration , tokenName , typeNode , makeStatic ) ) ;
235
- return createCodeFixAction ( fixName , changes , [ makeStatic ? Diagnostics . Declare_static_property_0 : Diagnostics . Declare_property_0 , tokenName ] , fixId , Diagnostics . Add_all_missing_members ) ;
242
+ function createAddPropertyDeclarationAction ( context : CodeFixContext , declSourceFile : SourceFile , classDeclaration : ClassOrInterface , tokenName : string , typeNode : TypeNode , modifierFlags : ModifierFlags ) : CodeFixAction {
243
+ const changes = textChanges . ChangeTracker . with ( context , t => addPropertyDeclaration ( t , declSourceFile , classDeclaration , tokenName , typeNode , modifierFlags ) ) ;
244
+ if ( modifierFlags & ModifierFlags . Private ) {
245
+ return createCodeFixActionWithoutFixAll ( fixName , changes , [ Diagnostics . Declare_private_property_0 , tokenName ] ) ;
246
+ }
247
+ return createCodeFixAction ( fixName , changes , [ modifierFlags & ModifierFlags . Static ? Diagnostics . Declare_static_property_0 : Diagnostics . Declare_property_0 , tokenName ] , fixId , Diagnostics . Add_all_missing_members ) ;
236
248
}
237
249
238
- function addPropertyDeclaration ( changeTracker : textChanges . ChangeTracker , declSourceFile : SourceFile , classDeclaration : ClassOrInterface , tokenName : string , typeNode : TypeNode , makeStatic : boolean ) : void {
250
+ function addPropertyDeclaration ( changeTracker : textChanges . ChangeTracker , declSourceFile : SourceFile , classDeclaration : ClassOrInterface , tokenName : string , typeNode : TypeNode , modifierFlags : ModifierFlags ) : void {
239
251
const property = createProperty (
240
252
/*decorators*/ undefined ,
241
- /*modifiers*/ makeStatic ? [ createToken ( SyntaxKind . StaticKeyword ) ] : undefined ,
253
+ /*modifiers*/ modifierFlags ? createNodeArray ( createModifiersFromModifierFlags ( modifierFlags ) ) : undefined ,
242
254
tokenName ,
243
255
/*questionToken*/ undefined ,
244
256
typeNode ,
0 commit comments