@@ -74,7 +74,7 @@ namespace ts.codefix {
7474 }
7575 else {
7676 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 ) ;
7878 }
7979 }
8080 }
@@ -211,8 +211,17 @@ namespace ts.codefix {
211211
212212 function getActionsForAddMissingMemberInTypeScriptFile ( context : CodeFixContext , declSourceFile : SourceFile , classDeclaration : ClassOrInterface , token : Identifier | PrivateIdentifier , makeStatic : boolean ) : CodeFixAction [ ] | undefined {
213213 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 ;
216225 }
217226
218227 function getTypeNode ( checker : TypeChecker , classDeclaration : ClassOrInterface , token : Node ) {
@@ -230,15 +239,18 @@ namespace ts.codefix {
230239 return typeNode || createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
231240 }
232241
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 ) ;
236248 }
237249
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 {
239251 const property = createProperty (
240252 /*decorators*/ undefined ,
241- /*modifiers*/ makeStatic ? [ createToken ( SyntaxKind . StaticKeyword ) ] : undefined ,
253+ /*modifiers*/ modifierFlags ? createNodeArray ( createModifiersFromModifierFlags ( modifierFlags ) ) : undefined ,
242254 tokenName ,
243255 /*questionToken*/ undefined ,
244256 typeNode ,
0 commit comments