Fix extract method for anon class expressions (#18168)

Check `scope.name` when trying to extract from an anon class
This commit is contained in:
Matt Bierner
2017-08-31 13:21:08 -07:00
committed by Mohamed Hegazy
parent 3d0c239bfd
commit c7b4ed3a91
3 changed files with 37 additions and 1 deletions
+8
View File
@@ -606,6 +606,14 @@ namespace A {
`function F<T, U extends T[], V extends U[]>(v: V) {
[#|v.toString()|];
}`);
testExtractMethod("extractMethod20",
`const _ = class {
a() {
[#|let a1 = { x: 1 };
return a1.x + 10;|]
}
}`);
});
+1 -1
View File
@@ -584,7 +584,7 @@ namespace ts.refactor.extractMethod {
else if (isClassLike(scope)) {
return scope.kind === SyntaxKind.ClassDeclaration
? `class '${scope.name.text}'`
: scope.name.text
: scope.name && scope.name.text
? `class expression '${scope.name.text}'`
: "anonymous class expression";
}
@@ -0,0 +1,28 @@
// ==ORIGINAL==
const _ = class {
a() {
let a1 = { x: 1 };
return a1.x + 10;
}
}
// ==SCOPE::anonymous class expression==
const _ = class {
a() {
return this.newFunction();
}
private newFunction() {
let a1 = { x: 1 };
return a1.x + 10;
}
}
// ==SCOPE::global scope==
const _ = class {
a() {
return newFunction();
}
}
function newFunction() {
let a1 = { x: 1 };
return a1.x + 10;
}