Skip to content

"Extract to inner function" refactoring not available inside function expression #44110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OliverJAsh opened this issue May 16, 2021 · 2 comments Β· Fixed by #44206
Closed

"Extract to inner function" refactoring not available inside function expression #44110

OliverJAsh opened this issue May 16, 2021 · 2 comments Β· Fixed by #44206
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Help Wanted You can do this
Milestone

Comments

@OliverJAsh
Copy link
Contributor

OliverJAsh commented May 16, 2021

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;
};
  1. Select the line that includes const y in either of the above function expressions
  2. 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;
    }
}
@OliverJAsh
Copy link
Contributor Author

OliverJAsh commented May 16, 2021

I would be happy to work on this and a few other issues related to these refactorings, but I will most likely need some guidance as I don't really know where to start nor where to find the code responsible.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Help Wanted You can do this labels May 20, 2021
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone May 20, 2021
@OliverJAsh
Copy link
Contributor Author

I've started work on this here: #44206. Does it look like I'm going in the right direction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Refactorings e.g. extract to constant or function, rename symbol Help Wanted You can do this
Projects
None yet
2 participants