microsoft / microsoft/TypeScript
Refactor to extract existing function to outer scope
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 3.1.0-dev.20180813
Code
function a(x: number) {
function b(y: number) {
return x + y;
}
return b(1);
}
Expected behavior:
Refactor on b to convert to:
function a(x: number) {
return b(1, x);
}
function b(y: number, x: number) {
return x + y;
}
Actual behavior:
No such refactor.
We already have the ability to refactor code to an outer scope. So a workaround is to highlight the entire body of b and refactor to a function in global scope, then delete b and rename the refactored function to b, then manually update call sites.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names the nested function b and the existing refactor-to-outer-scope capability; start by locating that refactor entry point and its tests. Reproduce the nested-function case, then verify that the refactor moves b, passes captured x as an argument, and updates the call site.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100