@@ -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
@@ -78,24 +80,9 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
78
80
return isIdentifier ( fieldName ) ? createPropertyAccess ( leftHead , fieldName ) : createElementAccess ( leftHead , createLiteral ( fieldName ) ) ;
79
81
}
80
82
81
- function getAccessorModifiers ( isJS : boolean , declaration : AccepedDeclaration , isStatic : boolean , isClassLike : boolean ) : NodeArray < Modifier > | undefined {
82
- if ( ! isClassLike ) return undefined ;
83
-
84
- if ( ! declaration . modifiers || getModifierFlags ( declaration ) & ModifierFlags . Private ) {
85
- const modifiers = append < Modifier > (
86
- ! isJS ? [ createToken ( SyntaxKind . PublicKeyword ) ] : undefined ,
87
- isStatic ? createToken ( SyntaxKind . StaticKeyword ) : undefined
88
- ) ;
89
- return modifiers && createNodeArray ( modifiers ) ;
90
- }
91
- return declaration . modifiers ;
92
- }
93
-
94
- function getFieldModifiers ( isJS : boolean , isStatic : boolean , isClassLike : boolean ) : NodeArray < Modifier > | undefined {
95
- if ( ! isClassLike ) return undefined ;
96
-
83
+ function getModifiers ( isJS : boolean , isStatic : boolean , accessModifier : SyntaxKind . PublicKeyword | SyntaxKind . PrivateKeyword ) : NodeArray < Modifier > {
97
84
const modifiers = append < Modifier > (
98
- ! isJS ? [ createToken ( SyntaxKind . PrivateKeyword ) ] : undefined ,
85
+ ! isJS ? [ createToken ( accessModifier ) as Token < SyntaxKind . PublicKeyword > | Token < SyntaxKind . PrivateKeyword > ] : undefined ,
99
86
isStatic ? createToken ( SyntaxKind . StaticKeyword ) : undefined
100
87
) ;
101
88
return modifiers && createNodeArray ( modifiers ) ;
0 commit comments