microsoft / microsoft/TypeScript

Allow Extract Constant in expression-bodied arrow functions

Open
#18,924 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Domain: LS: Refactorings Experience Enhancement Suggestion
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.