mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Fix extract method for anon class expressions (#18168)
Check `scope.name` when trying to extract from an anon class
This commit is contained in:
committed by
Mohamed Hegazy
parent
3d0c239bfd
commit
c7b4ed3a91
@@ -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;|]
|
||||
}
|
||||
}`);
|
||||
});
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user