fix(33362): 'extract to function' for variable that is assigne… (#36455)
This commit is contained in:
parent
fdf29891e2
commit
2cc7a5d6bf
|
@ -437,6 +437,7 @@ namespace ts.refactor.extractSymbol {
|
|||
permittedJumps = PermittedJumps.Return;
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.DefaultClause:
|
||||
case SyntaxKind.CaseClause:
|
||||
// allow unlabeled break inside case clauses
|
||||
permittedJumps |= PermittedJumps.Break;
|
||||
|
|
38
tests/cases/fourslash/extract-method31.ts
Normal file
38
tests/cases/fourslash/extract-method31.ts
Normal file
|
@ -0,0 +1,38 @@
|
|||
/// <reference path='fourslash.ts' />
|
||||
|
||||
//// /*start*/let value: string;
|
||||
//// switch (Date.now()) {
|
||||
//// case 1:
|
||||
//// value = 'foo';
|
||||
//// break;
|
||||
//// default:
|
||||
//// value = 'bar';
|
||||
//// break;
|
||||
//// }/*end*/
|
||||
////
|
||||
//// console.log(value);
|
||||
|
||||
goTo.select("start", "end");
|
||||
edit.applyRefactor({
|
||||
refactorName: "Extract Symbol",
|
||||
actionName: "function_scope_0",
|
||||
actionDescription: "Extract to function in global scope",
|
||||
newContent:
|
||||
`let value: string = /*RENAME*/newFunction();
|
||||
|
||||
console.log(value);
|
||||
|
||||
function newFunction() {
|
||||
let value: string;
|
||||
switch (Date.now()) {
|
||||
case 1:
|
||||
value = 'foo';
|
||||
break;
|
||||
default:
|
||||
value = 'bar';
|
||||
break;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
`
|
||||
});
|
Loading…
Reference in a new issue