Skip to content

Commit 2cc7a5d

Browse files
a-tarasyukDanielRosenwasser
authored andcommitted
fix(33362): 'extract to function' for variable that is assigne… (microsoft#36455)
1 parent fdf2989 commit 2cc7a5d

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/services/refactors/extractSymbol.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ namespace ts.refactor.extractSymbol {
437437
permittedJumps = PermittedJumps.Return;
438438
}
439439
break;
440+
case SyntaxKind.DefaultClause:
440441
case SyntaxKind.CaseClause:
441442
// allow unlabeled break inside case clauses
442443
permittedJumps |= PermittedJumps.Break;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// /*start*/let value: string;
4+
//// switch (Date.now()) {
5+
//// case 1:
6+
//// value = 'foo';
7+
//// break;
8+
//// default:
9+
//// value = 'bar';
10+
//// break;
11+
//// }/*end*/
12+
////
13+
//// console.log(value);
14+
15+
goTo.select("start", "end");
16+
edit.applyRefactor({
17+
refactorName: "Extract Symbol",
18+
actionName: "function_scope_0",
19+
actionDescription: "Extract to function in global scope",
20+
newContent:
21+
`let value: string = /*RENAME*/newFunction();
22+
23+
console.log(value);
24+
25+
function newFunction() {
26+
let value: string;
27+
switch (Date.now()) {
28+
case 1:
29+
value = 'foo';
30+
break;
31+
default:
32+
value = 'bar';
33+
break;
34+
}
35+
return value;
36+
}
37+
`
38+
});

0 commit comments

Comments
 (0)