Skip to content

Refactor Suggestion: Inline SymbolΒ #53724

Closed
@gioragutt

Description

@gioragutt

Suggestion

πŸ” Search Terms

  • Refactor
  • Inline
  • Symbol
  • Variable
  • Function

βœ… 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

The suggestion is basically to implement the Inline Symbol refactor that already exists in JetBrains IDEs.

As the article linked above shows, there are several types of symbols that can be inlined, but a good idea would be to start with the Inline Variable refactor, as it's likely to be the simplest one.

πŸ“ƒ Motivating Example

Consider the following code:

const message = 'Something happened!';

console.log(message);
console.log(message);

The Inline Symbol refactor, when applied on message (the VariableDeclarator['id']), would replace the instances where the identifier is referenced with the expression that message is assigned to (the VariableDeclarator['init']).

This would be the output:

console.log('Something happened!');
console.log('Something happened!');

πŸ’» Use Cases

Basically, just like Extract Constant, this refactor's main purpose is to reduce time spent making boilerplate-y operations that could be entirely automatic.

Although I'm not a fan of WebStorm, I've used IntelliJ heavily, and the refactorings available there are really top-notch. They save a serious amount of time. For reference, from colleagues using WebStorm, I know these refactorings are implemented for JS/TS as well, so that's proof to me there's no technically blocker from getting it done.

I'd have contributed all the missing refactorings, but that's a bit far, so I'd like to start with the seemingly (I assume it'll be harder than I imagine) easiest one, with the smallest scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions