@@ -19,7 +19,7 @@ namespace ts.codefix {
19
19
errorCodes,
20
20
getCodeActions ( context ) {
21
21
const typeChecker = context . program . getTypeChecker ( ) ;
22
- const info = getInfo ( context . sourceFile , context . span . start , context . errorCode , typeChecker , context . program , context . formatContext ) ;
22
+ const info = getInfo ( context . sourceFile , context . span . start , context . errorCode , typeChecker , context . program ) ;
23
23
if ( ! info ) {
24
24
return undefined ;
25
25
}
@@ -50,7 +50,7 @@ namespace ts.codefix {
50
50
51
51
return createCombinedCodeActions ( textChanges . ChangeTracker . with ( context , changes => {
52
52
eachDiagnostic ( context , errorCodes , diag => {
53
- const info = getInfo ( diag . file , diag . start , diag . code , checker , context . program , context . formatContext ) ;
53
+ const info = getInfo ( diag . file , diag . start , diag . code , checker , context . program ) ;
54
54
if ( ! info || ! addToSeen ( seen , getNodeId ( info . parentDeclaration ) + "#" + info . token . text ) ) {
55
55
return ;
56
56
}
@@ -141,7 +141,6 @@ namespace ts.codefix {
141
141
readonly properties : Symbol [ ] ;
142
142
readonly parentDeclaration : ObjectLiteralExpression ;
143
143
readonly indentation ?: number ;
144
- readonly trimLeadingWhiteSpaces ?: boolean ;
145
144
}
146
145
147
146
interface JsxAttributesInfo {
@@ -151,7 +150,7 @@ namespace ts.codefix {
151
150
readonly parentDeclaration : JsxOpeningLikeElement ;
152
151
}
153
152
154
- function getInfo ( sourceFile : SourceFile , tokenPos : number , errorCode : number , checker : TypeChecker , program : Program , formatContext : formatting . FormatContext ) : Info | undefined {
153
+ function getInfo ( sourceFile : SourceFile , tokenPos : number , errorCode : number , checker : TypeChecker , program : Program ) : Info | undefined {
155
154
// The identifier of the missing property. eg:
156
155
// this.missing = 1;
157
156
// ^^^^^^^
@@ -172,8 +171,7 @@ namespace ts.codefix {
172
171
173
172
const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent ) , checker . getTypeAtLocation ( param ) , /* requireOptionalProperties */ false , /* matchDiscriminantProperties */ false ) ) ;
174
173
if ( ! length ( properties ) ) return undefined ;
175
-
176
- return createObjectLiteralInfo ( param . name , properties , parent ) ;
174
+ return { kind : InfoKind . ObjectLiteral , token : param . name , properties, parentDeclaration : parent } ;
177
175
}
178
176
179
177
if ( ! isMemberName ( token ) ) return undefined ;
@@ -182,7 +180,7 @@ namespace ts.codefix {
182
180
const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent . initializer ) , checker . getTypeAtLocation ( token ) , /* requireOptionalProperties */ false , /* matchDiscriminantProperties */ false ) ) ;
183
181
if ( ! length ( properties ) ) return undefined ;
184
182
185
- return createObjectLiteralInfo ( token , properties , parent . initializer ) ;
183
+ return { kind : InfoKind . ObjectLiteral , token, properties, parentDeclaration : parent . initializer } ;
186
184
}
187
185
188
186
if ( isIdentifier ( token ) && isJsxOpeningLikeElement ( token . parent ) ) {
@@ -240,34 +238,6 @@ namespace ts.codefix {
240
238
}
241
239
242
240
return undefined ;
243
-
244
- // for object literal, we want to the indentation work like block
245
- // if { starts in any position (can be in the middle of line)
246
- // the following indentation should treat { as starting of that line (including leading whitespace)
247
- // ```
248
- // const a: { x: undefined, y: undefined } = {} // leading 4 whitespaces and { starts in the middle of line
249
- // ->
250
- // const a: { x: undefined, y: undefined } = {
251
- // x: undefined,
252
- // y: undefined,
253
- // }
254
- // ---------------------
255
- // const a: {x : undefined, y: undefined } =
256
- // {}
257
- // ->
258
- // const a: { x: undefined, y: undefined } =
259
- // { // leading 5 whitespaces and { starts at 6 column
260
- // x: undefined,
261
- // y: undefined,
262
- // }
263
- // ```
264
- function createObjectLiteralInfo ( token : Identifier , properties : Symbol [ ] , parentDeclaration : ObjectLiteralExpression ) : Info {
265
- const formatOptions = getFormatCodeSettingsForWriting ( formatContext , sourceFile ) ;
266
- const lineStartPosition = getLineStartPositionForPosition ( tokenPos , sourceFile ) ;
267
- const indentation = formatting . SmartIndenter . getIndentation ( tokenPos , sourceFile , { ...formatOptions , indentStyle : IndentStyle . Block } , lineStartPosition === tokenPos ) ;
268
-
269
- return { kind : InfoKind . ObjectLiteral , token, properties, indentation, trimLeadingWhiteSpaces : true , parentDeclaration } ;
270
- }
271
241
}
272
242
273
243
function isSourceFileFromLibrary ( program : Program , node : SourceFile ) {
@@ -522,8 +492,7 @@ namespace ts.codefix {
522
492
const options = {
523
493
leadingTriviaOption : textChanges . LeadingTriviaOption . Exclude ,
524
494
trailingTriviaOption : textChanges . TrailingTriviaOption . Exclude ,
525
- indentation : info . indentation ,
526
- trimLeadingWhiteSpaces : info . trimLeadingWhiteSpaces ,
495
+ indentation : info . indentation
527
496
} ;
528
497
changes . replaceNode ( context . sourceFile , info . parentDeclaration , factory . createObjectLiteralExpression ( [ ...info . parentDeclaration . properties , ...props ] , /*multiLine*/ true ) , options ) ;
529
498
}
0 commit comments