Open ArneBab opened 4 years ago
I see an even stronger version of this: Extracting the region in an if-clause extracts the whole if-block:
Minimal broken example:
function something (foo) {
let variable = 0;
if (foo?.length > 0) { // selected region from foo to 0
variable = foo;
}
return variable;
}
Running js2r-extract-function and giving it the new name longFoo yields:
function longFoo(variable, foo) {
if (foo?.length > 0) {
variable = foo;
}
}
function something (foo) {
let variable = 0;
longFoo(variable, foo);
return variable;
}
But it should create:
function longFoo (foo) {
return foo?.length > 0;
}
function something (foo) {
let variable = 0;
if (longFoo(foo)) {
variable = foo;
}
return variable;
}
When using C-c RET e f on a selected region, rs2-refactor extracts the whole line, but my intention is to refactor only the selected region, for example the condition in an if-statement.
In the following example the selected region is indicated by ^ and $:
I expected
js2r-extract-function
to change the code to the following:Instead the refactoring creates the following: