Skip to content

Commit b629ff4

Browse files
author
Andy
authored
Fix bug: FunctionDeclaration may have missing name (#20618)
1 parent f2f1745 commit b629ff4

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/services/refactors/extractSymbol.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -658,11 +658,10 @@ namespace ts.refactor.extractSymbol {
658658
case SyntaxKind.Constructor:
659659
return "constructor";
660660
case SyntaxKind.FunctionExpression:
661-
return scope.name
662-
? `function expression '${scope.name.text}'`
663-
: "anonymous function expression";
664661
case SyntaxKind.FunctionDeclaration:
665-
return `function '${scope.name.text}'`;
662+
return scope.name
663+
? `function '${scope.name.text}'`
664+
: "anonymous function";
666665
case SyntaxKind.ArrowFunction:
667666
return "arrow function";
668667
case SyntaxKind.MethodDeclaration:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////export default function() {
4+
//// /*start*/0/*end*/
5+
////}
6+
7+
goTo.select('start', 'end')
8+
edit.applyRefactor({
9+
refactorName: "Extract Symbol",
10+
actionName: "function_scope_0",
11+
actionDescription: "Extract to inner function in anonymous function",
12+
newContent:
13+
`export default function() {
14+
/*RENAME*/newFunction();
15+
16+
function newFunction() {
17+
0;
18+
}
19+
}`
20+
});

0 commit comments

Comments
 (0)