microsoft / microsoft/TypeScript
Extract to function in upper scope
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
We have Extract to function in module scope and Extract to inner function in function xxx(which is Extract to function in current scope), we should also have Extract to function in upper scope. With it, we can:
const g = 'g';
export function A() {
const a_local = 'a';
return function B() {
const b_local = 'b';
return function C() {
const c_local = 'c';
// the bottom will be extracted to function upper scope
console.log(g, a_local, b_local, c_local);
// the above will be extracted to function upper scope
}
}
}
After the extraction, code will be:
const g = 'g';
export function A() {
const a_local = 'a';
return function B() {
const b_local = 'b';
function newFunction(c_local: string) {
console.log(g, a_local, b_local, c_local);
}
return function C() {
const c_local = 'c';
newFunction(c_local);
}
}
}
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
Start by locating the implementations and tests for “Extract to function in module scope” and “Extract to function in current scope.” Extend the existing refactoring behavior so extraction can target the upper function scope while passing variables from deeper scopes as parameters, and add coverage matching the TypeScript example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100