Skip to content

Commit 02cfb81

Browse files
authored
Merge pull request #18164 from amcasey/GH18140
Handle the combination of a write and a void return
2 parents 27f9cdb + 0e50da6 commit 02cfb81

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
@@ -613,6 +613,13 @@ namespace A {
613613
[#|let a1 = { x: 1 };
614614
return a1.x + 10;|]
615615
}
616+
}`);
617+
// Write + void return
618+
testExtractMethod("extractMethod21",
619+
`function foo() {
620+
let x = 10;
621+
[#|x++;
622+
return;|]
616623
}`);
617624
});
618625

src/services/refactors/extractMethod.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ namespace ts.refactor.extractMethod {
748748
}
749749
else {
750750
newNodes.push(createStatement(createBinary(assignments[0].name, SyntaxKind.EqualsToken, call)));
751+
752+
if (range.facts & RangeFacts.HasReturn) {
753+
newNodes.push(createReturn());
754+
}
751755
}
752756
}
753757
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 newFunction();
11+
12+
function newFunction() {
13+
x++;
14+
return;
15+
}
16+
}
17+
// ==SCOPE::global scope==
18+
function foo() {
19+
let x = 10;
20+
x = newFunction(x);
21+
return;
22+
}
23+
function newFunction(x: number) {
24+
x++;
25+
return x;
26+
}

0 commit comments

Comments
 (0)