@@ -82,15 +82,19 @@ namespace ts.codefix {
82
82
83
83
const className = classDeclaration . name . getText ( ) ;
84
84
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 } ) ;
85
95
const initializeStaticAction = {
86
96
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 ( )
94
98
} ;
95
99
96
100
( actions || ( actions = [ ] ) ) . push ( initializeStaticAction ) ;
@@ -102,15 +106,20 @@ namespace ts.codefix {
102
106
return actions ;
103
107
}
104
108
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
+
105
120
const initializeAction = {
106
121
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 ( )
114
123
} ;
115
124
116
125
( actions || ( actions = [ ] ) ) . push ( initializeAction ) ;
0 commit comments