Skip to content

Commit af7b6d9

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 0dc335b commit af7b6d9

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
@@ -554,6 +554,13 @@ namespace A {
554554
[#|let a1 = { x: 1 };
555555
return a1.x + 10;|]
556556
}
557+
}`);
558+
// Write + void return
559+
testExtractMethod("extractMethod21",
560+
`function foo() {
561+
let x = 10;
562+
[#|x++;
563+
return;|]
557564
}`);
558565
});
559566

src/services/refactors/extractMethod.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,10 @@ namespace ts.refactor.extractMethod {
722722
}
723723
else {
724724
newNodes.push(createStatement(createBinary(assignments[0].name, SyntaxKind.EqualsToken, call)));
725+
726+
if (range.facts & RangeFacts.HasReturn) {
727+
newNodes.push(createReturn());
728+
}
725729
}
726730
}
727731
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)