Skip to content

Commit ff061a1

Browse files
author
Arthur Ozga
committed
consolidate edits
1 parent d3661f5 commit ff061a1

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/services/codefixes/fixClassDoesntImplementInheritedAbstractMember.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace ts.codefix {
3131

3232
const newNodes = createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, checker);
3333
const changes = newNodesToChanges(newNodes, getOpenBraceOfClassLike(classDeclaration, sourceFile), context);
34-
if(changes && changes.length > 0) {
34+
if (changes && changes.length > 0) {
3535
return [{
3636
description: getLocaleSpecificMessage(Diagnostics.Implement_inherited_abstract_class),
3737
changes

src/services/codefixes/fixClassIncorrectlyImplementsInterface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ namespace ts.codefix {
4545

4646
function createAndAddMissingIndexSignatureDeclaration(type: InterfaceType, kind: IndexKind, hasIndexSigOfKind: boolean, newNodes: Node[]): void {
4747
if (hasIndexSigOfKind) {
48-
return undefined;
48+
return;
4949
}
5050

5151
const indexInfoOfKind = checker.getIndexInfoOfType(type, kind);
5252

5353
if (!indexInfoOfKind) {
54-
return undefined;
54+
return;
5555
}
5656
const newIndexSignatureDeclaration = checker.createIndexSignatureFromIndexInfo(indexInfoOfKind, kind, classDeclaration);
5757
newNodes.push(newIndexSignatureDeclaration);

src/services/codefixes/helpers.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,28 @@ namespace ts.codefix {
33

44
export function newNodesToChanges(newNodes: Node[], insertAfter: Node, context: CodeFixContext) {
55
const sourceFile = context.sourceFile;
6-
if (!(newNodes)) {
7-
throw new Error("newNodesToChanges expects an array");
8-
}
96

107
const changeTracker = textChanges.ChangeTracker.fromCodeFixContext(context);
118

129
for (const newNode of newNodes) {
1310
changeTracker.insertNodeAfter(sourceFile, insertAfter, newNode, { suffix: context.newLineCharacter });
1411
}
15-
// TODO (aozgaa): concatenate changes into a single change.
16-
return changeTracker.getChanges();
12+
13+
const changes = changeTracker.getChanges();
14+
if (!(changes && changes.length > 0)) {
15+
return changes;
16+
}
17+
18+
Debug.assert(changes.length === 1);
19+
const consolidatedChanges: FileTextChanges[] = [{
20+
fileName: changes[0].fileName,
21+
textChanges: [{
22+
span: changes[0].textChanges[0].span,
23+
newText: changes[0].textChanges.reduce((prev, cur) => prev + cur.newText, "")
24+
}]
25+
26+
}]
27+
return consolidatedChanges;
1728
}
1829

1930
/**

0 commit comments

Comments
 (0)