568c8a3298
If there are only declarations, use the new function as the initializer for a destructuring declaration. If there are declarations and writes, changes all of the `const` declarations to `let` and add `| undefined` onto any explicit types. Use destructuring assignment to accomplish both "initialization" and writes. I don't believe there is a case where there are both declarations and a return (since the declarations wouldn't be available after the return). UNDONE: this could probably be generalized to handle binding patterns but, for now, only identifiers are supported. Fixes #18242 Fixes #18855
16 lines
275 B
TypeScript
16 lines
275 B
TypeScript
// ==ORIGINAL==
|
|
|
|
/*[#|*/const x = 1, y = "a";
|
|
const z = 3;/*|]*/
|
|
x; y; z;
|
|
|
|
// ==SCOPE::Extract to function in global scope==
|
|
|
|
const { x, y, z } = /*RENAME*/newFunction();
|
|
x; y; z;
|
|
|
|
function newFunction() {
|
|
const x = 1, y = "a";
|
|
const z = 3;
|
|
return { x, y, z };
|
|
}
|