mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 20:14:05 -05:00
fixAddMissingMember: Add a new PropertyDeclaration at the end of the first set (#23837)
This commit is contained in:
@@ -132,7 +132,24 @@ namespace ts.codefix {
|
||||
/*questionToken*/ undefined,
|
||||
typeNode,
|
||||
/*initializer*/ undefined);
|
||||
changeTracker.insertNodeAtClassStart(classDeclarationSourceFile, classDeclaration, property);
|
||||
|
||||
const lastProp = getNodeToInsertPropertyAfter(classDeclaration);
|
||||
if (lastProp) {
|
||||
changeTracker.insertNodeAfter(classDeclarationSourceFile, lastProp, property);
|
||||
}
|
||||
else {
|
||||
changeTracker.insertNodeAtClassStart(classDeclarationSourceFile, classDeclaration, property);
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the last of the first run of PropertyDeclarations, or undefined if the class does not start with a PropertyDeclaration.
|
||||
function getNodeToInsertPropertyAfter(cls: ClassLikeDeclaration): PropertyDeclaration | undefined {
|
||||
let res: PropertyDeclaration | undefined;
|
||||
for (const member of cls.members) {
|
||||
if (!isPropertyDeclaration(member)) break;
|
||||
res = member;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
function createAddIndexSignatureAction(context: CodeFixContext, classDeclarationSourceFile: SourceFile, classDeclaration: ClassLikeDeclaration, tokenName: string, typeNode: TypeNode): CodeFixAction {
|
||||
|
||||
Reference in New Issue
Block a user