microsoft / microsoft/TypeScript
Inline function refactoring
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
inline function method refactoring
Suggestion
I would like a refactoring that inlines a function from
1: function foo() { return 42; }
2: function bar() { const meaningOfLife = foo(); }
to
1: function bar() { const meaningOfLife = 42; }
Use Cases
This is a very common refactoring and thus widely used while cleaning up code.
Examples
In the above code sample, block 1, line 1: selecting foo, the user should be able to inline this function to every occurence and optionally delete the function definition.
In the above code sample, block 1, line 2: selecting foo, the user should be able to inline the function to this occurence, and, if it's the only one, optionally delete the function definition.
I am not sure how the option can be handled in vscode. Eclipse brings up a pop-up with the two options, but afaik vs code tries to be minimalist.
Checklist
My suggestion meets these guidelines:
- This wouldn't change the runtime behavior of existing JavaScript code
- This wouldn't be a breaking change in existing TypeScript / JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. new expression-level syntax)
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 from the inline-function examples and the requested behavior for selecting a function declaration or call site. Review how the TypeScript editor currently handles refactorings and determine the semantics for replacing occurrences, preserving behavior, and optionally removing the definition. The issue names no files or tests, so the implementation entry point and completion checks still need to be identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100