Closed
Description
Bug Report
π Search Terms
vs code quick fix refactoring code action arrow anonymous function
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about refactorings
β― Playground Link
N/A
π» Code
const fn1 = () => {
const x = 1;
const y = x + 1;
};
const fn2 = function () {
const x = 1;
const y = x + 1;
};
- Select the line that includes
const y
in either of the above function expressions - Try to find and run the "extract to inner function" refactoring
π Actual behavior
The "extract to inner function" refactoring is not listed.
π Expected behavior
The "extract to inner function" refactoring is listed and produces this code:
const fn1 = () => {
const x = 1;
const y = newFunction();
function newFunction() {
return x + 1;
}
};
const fn2 = function () {
const x = 1;
const y = newFunction();
function newFunction() {
return x + 1;
}
};
Note: ideally it would produce arrow functions but that's a separate issue: #31860
It seems this refactoring is only available inside of function declarations. Is there a reason for this?
function fn0() {
const x = 1;
const y = x + 1;
}
This produces:
function fn0() {
const x = 1;
const y = newFunction();
function newFunction() {
return x + 1;
}
}