@@ -21,8 +21,8 @@ namespace ts.codefix {
21
21
getAllCodeActions : context => {
22
22
const seenNames = createMap < true > ( ) ;
23
23
return codeFixAll ( context , errorCodes , ( changes , diag ) => {
24
- const { newLineCharacter , program } = context ;
25
- const info = getInfo ( diag . file ! , diag . start ! , context . program . getTypeChecker ( ) ) ;
24
+ const { program } = context ;
25
+ const info = getInfo ( diag . file ! , diag . start ! , program . getTypeChecker ( ) ) ;
26
26
if ( ! info ) return ;
27
27
const { classDeclaration, classDeclarationSourceFile, inJs, makeStatic, token, call } = info ;
28
28
if ( ! addToSeen ( seenNames , token . text ) ) {
@@ -31,15 +31,15 @@ namespace ts.codefix {
31
31
32
32
// Always prefer to add a method declaration if possible.
33
33
if ( call ) {
34
- addMethodDeclaration ( changes , classDeclarationSourceFile , classDeclaration , token , call , newLineCharacter , makeStatic , inJs ) ;
34
+ addMethodDeclaration ( changes , classDeclarationSourceFile , classDeclaration , token , call , makeStatic , inJs ) ;
35
35
}
36
36
else {
37
37
if ( inJs ) {
38
- addMissingMemberInJs ( changes , classDeclarationSourceFile , classDeclaration , token . text , makeStatic , newLineCharacter ) ;
38
+ addMissingMemberInJs ( changes , classDeclarationSourceFile , classDeclaration , token . text , makeStatic ) ;
39
39
}
40
40
else {
41
41
const typeNode = getTypeNode ( program . getTypeChecker ( ) , classDeclaration , token ) ;
42
- addPropertyDeclaration ( changes , classDeclarationSourceFile , classDeclaration , token . text , typeNode , makeStatic , newLineCharacter ) ;
42
+ addPropertyDeclaration ( changes , classDeclarationSourceFile , classDeclaration , token . text , typeNode , makeStatic ) ;
43
43
}
44
44
}
45
45
} ) ;
@@ -96,13 +96,14 @@ namespace ts.codefix {
96
96
}
97
97
98
98
function getActionsForAddMissingMemberInJavaScriptFile ( context : CodeFixContext , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , tokenName : string , makeStatic : boolean ) : CodeFixAction | undefined {
99
- const changes = textChanges . ChangeTracker . with ( context , t => addMissingMemberInJs ( t , classDeclarationSourceFile , classDeclaration , tokenName , makeStatic , context . newLineCharacter ) ) ;
99
+ const changes = textChanges . ChangeTracker . with ( context , t => addMissingMemberInJs ( t , classDeclarationSourceFile , classDeclaration , tokenName , makeStatic ) ) ;
100
100
if ( changes . length === 0 ) return undefined ;
101
101
const description = formatStringFromArgs ( getLocaleSpecificMessage ( makeStatic ? Diagnostics . Initialize_static_property_0 : Diagnostics . Initialize_property_0_in_the_constructor ) , [ tokenName ] ) ;
102
102
return { description, changes, fixId } ;
103
103
}
104
104
105
- function addMissingMemberInJs ( changeTracker : textChanges . ChangeTracker , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , tokenName : string , makeStatic : boolean , newLineCharacter : string ) : void {
105
+ function addMissingMemberInJs ( changeTracker : textChanges . ChangeTracker , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , tokenName : string , makeStatic : boolean ) : void {
106
+ const { newLineCharacter } = changeTracker ;
106
107
if ( makeStatic ) {
107
108
if ( classDeclaration . kind === SyntaxKind . ClassExpression ) {
108
109
return ;
@@ -142,24 +143,24 @@ namespace ts.codefix {
142
143
return typeNode || createKeywordTypeNode ( SyntaxKind . AnyKeyword ) ;
143
144
}
144
145
145
- function createAddPropertyDeclarationAction ( context : CodeFixContext , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , makeStatic : boolean , tokenName : string , typeNode : TypeNode ) : CodeFixAction {
146
+ function createAddPropertyDeclarationAction ( context : textChanges . TextChangesContext , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , makeStatic : boolean , tokenName : string , typeNode : TypeNode ) : CodeFixAction {
146
147
const description = formatStringFromArgs ( getLocaleSpecificMessage ( makeStatic ? Diagnostics . Declare_static_property_0 : Diagnostics . Declare_property_0 ) , [ tokenName ] ) ;
147
- const changes = textChanges . ChangeTracker . with ( context , t => addPropertyDeclaration ( t , classDeclarationSourceFile , classDeclaration , tokenName , typeNode , makeStatic , context . newLineCharacter ) ) ;
148
+ const changes = textChanges . ChangeTracker . with ( context , t => addPropertyDeclaration ( t , classDeclarationSourceFile , classDeclaration , tokenName , typeNode , makeStatic ) ) ;
148
149
return { description, changes, fixId } ;
149
150
}
150
151
151
- function addPropertyDeclaration ( changeTracker : textChanges . ChangeTracker , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , tokenName : string , typeNode : TypeNode , makeStatic : boolean , newLineCharacter : string ) : void {
152
+ function addPropertyDeclaration ( changeTracker : textChanges . ChangeTracker , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , tokenName : string , typeNode : TypeNode , makeStatic : boolean ) : void {
152
153
const property = createProperty (
153
154
/*decorators*/ undefined ,
154
155
/*modifiers*/ makeStatic ? [ createToken ( SyntaxKind . StaticKeyword ) ] : undefined ,
155
156
tokenName ,
156
157
/*questionToken*/ undefined ,
157
158
typeNode ,
158
159
/*initializer*/ undefined ) ;
159
- changeTracker . insertNodeAtClassStart ( classDeclarationSourceFile , classDeclaration , property , newLineCharacter ) ;
160
+ changeTracker . insertNodeAtClassStart ( classDeclarationSourceFile , classDeclaration , property ) ;
160
161
}
161
162
162
- function createAddIndexSignatureAction ( context : CodeFixContext , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , tokenName : string , typeNode : TypeNode ) : CodeFixAction {
163
+ function createAddIndexSignatureAction ( context : textChanges . TextChangesContext , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , tokenName : string , typeNode : TypeNode ) : CodeFixAction {
163
164
// Index signatures cannot have the static modifier.
164
165
const stringTypeNode = createKeywordTypeNode ( SyntaxKind . StringKeyword ) ;
165
166
const indexingParameter = createParameter (
@@ -176,19 +177,19 @@ namespace ts.codefix {
176
177
[ indexingParameter ] ,
177
178
typeNode ) ;
178
179
179
- const changes = textChanges . ChangeTracker . with ( context , t => t . insertNodeAtClassStart ( classDeclarationSourceFile , classDeclaration , indexSignature , context . newLineCharacter ) ) ;
180
+ const changes = textChanges . ChangeTracker . with ( context , t => t . insertNodeAtClassStart ( classDeclarationSourceFile , classDeclaration , indexSignature ) ) ;
180
181
// No fixId here because code-fix-all currently only works on adding individual named properties.
181
182
return { description : formatStringFromArgs ( getLocaleSpecificMessage ( Diagnostics . Add_index_signature_for_property_0 ) , [ tokenName ] ) , changes, fixId : undefined } ;
182
183
}
183
184
184
- function getActionForMethodDeclaration ( context : CodeFixContext , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , token : Identifier , callExpression : CallExpression , makeStatic : boolean , inJs : boolean ) : CodeFixAction | undefined {
185
+ function getActionForMethodDeclaration ( context : textChanges . TextChangesContext , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , token : Identifier , callExpression : CallExpression , makeStatic : boolean , inJs : boolean ) : CodeFixAction | undefined {
185
186
const description = formatStringFromArgs ( getLocaleSpecificMessage ( makeStatic ? Diagnostics . Declare_static_method_0 : Diagnostics . Declare_method_0 ) , [ token . text ] ) ;
186
- const changes = textChanges . ChangeTracker . with ( context , t => addMethodDeclaration ( t , classDeclarationSourceFile , classDeclaration , token , callExpression , context . newLineCharacter , makeStatic , inJs ) ) ;
187
+ const changes = textChanges . ChangeTracker . with ( context , t => addMethodDeclaration ( t , classDeclarationSourceFile , classDeclaration , token , callExpression , makeStatic , inJs ) ) ;
187
188
return { description, changes, fixId } ;
188
189
}
189
190
190
- function addMethodDeclaration ( changeTracker : textChanges . ChangeTracker , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , token : Identifier , callExpression : CallExpression , newLineCharacter : string , makeStatic : boolean , inJs : boolean ) {
191
+ function addMethodDeclaration ( changeTracker : textChanges . ChangeTracker , classDeclarationSourceFile : SourceFile , classDeclaration : ClassLikeDeclaration , token : Identifier , callExpression : CallExpression , makeStatic : boolean , inJs : boolean ) {
191
192
const methodDeclaration = createMethodFromCallExpression ( callExpression , token . text , inJs , makeStatic ) ;
192
- changeTracker . insertNodeAtClassStart ( classDeclarationSourceFile , classDeclaration , methodDeclaration , newLineCharacter ) ;
193
+ changeTracker . insertNodeAtClassStart ( classDeclarationSourceFile , classDeclaration , methodDeclaration ) ;
193
194
}
194
195
}
0 commit comments