microsoft / microsoft/TypeScript
Allow Extract Constant in expression-bodied arrow functions
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
const f = () => 1 + [#|(2 + 3)|] + 4;
Expected:
const f = () => {
const newLocal = (2 + 3);
return 1 + newLocal + 4;
};
We can detect this scenario, but ChangeTracker doesn't support overlapping transformations (i.e. substituting newLocal into the expression and then putting the result into a return statement).
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 Extract Constant refactoring entry point and the ChangeTracker handling for expression-bodied arrow functions. Reproduce the TypeScript example from the issue and trace how the constant substitution and return conversion are represented. Done means the shown expression is converted to a block-bodied arrow function with the local constant and return statement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100