microsoft / microsoft/TypeScript

Inline function refactoring

Offen
#27,070 7 Kommentare 33 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Domain: LS: Refactorings In Discussion Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

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)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginnen Sie mit den Beispielen für Inline-Funktionen und dem angeforderten Verhalten zur Auswahl einer Funktionsdeklaration oder Aufrufstelle. Überprüfen Sie, wie der TypeScript-Editor derzeit Refactorings verarbeitet, und bestimmen Sie die Semantik für das Ersetzen von Vorkommen, das Beibehalten des Verhaltens und das optionale Entfernen der Definition. Im Issue werden keine Dateien oder Tests genannt, daher müssen der Einstiegspunkt der Implementierung und die Prüfungen für den Abschluss noch ermittelt werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript, typescript
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.