@@ -79,9 +79,8 @@ namespace ts.codefix {
7979 * In such cases, we assume the declaration to be a `PropertySignature`.
8080 */
8181 const kind = declaration ?. kind ?? SyntaxKind . PropertySignature ;
82- const name = getSynthesizedDeepClone ( getNameOfDeclaration ( declaration ) , /*includeTrivia*/ false ) as PropertyName ;
82+ const declarationName = getNameOfDeclaration ( declaration ) as PropertyName ;
8383 const visibilityModifier = createVisibilityModifier ( declaration ? getEffectiveModifierFlags ( declaration ) : ModifierFlags . None ) ;
84- const modifiers = visibilityModifier ? factory . createNodeArray ( [ visibilityModifier ] ) : undefined ;
8584 const type = checker . getWidenedType ( checker . getTypeOfSymbolAtLocation ( symbol , enclosingDeclaration ) ) ;
8685 const optional = ! ! ( symbol . flags & SymbolFlags . Optional ) ;
8786 const ambient = ! ! ( enclosingDeclaration . flags & NodeFlags . Ambient ) || isAmbient ;
@@ -100,8 +99,8 @@ namespace ts.codefix {
10099 }
101100 }
102101 addClassElement ( factory . createPropertyDeclaration (
103- modifiers ,
104- declaration ? name : symbol . getName ( ) ,
102+ createModifiers ( visibilityModifier ) ,
103+ declaration ? createName ( declarationName ) : symbol . getName ( ) ,
105104 optional && ( preserveOptional & PreserveOptionalFlags . Property ) ? factory . createToken ( SyntaxKind . QuestionToken ) : undefined ,
106105 typeNode ,
107106 /*initializer*/ undefined ) ) ;
@@ -124,21 +123,21 @@ namespace ts.codefix {
124123 for ( const accessor of orderedAccessors ) {
125124 if ( isGetAccessorDeclaration ( accessor ) ) {
126125 addClassElement ( factory . createGetAccessorDeclaration (
127- modifiers ,
128- name ,
126+ createModifiers ( visibilityModifier ) ,
127+ createName ( declarationName ) ,
129128 emptyArray ,
130- typeNode ,
131- ambient ? undefined : body || createStubbedMethodBody ( quotePreference ) ) ) ;
129+ createTypeNode ( typeNode ) ,
130+ createBody ( body , quotePreference , ambient ) ) ) ;
132131 }
133132 else {
134133 Debug . assertNode ( accessor , isSetAccessorDeclaration , "The counterpart to a getter should be a setter" ) ;
135134 const parameter = getSetAccessorValueParameter ( accessor ) ;
136135 const parameterName = parameter && isIdentifier ( parameter . name ) ? idText ( parameter . name ) : undefined ;
137136 addClassElement ( factory . createSetAccessorDeclaration (
138- modifiers ,
139- name ,
140- createDummyParameters ( 1 , [ parameterName ] , [ typeNode ] , 1 , /*inJs*/ false ) ,
141- ambient ? undefined : body || createStubbedMethodBody ( quotePreference ) ) ) ;
137+ createModifiers ( visibilityModifier ) ,
138+ createName ( declarationName ) ,
139+ createDummyParameters ( 1 , [ parameterName ] , [ createTypeNode ( typeNode ) ] , 1 , /*inJs*/ false ) ,
140+ createBody ( body , quotePreference , ambient ) ) ) ;
142141 }
143142 }
144143 break ;
@@ -161,23 +160,23 @@ namespace ts.codefix {
161160 if ( declarations . length === 1 ) {
162161 Debug . assert ( signatures . length === 1 , "One declaration implies one signature" ) ;
163162 const signature = signatures [ 0 ] ;
164- outputMethod ( quotePreference , signature , modifiers , name , ambient ? undefined : body || createStubbedMethodBody ( quotePreference ) ) ;
163+ outputMethod ( quotePreference , signature , createModifiers ( visibilityModifier ) , createName ( declarationName ) , createBody ( body , quotePreference , ambient ) ) ;
165164 break ;
166165 }
167166
168167 for ( const signature of signatures ) {
169168 // Ensure nodes are fresh so they can have different positions when going through formatting.
170- outputMethod ( quotePreference , signature , getSynthesizedDeepClones ( modifiers , /*includeTrivia*/ false ) , getSynthesizedDeepClone ( name , /*includeTrivia*/ false ) ) ;
169+ outputMethod ( quotePreference , signature , createModifiers ( visibilityModifier ) , createName ( declarationName ) ) ;
171170 }
172171
173172 if ( ! ambient ) {
174173 if ( declarations . length > signatures . length ) {
175174 const signature = checker . getSignatureFromDeclaration ( declarations [ declarations . length - 1 ] as SignatureDeclaration ) ! ;
176- outputMethod ( quotePreference , signature , modifiers , name , body || createStubbedMethodBody ( quotePreference ) ) ;
175+ outputMethod ( quotePreference , signature , createModifiers ( visibilityModifier ) , createName ( declarationName ) , createBody ( body , quotePreference ) ) ;
177176 }
178177 else {
179178 Debug . assert ( declarations . length === signatures . length , "Declarations and signatures should match count" ) ;
180- addClassElement ( createMethodImplementingSignatures ( checker , context , enclosingDeclaration , signatures , name , optional && ! ! ( preserveOptional & PreserveOptionalFlags . Method ) , modifiers , quotePreference , body ) ) ;
179+ addClassElement ( createMethodImplementingSignatures ( checker , context , enclosingDeclaration , signatures , createName ( declarationName ) , optional && ! ! ( preserveOptional & PreserveOptionalFlags . Method ) , createModifiers ( visibilityModifier ) , quotePreference , body ) ) ;
181180 }
182181 }
183182 break ;
@@ -187,6 +186,23 @@ namespace ts.codefix {
187186 const method = createSignatureDeclarationFromSignature ( SyntaxKind . MethodDeclaration , context , quotePreference , signature , body , name , modifiers , optional && ! ! ( preserveOptional & PreserveOptionalFlags . Method ) , enclosingDeclaration , importAdder ) as MethodDeclaration ;
188187 if ( method ) addClassElement ( method ) ;
189188 }
189+
190+ function createName ( node : PropertyName ) {
191+ return getSynthesizedDeepClone ( node , /*includeTrivia*/ false ) ;
192+ }
193+
194+ function createModifiers ( modifier : Modifier | undefined ) {
195+ return modifier ? factory . createNodeArray ( [ modifier ] ) : undefined ;
196+ }
197+
198+ function createBody ( block : Block | undefined , quotePreference : QuotePreference , ambient ?: boolean ) {
199+ return ambient ? undefined :
200+ getSynthesizedDeepClone ( block , /*includeTrivia*/ false ) || createStubbedMethodBody ( quotePreference ) ;
201+ }
202+
203+ function createTypeNode ( typeNode : TypeNode | undefined ) {
204+ return getSynthesizedDeepClone ( typeNode , /*includeTrivia*/ false ) ;
205+ }
190206 }
191207
192208 export function createSignatureDeclarationFromSignature (
0 commit comments