Skip to content

"Inline temporary variable" quickfix #46440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
srmagura opened this issue Oct 20, 2021 · 1 comment
Closed

"Inline temporary variable" quickfix #46440

srmagura opened this issue Oct 20, 2021 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@srmagura
Copy link

Suggestion

πŸ” Search Terms

  • Quickfix, quick fix
  • Inline temporary variable, inline variable, temporary variable

βœ… Viability Checklist

My suggestion meets these guidelines:

  • [ βœ”οΈ ] This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • [ βœ”οΈ ] This wouldn't change the runtime behavior of existing 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. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • [ βœ”οΈ ] This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

C# has a nice quickfix called "inline temporary variable":

image

I propose adding an equivalent quickfix to TypeScript.

πŸ“ƒ Motivating Example

Developers frequently define variables and then only use them in one place. Inlining such variables can make the code more succinct and readable. As with all quickfixes, this quickfix would simply be a convenient shortcut for what you can already do by hand.

For example, the quickfix would transform this code:

const message = 'Failed to activate foobars.'
throw new Error(message)

into

throw new Error('Failed to activate foobars.')

πŸ’» Use Cases

  • Automate the process of inlining temporary variables that are only used once (in both JavaScript and TypeScript code)
  • (???) Automate the process of inlining temporary variables that are used more than once. The C# quickfix does support this but I'm not sure if it's a useful feature, since inlining a variable that is used multiple times results in duplication.

We would need to define exactly which variable declarations are eligible for this quickfix. I'm not sure since I'm not a compiler person.

@DanielRosenwasser
Copy link
Member

Duplicate of #18459

@DanielRosenwasser DanielRosenwasser marked this as a duplicate of #18459 Nov 4, 2021
@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Nov 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants