1/* @internal */ 2namespace ts.codefix { 3 const fixId = "fixPropertyAssignment"; 4 const errorCodes = [ 5 Diagnostics.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern.code 6 ]; 7 8 registerCodeFix({ 9 errorCodes, 10 fixIds: [fixId], 11 getCodeActions(context) { 12 const { sourceFile, span } = context; 13 const property = getProperty(sourceFile, span.start); 14 const changes = textChanges.ChangeTracker.with(context, t => doChange(t, context.sourceFile, property)); 15 return [createCodeFixAction(fixId, changes, [Diagnostics.Change_0_to_1, "=", ":"], fixId, [Diagnostics.Switch_each_misused_0_to_1, "=", ":"])]; 16 }, 17 getAllCodeActions: context => 18 codeFixAll(context, errorCodes, (changes, diag) => doChange(changes, diag.file, getProperty(diag.file, diag.start))) 19 }); 20 21 function doChange(changes: textChanges.ChangeTracker, sourceFile: SourceFile, node: ShorthandPropertyAssignment): void { 22 changes.replaceNode(sourceFile, node, factory.createPropertyAssignment(node.name, node.objectAssignmentInitializer as Expression)); 23 } 24 25 function getProperty(sourceFile: SourceFile, pos: number): ShorthandPropertyAssignment { 26 return cast(getTokenAtPosition(sourceFile, pos).parent, isShorthandPropertyAssignment); 27 } 28} 29