fixAddMissingMember: Add a new PropertyDeclaration at the end of the first set (#23837)
This commit is contained in:
parent
5aa0a79dac
commit
306418e171
|
@ -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 {
|
||||
|
|
|
@ -78,9 +78,8 @@ verify.codeFix({
|
|||
index: 1, // fix at index 0 is to change the spelling to 'prop1'
|
||||
newFileContent:
|
||||
`class A {
|
||||
static prop2: string;
|
||||
|
||||
static prop1: number;
|
||||
static prop2: string;
|
||||
|
||||
static m2(arg0: any, arg1: any): any {
|
||||
throw new Error("Method not implemented.");
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
|
||||
verify.rangeAfterCodeFix(`
|
||||
class A {
|
||||
x: (x: number, y?: A) => number | A;
|
||||
y: number;
|
||||
x: (x: number, y?: A) => number | A;
|
||||
constructor(public a: number) {
|
||||
this.x = function(x: number, y?: A){
|
||||
return x > 0 ? x : y;
|
||||
|
|
Loading…
Reference in a new issue