mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 02:15:10 -05:00
fix trailing comma in accessor generator
This commit is contained in:
@@ -204,7 +204,9 @@ namespace ts.refactor.generateGetAccessorAndSetAccessor {
|
||||
function insertAccessor(changeTracker: textChanges.ChangeTracker, file: SourceFile, accessor: AccessorDeclaration, declaration: AcceptedDeclaration, container: ContainerDeclaration) {
|
||||
isParameterPropertyDeclaration(declaration)
|
||||
? changeTracker.insertNodeAtClassStart(file, <ClassLikeDeclaration>container, accessor)
|
||||
: changeTracker.insertNodeAfter(file, declaration, accessor);
|
||||
: isPropertyAssignment(declaration)
|
||||
? changeTracker.insertNodeAfterComma(file, declaration, accessor)
|
||||
: changeTracker.insertNodeAfter(file, declaration, accessor);
|
||||
}
|
||||
|
||||
function updateReadonlyPropertyInitializerStatementConstructor(changeTracker: textChanges.ChangeTracker, context: RefactorContext, constructor: ConstructorDeclaration, fieldName: AcceptedNameType, originalName: AcceptedNameType) {
|
||||
|
||||
@@ -320,10 +320,14 @@ namespace ts.textChanges {
|
||||
return this.replaceRangeWithNodes(sourceFile, getAdjustedRange(sourceFile, startNode, endNode, options), newNodes, options);
|
||||
}
|
||||
|
||||
private nextCommaToken (sourceFile: SourceFile, node: Node): Node | undefined {
|
||||
const next = findNextToken(node, node.parent, sourceFile);
|
||||
return next && next.kind === SyntaxKind.CommaToken ? next : undefined;
|
||||
}
|
||||
|
||||
public replacePropertyAssignment(sourceFile: SourceFile, oldNode: PropertyAssignment, newNode: PropertyAssignment) {
|
||||
return this.replaceNode(sourceFile, oldNode, newNode, {
|
||||
suffix: "," + this.newLineCharacter
|
||||
});
|
||||
const suffix = this.nextCommaToken(sourceFile, oldNode) ? "" : ("," + this.newLineCharacter);
|
||||
return this.replaceNode(sourceFile, oldNode, newNode, { suffix });
|
||||
}
|
||||
|
||||
private insertNodeAt(sourceFile: SourceFile, pos: number, newNode: Node, options: InsertNodeOptions = {}) {
|
||||
@@ -465,6 +469,11 @@ namespace ts.textChanges {
|
||||
}
|
||||
}
|
||||
|
||||
public insertNodeAfterComma(sourceFile: SourceFile, after: Node, newNode: Node): void {
|
||||
const endPosition = this.insertNodeAfterWorker(sourceFile, this.nextCommaToken(sourceFile, after) || after, newNode);
|
||||
this.insertNodeAt(sourceFile, endPosition, newNode, this.getInsertNodeAfterOptions(sourceFile, after));
|
||||
}
|
||||
|
||||
public insertNodeAfter(sourceFile: SourceFile, after: Node, newNode: Node): void {
|
||||
const endPosition = this.insertNodeAfterWorker(sourceFile, after, newNode);
|
||||
this.insertNodeAt(sourceFile, endPosition, newNode, this.getInsertNodeAfterOptions(sourceFile, after));
|
||||
|
||||
Reference in New Issue
Block a user