Refactor "move to function in module scope" moves function past the following variable declaration
See original GitHub issueTypeScript Version: 3.1.0-dev.20180807
Search Terms: refactor function module
Code
import "fs";
function foo() {
const bar = 1; // select this line
}
let flag = false;
function doSomethingWithFlag() {
}
- select the line with the comment
- choose “extract to function in module scope”
Expected behavior:
import "fs";
function newFunction() {
return 1;
}
function foo() {
const bar = newFunction();
}
let flag = false;
function doSomethingWithFlag() {
}
or
import "fs";
function foo() {
const bar = newFunction();
}
function newFunction() {
return 1;
}
let flag = false;
function doSomethingWithFlag() {
}
Actual behavior:
import "fs";
function foo() {
const bar = newFunction();
}
let flag = false;
function newFunction() {
return 1;
}
function doSomethingWithFlag() {
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Refactoring JavaScript | WebStorm Documentation - JetBrains
The Move Symbol Refactoring works for classes, functions, and variables in ES6 modules. Move a class, a function, or a variable.
Read more >Move declaration near reference refactoring - Microsoft Learn
What: Lets you move variable declarations closer to their usage. When: You have variable declarations that can be in a narrower scope.
Read more >Summary and Criticism of Fowler's “Refactoring” | by Mark Looi
Changing function declaration is often an intermediate step to a further refactoring; in the example, it sets up moving a function into ...
Read more >Refactoring TypeScript - Help | JetBrains Rider
The Move Symbol Refactoring works for classes, functions, and variables in ES6 modules. To move a class, a function, or a variable. Select...
Read more >Refactoring - Eclipse Help
For example, the Refactor > Rename command can automatically locate the declaration(s) and uses of a particular subroutine, and change its name in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@AlCalzone was there more context when you originally opened this issue that would help us out?
For me it was just the placement of the function. The refactor works, but it seems unlogical where the function is placed. In the above example,
newFunction
andfoo
belong together andflag
anddoSomethingWithFlag
logically belong together. After the refactor, this is not immediately clear, especially if there is more than one variable declaration between the functions.