@@ -47,8 +47,10 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
47
47
const { isStatic, fieldName, accessorName, type, container, declaration } = fieldInfo ;
48
48
49
49
const isInClassLike = isClassLike ( container ) ;
50
- const accessorModifiers = getAccessorModifiers ( isJS , declaration , isStatic , isInClassLike ) ;
51
- const fieldModifiers = getFieldModifiers ( isJS , isStatic , isInClassLike ) ;
50
+ const accessorModifiers = isInClassLike
51
+ ? ! declaration . modifiers || getModifierFlags ( declaration ) & ModifierFlags . Private ? getModifiers ( isJS , isStatic , SyntaxKind . PublicKeyword ) : declaration . modifiers
52
+ : undefined ;
53
+ const fieldModifiers = isInClassLike ? getModifiers ( isJS , isStatic , SyntaxKind . PrivateKeyword ) : undefined ;
52
54
53
55
updateFieldDeclaration ( changeTracker , file , declaration , fieldName , fieldModifiers , container ) ;
54
56
@@ -82,24 +84,9 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
82
84
return isIdentifier ( fieldName ) ? createPropertyAccess ( leftHead , fieldName ) : createElementAccess ( leftHead , createLiteral ( fieldName ) ) ;
83
85
}
84
86
85
- function getAccessorModifiers ( isJS : boolean , declaration : AcceptedDeclaration , isStatic : boolean , isClassLike : boolean ) : NodeArray < Modifier > | undefined {
86
- if ( ! isClassLike ) return undefined ;
87
-
88
- if ( ! declaration . modifiers || getModifierFlags ( declaration ) & ModifierFlags . Private ) {
89
- const modifiers = append < Modifier > (
90
- ! isJS ? [ createToken ( SyntaxKind . PublicKeyword ) ] : undefined ,
91
- isStatic ? createToken ( SyntaxKind . StaticKeyword ) : undefined
92
- ) ;
93
- return modifiers && createNodeArray ( modifiers ) ;
94
- }
95
- return declaration . modifiers ;
96
- }
97
-
98
- function getFieldModifiers ( isJS : boolean , isStatic : boolean , isClassLike : boolean ) : NodeArray < Modifier > | undefined {
99
- if ( ! isClassLike ) return undefined ;
100
-
87
+ function getModifiers ( isJS : boolean , isStatic : boolean , accessModifier : SyntaxKind . PublicKeyword | SyntaxKind . PrivateKeyword ) : NodeArray < Modifier > {
101
88
const modifiers = append < Modifier > (
102
- ! isJS ? [ createToken ( SyntaxKind . PrivateKeyword ) ] : undefined ,
89
+ ! isJS ? [ createToken ( accessModifier ) as Token < SyntaxKind . PublicKeyword > | Token < SyntaxKind . PrivateKeyword > ] : undefined ,
103
90
isStatic ? createToken ( SyntaxKind . StaticKeyword ) : undefined
104
91
) ;
105
92
return modifiers && createNodeArray ( modifiers ) ;
0 commit comments