Merge pull request #18164 from amcasey/GH18140

Handle the combination of a write and a void return
This commit is contained in:
Andrew Casey 2017-09-07 16:32:55 -07:00 committed by GitHub
commit 02cfb81ac0
3 changed files with 37 additions and 0 deletions

View file

@ -613,6 +613,13 @@ namespace A {
[#|let a1 = { x: 1 };
return a1.x + 10;|]
}
}`);
// Write + void return
testExtractMethod("extractMethod21",
`function foo() {
let x = 10;
[#|x++;
return;|]
}`);
});

View file

@ -748,6 +748,10 @@ namespace ts.refactor.extractMethod {
}
else {
newNodes.push(createStatement(createBinary(assignments[0].name, SyntaxKind.EqualsToken, call)));
if (range.facts & RangeFacts.HasReturn) {
newNodes.push(createReturn());
}
}
}
else {

View file

@ -0,0 +1,26 @@
// ==ORIGINAL==
function foo() {
let x = 10;
x++;
return;
}
// ==SCOPE::function 'foo'==
function foo() {
let x = 10;
return newFunction();
function newFunction() {
x++;
return;
}
}
// ==SCOPE::global scope==
function foo() {
let x = 10;
x = newFunction(x);
return;
}
function newFunction(x: number) {
x++;
return x;
}