@@ -13,6 +13,8 @@ namespace ts.codefix {
13
13
fixIds : [ fixId ] ,
14
14
getAllCodeActions : context => {
15
15
const seenNames = createMap < true > ( ) ;
16
+ const newLineCharacter = getNewLineOrDefaultFromHost ( context . host , context . formatContext . options ) ;
17
+
16
18
return codeFixAll ( context , errorCodes , ( changes , diag ) => {
17
19
const info = getInfo ( diag . file ! , diag . start ! ) ;
18
20
if ( ! info ) return undefined ;
@@ -22,7 +24,7 @@ namespace ts.codefix {
22
24
return ;
23
25
}
24
26
25
- addDefiniteAssignmentAssertion ( changes , diag . file , propertyDeclaration ) ;
27
+ addDefiniteAssignmentAssertion ( changes , diag . file , propertyDeclaration , newLineCharacter ) ;
26
28
} ) ;
27
29
} ,
28
30
} ) ;
@@ -43,13 +45,16 @@ namespace ts.codefix {
43
45
}
44
46
45
47
function getActionsForAddMissingDefiniteAssignmentAssertion ( context : CodeFixContext , token : Identifier , propertyDeclaration : PropertyDeclaration ) : CodeFixAction [ ] | undefined {
48
+ const newLineCharacter = getNewLineOrDefaultFromHost ( context . host , context . formatContext . options ) ;
46
49
const description = formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Declare_property_0 ) , [ token . text ] ) ;
47
- const changes = textChanges . ChangeTracker . with ( context , t => addDefiniteAssignmentAssertion ( t , context . sourceFile , propertyDeclaration ) ) ;
50
+ const changes = textChanges . ChangeTracker . with ( context , t => addDefiniteAssignmentAssertion ( t , context . sourceFile , propertyDeclaration , newLineCharacter ) ) ;
48
51
const action = { description, changes, fixId } ;
49
52
return [ action ] ;
50
53
}
51
54
52
- function addDefiniteAssignmentAssertion ( changeTracker : textChanges . ChangeTracker , propertyDeclarationSourceFile : SourceFile , propertyDeclaration : PropertyDeclaration ) : void {
53
- changeTracker . insertTokenAfter ( propertyDeclarationSourceFile , SyntaxKind . ExclamationToken , propertyDeclaration . name ) ;
55
+ function addDefiniteAssignmentAssertion ( changeTracker : textChanges . ChangeTracker , propertyDeclarationSourceFile : SourceFile , propertyDeclaration : PropertyDeclaration , newLineCharacter : string ) : void {
56
+ const property = clone ( propertyDeclaration ) ;
57
+ property . exclamationToken = createToken ( SyntaxKind . ExclamationToken ) ;
58
+ changeTracker . replaceNode ( propertyDeclarationSourceFile , propertyDeclaration , property , { suffix : newLineCharacter } ) ;
54
59
}
55
60
}
0 commit comments