|
1 | 1 | import {
|
2 |
| - addToSeen, |
3 | 2 | ArrowFunction,
|
4 | 3 | BindingElement,
|
5 | 4 | CharacterCodes,
|
@@ -493,7 +492,7 @@ export function isThisTypeAnnotatable(containingFunction: SignatureDeclaration):
|
493 | 492 | export class ChangeTracker {
|
494 | 493 | private readonly changes: Change[] = [];
|
495 | 494 | private newFileChanges?: MultiMap<string, NewFileInsertion>;
|
496 |
| - private readonly classesWithNodesInsertedAtStart = new Map<number, { readonly node: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression; readonly sourceFile: SourceFile; }>(); // Set<ClassDeclaration> implemented as Map<node id, ClassDeclaration> |
| 495 | + private readonly classesWithNodesInsertedAtStart = new Map<number, { readonly node: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression | TypeLiteralNode | EnumDeclaration; readonly sourceFile: SourceFile; }>(); // Set<ClassDeclaration> implemented as Map<node id, ClassDeclaration> |
497 | 496 | private readonly deletedNodes: { readonly sourceFile: SourceFile; readonly node: Node | NodeArray<TypeParameterDeclaration>; }[] = [];
|
498 | 497 |
|
499 | 498 | public static fromContext(context: TextChangesContext): ChangeTracker {
|
@@ -903,7 +902,10 @@ export class ChangeTracker {
|
903 | 902 |
|
904 | 903 | const members = getMembersOrProperties(node);
|
905 | 904 | const isEmpty = members.length === 0;
|
906 |
| - const isFirstInsertion = addToSeen(this.classesWithNodesInsertedAtStart, getNodeId(node), { node, sourceFile }); |
| 905 | + const isFirstInsertion = !this.classesWithNodesInsertedAtStart.has(getNodeId(node)); |
| 906 | + if (isFirstInsertion) { |
| 907 | + this.classesWithNodesInsertedAtStart.set(getNodeId(node), { node, sourceFile }); |
| 908 | + } |
907 | 909 | const insertTrailingComma = isObjectLiteralExpression(node) && (!isJsonSourceFile(sourceFile) || !isEmpty);
|
908 | 910 | const insertLeadingComma = isObjectLiteralExpression(node) && isJsonSourceFile(sourceFile) && isEmpty && !isFirstInsertion;
|
909 | 911 | return {
|
@@ -1246,7 +1248,7 @@ function endPositionToDeleteNodeInList(sourceFile: SourceFile, node: Node, prevN
|
1246 | 1248 | return end;
|
1247 | 1249 | }
|
1248 | 1250 |
|
1249 |
| -function getClassOrObjectBraceEnds(cls: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression, sourceFile: SourceFile): [number | undefined, number | undefined] { |
| 1251 | +function getClassOrObjectBraceEnds(cls: ClassLikeDeclaration | InterfaceDeclaration | ObjectLiteralExpression | TypeLiteralNode | EnumDeclaration, sourceFile: SourceFile): [number | undefined, number | undefined] { |
1250 | 1252 | const open = findChildOfKind(cls, SyntaxKind.OpenBraceToken, sourceFile);
|
1251 | 1253 | const close = findChildOfKind(cls, SyntaxKind.CloseBraceToken, sourceFile);
|
1252 | 1254 | return [open?.end, close?.end];
|
|
0 commit comments