Skip to content

Commit 1bf5078

Browse files
committed
Merge pull request microsoft#18164 from amcasey/GH18140
Handle the combination of a write and a void return (cherry picked from commit 02cfb81)
1 parent fedd8de commit 1bf5078

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

src/harness/unittests/extractMethods.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,13 @@ namespace A {
615615
[#|let a1 = { x: 1 };
616616
return a1.x + 10;|]
617617
}
618+
}`);
619+
// Write + void return
620+
testExtractMethod("extractMethod21",
621+
`function foo() {
622+
let x = 10;
623+
[#|x++;
624+
return;|]
618625
}`);
619626
});
620627

src/services/refactors/extractMethod.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,10 @@ namespace ts.refactor.extractMethod {
734734
}
735735
else {
736736
newNodes.push(createStatement(createBinary(assignments[0].name, SyntaxKind.EqualsToken, call)));
737+
738+
if (range.facts & RangeFacts.HasReturn) {
739+
newNodes.push(createReturn());
740+
}
737741
}
738742
}
739743
else {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// ==ORIGINAL==
2+
function foo() {
3+
let x = 10;
4+
x++;
5+
return;
6+
}
7+
// ==SCOPE::function 'foo'==
8+
function foo() {
9+
let x = 10;
10+
return /*RENAME*/newFunction();
11+
12+
function newFunction() {
13+
x++;
14+
return;
15+
}
16+
}
17+
// ==SCOPE::global scope==
18+
function foo() {
19+
let x = 10;
20+
x = /*RENAME*/newFunction(x);
21+
return;
22+
}
23+
function newFunction(x: number) {
24+
x++;
25+
return x;
26+
}

0 commit comments

Comments
 (0)