Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/harness/unittests/extractFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,13 @@ var q = /*b*/ //c
/*g*/ + /*h*/ //i
/*j*/ 2|] /*k*/ //l
/*m*/; /*n*/ //o`);

testExtractFunction("extractFunction_NamelessClass", `
export default class {
M() {
[#|1 + 1|];
}
}`);
});

function testExtractFunction(caption: string, text: string, includeLib?: boolean) {
Expand Down
2 changes: 1 addition & 1 deletion src/services/refactors/extractSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ namespace ts.refactor.extractSymbol {
}
function getDescriptionForClassLikeDeclaration(scope: ClassLikeDeclaration): string {
return scope.kind === SyntaxKind.ClassDeclaration
? `class '${scope.name.text}'`
? scope.name ? `class '${scope.name.text}'` : "anonymous class declaration"
: scope.name ? `class expression '${scope.name.text}'` : "anonymous class expression";
}
function getDescriptionForModuleLikeDeclaration(scope: SourceFile | ModuleBlock): string | SpecialScope {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ==ORIGINAL==

export default class {
M() {
/*[#|*/1 + 1/*|]*/;
}
}
// ==SCOPE::Extract to method in anonymous class declaration==

export default class {
M() {
this./*RENAME*/newMethod();
}

newMethod() {
1 + 1;
}
}
// ==SCOPE::Extract to function in module scope==

export default class {
M() {
/*RENAME*/newFunction();
}
}

function newFunction() {
1 + 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ==ORIGINAL==

export default class {
M() {
/*[#|*/1 + 1/*|]*/;
}
}
// ==SCOPE::Extract to method in anonymous class declaration==

export default class {
M() {
this./*RENAME*/newMethod();
}

private newMethod() {
1 + 1;
}
}
// ==SCOPE::Extract to function in module scope==

export default class {
M() {
/*RENAME*/newFunction();
}
}

function newFunction() {
1 + 1;
}