mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 20:14:01 -06:00
Merge pull request #18164 from amcasey/GH18140
Handle the combination of a write and a void return (cherry picked from commit 02cfb81ac0c9b870d31be14b16b0a08ea24ed32a)
This commit is contained in:
parent
d36f254f5e
commit
2dd647d08c
@ -554,6 +554,13 @@ namespace A {
|
||||
[#|let a1 = { x: 1 };
|
||||
return a1.x + 10;|]
|
||||
}
|
||||
}`);
|
||||
// Write + void return
|
||||
testExtractMethod("extractMethod21",
|
||||
`function foo() {
|
||||
let x = 10;
|
||||
[#|x++;
|
||||
return;|]
|
||||
}`);
|
||||
});
|
||||
|
||||
|
||||
@ -722,6 +722,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 {
|
||||
|
||||
26
tests/baselines/reference/extractMethod/extractMethod21.ts
Normal file
26
tests/baselines/reference/extractMethod/extractMethod21.ts
Normal file
@ -0,0 +1,26 @@
|
||||
// ==ORIGINAL==
|
||||
function foo() {
|
||||
let x = 10;
|
||||
x++;
|
||||
return;
|
||||
}
|
||||
// ==SCOPE::function 'foo'==
|
||||
function foo() {
|
||||
let x = 10;
|
||||
return /*RENAME*/newFunction();
|
||||
|
||||
function newFunction() {
|
||||
x++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// ==SCOPE::global scope==
|
||||
function foo() {
|
||||
let x = 10;
|
||||
x = /*RENAME*/newFunction(x);
|
||||
return;
|
||||
}
|
||||
function newFunction(x: number) {
|
||||
x++;
|
||||
return x;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user