@@ -82,15 +82,19 @@ namespace ts.codefix {
8282
8383 const className = classDeclaration . name . getText ( ) ;
8484
85+ const staticInitialization = createStatement ( createAssignment (
86+ createPropertyAccess ( createIdentifier ( className ) , tokenName ) ,
87+ createIdentifier ( "undefined" ) ) ) ;
88+
89+ const staticInitializationChangeTracker = textChanges . ChangeTracker . fromCodeFixContext ( context ) ;
90+ staticInitializationChangeTracker . insertNodeAfter (
91+ classDeclarationSourceFile ,
92+ classDeclaration ,
93+ staticInitialization ,
94+ { suffix : context . newLineCharacter } ) ;
8595 const initializeStaticAction = {
8696 description : formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Initialize_static_property_0 ) , [ tokenName ] ) ,
87- changes : [ {
88- fileName : classDeclarationSourceFile . fileName ,
89- textChanges : [ {
90- span : { start : classDeclaration . getEnd ( ) , length : 0 } ,
91- newText : `${ context . newLineCharacter } ${ className } .${ tokenName } = undefined;${ context . newLineCharacter } `
92- } ]
93- } ]
97+ changes : staticInitializationChangeTracker . getChanges ( )
9498 } ;
9599
96100 ( actions || ( actions = [ ] ) ) . push ( initializeStaticAction ) ;
@@ -102,15 +106,20 @@ namespace ts.codefix {
102106 return actions ;
103107 }
104108
109+ const propertyInitialization = createStatement ( createAssignment (
110+ createPropertyAccess ( createThis ( ) , tokenName ) ,
111+ createIdentifier ( "undefined" ) ) ) ;
112+
113+ const propertyInitializationChangeTracker = textChanges . ChangeTracker . fromCodeFixContext ( context ) ;
114+ propertyInitializationChangeTracker . insertNodeAt (
115+ classDeclarationSourceFile ,
116+ classConstructor . body . getEnd ( ) - 1 ,
117+ propertyInitialization ,
118+ { prefix : context . newLineCharacter , suffix : context . newLineCharacter } ) ;
119+
105120 const initializeAction = {
106121 description : formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Initialize_property_0_in_the_constructor ) , [ tokenName ] ) ,
107- changes : [ {
108- fileName : classDeclarationSourceFile . fileName ,
109- textChanges : [ {
110- span : { start : classConstructor . body . getEnd ( ) - 1 , length : 0 } ,
111- newText : `this.${ tokenName } = undefined;${ context . newLineCharacter } `
112- } ]
113- } ]
122+ changes : propertyInitializationChangeTracker . getChanges ( )
114123 } ;
115124
116125 ( actions || ( actions = [ ] ) ) . push ( initializeAction ) ;
0 commit comments