@@ -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
}
@@ -151,7 +151,7 @@ namespace ts.codefix {
151
151
readonly parentDeclaration : JsxOpeningLikeElement ;
152
152
}
153
153
154
- function getInfo ( sourceFile : SourceFile , tokenPos : number , errorCode : number , checker : TypeChecker , program : Program , formatContext : formatting . FormatContext ) : Info | undefined {
154
+ function getInfo ( sourceFile : SourceFile , tokenPos : number , errorCode : number , checker : TypeChecker , program : Program ) : Info | undefined {
155
155
// The identifier of the missing property. eg:
156
156
// this.missing = 1;
157
157
// ^^^^^^^
@@ -172,8 +172,7 @@ namespace ts.codefix {
172
172
173
173
const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent ) , checker . getTypeAtLocation ( param ) , /* requireOptionalProperties */ false , /* matchDiscriminantProperties */ false ) ) ;
174
174
if ( ! length ( properties ) ) return undefined ;
175
-
176
- return createObjectLiteralInfo ( param . name , properties , parent ) ;
175
+ return { kind : InfoKind . ObjectLiteral , token : param . name , properties, parentDeclaration : parent } ;
177
176
}
178
177
179
178
if ( ! isMemberName ( token ) ) return undefined ;
@@ -182,7 +181,7 @@ namespace ts.codefix {
182
181
const properties = arrayFrom ( checker . getUnmatchedProperties ( checker . getTypeAtLocation ( parent . initializer ) , checker . getTypeAtLocation ( token ) , /* requireOptionalProperties */ false , /* matchDiscriminantProperties */ false ) ) ;
183
182
if ( ! length ( properties ) ) return undefined ;
184
183
185
- return createObjectLiteralInfo ( token , properties , parent . initializer ) ;
184
+ return { kind : InfoKind . ObjectLiteral , token, properties, parentDeclaration : parent . initializer } ;
186
185
}
187
186
188
187
if ( isIdentifier ( token ) && isJsxOpeningLikeElement ( token . parent ) ) {
@@ -240,34 +239,6 @@ namespace ts.codefix {
240
239
}
241
240
242
241
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
242
}
272
243
273
244
function isSourceFileFromLibrary ( program : Program , node : SourceFile ) {
@@ -511,6 +482,7 @@ namespace ts.codefix {
511
482
}
512
483
513
484
function addObjectLiteralProperties ( changes : textChanges . ChangeTracker , context : CodeFixContextBase , info : ObjectLiteralInfo ) {
485
+ // debugger;
514
486
const importAdder = createImportAdder ( context . sourceFile , context . program , context . preferences , context . host ) ;
515
487
const quotePreference = getQuotePreference ( context . sourceFile , context . preferences ) ;
516
488
const target = getEmitScriptTarget ( context . program . getCompilerOptions ( ) ) ;
@@ -522,8 +494,7 @@ namespace ts.codefix {
522
494
const options = {
523
495
leadingTriviaOption : textChanges . LeadingTriviaOption . Exclude ,
524
496
trailingTriviaOption : textChanges . TrailingTriviaOption . Exclude ,
525
- indentation : info . indentation ,
526
- trimLeadingWhiteSpaces : info . trimLeadingWhiteSpaces ,
497
+ indentation : info . indentation
527
498
} ;
528
499
changes . replaceNode ( context . sourceFile , info . parentDeclaration , factory . createObjectLiteralExpression ( [ ...info . parentDeclaration . properties , ...props ] , /*multiLine*/ true ) , options ) ;
529
500
}
0 commit comments