Merge pull request #24438 from vpukhanov/issue-22674

addMethodDeclaration: add after quickfix location if possible
This commit is contained in:
Mohamed Hegazy
2018-05-30 10:30:01 -07:00
committed by GitHub
4 changed files with 35 additions and 28 deletions

View File

@@ -199,6 +199,13 @@ namespace ts.codefix {
preferences: UserPreferences,
): void {
const methodDeclaration = createMethodFromCallExpression(callExpression, token.text, inJs, makeStatic, preferences);
changeTracker.insertNodeAtClassStart(classDeclarationSourceFile, classDeclaration, methodDeclaration);
const containingMethodDeclaration = getAncestor(callExpression, SyntaxKind.MethodDeclaration);
if (containingMethodDeclaration && containingMethodDeclaration.parent === classDeclaration) {
changeTracker.insertNodeAfter(classDeclarationSourceFile, containingMethodDeclaration, methodDeclaration);
}
else {
changeTracker.insertNodeAtClassStart(classDeclarationSourceFile, classDeclaration, methodDeclaration);
}
}
}

View File

@@ -14,13 +14,13 @@ verify.codeFixAll({
newFileContent:
`class C {
x: number;
y(): any {
throw new Error("Method not implemented.");
}
method() {
this.x = 0;
this.y();
this.x = "";
}
y(): any {
throw new Error("Method not implemented.");
}
}`,
});

View File

@@ -18,9 +18,6 @@ verify.codeFixAll({
fixAllDescription: "Add all missing members",
newFileContent:
`class C {
y() {
throw new Error("Method not implemented.");
}
constructor() {
this.x = undefined;
}
@@ -29,5 +26,8 @@ verify.codeFixAll({
this.y();
this.x;
}
y() {
throw new Error("Method not implemented.");
}
}`,
});

View File

@@ -14,15 +14,15 @@ verify.codeFix({
index: 0,
newFileContent:
`class A {
static m1(arg0: any, arg1: any, arg2: any): any {
throw new Error("Method not implemented.");
}
static foo0() {
this.m1(1,2,3);
A.m2(1,2);
this.prop1 = 10;
A.prop2 = "asdf";
}
static m1(arg0: any, arg1: any, arg2: any): any {
throw new Error("Method not implemented.");
}
}`,
});
@@ -31,18 +31,18 @@ verify.codeFix({
index: 0,
newFileContent:
`class A {
static m2(arg0: any, arg1: any): any {
throw new Error("Method not implemented.");
}
static m1(arg0: any, arg1: any, arg2: any): any {
throw new Error("Method not implemented.");
}
static foo0() {
this.m1(1,2,3);
A.m2(1,2);
this.prop1 = 10;
A.prop2 = "asdf";
}
static m2(arg0: any, arg1: any): any {
throw new Error("Method not implemented.");
}
static m1(arg0: any, arg1: any, arg2: any): any {
throw new Error("Method not implemented.");
}
}`,
});
@@ -52,18 +52,18 @@ verify.codeFix({
newFileContent:
`class A {
static prop1: number;
static m2(arg0: any, arg1: any): any {
throw new Error("Method not implemented.");
}
static m1(arg0: any, arg1: any, arg2: any): any {
throw new Error("Method not implemented.");
}
static foo0() {
this.m1(1,2,3);
A.m2(1,2);
this.prop1 = 10;
A.prop2 = "asdf";
}
static m2(arg0: any, arg1: any): any {
throw new Error("Method not implemented.");
}
static m1(arg0: any, arg1: any, arg2: any): any {
throw new Error("Method not implemented.");
}
}`,
});
@@ -74,17 +74,17 @@ verify.codeFix({
`class A {
static prop1: number;
static prop2: string;
static m2(arg0: any, arg1: any): any {
throw new Error("Method not implemented.");
}
static m1(arg0: any, arg1: any, arg2: any): any {
throw new Error("Method not implemented.");
}
static foo0() {
this.m1(1,2,3);
A.m2(1,2);
this.prop1 = 10;
A.prop2 = "asdf";
}
static m2(arg0: any, arg1: any): any {
throw new Error("Method not implemented.");
}
static m1(arg0: any, arg1: any, arg2: any): any {
throw new Error("Method not implemented.");
}
}`,
});