microsoft / microsoft/TypeScript
Renaming a module with a default export should rename default imports which match the filename
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
Search Terms
rename default import
Suggestion
I noticed that recently it became possible to auto-import default exports of modules:
// foo.ts
export default 42;
// bar.ts
const x = 3 + foo
// ^ control-space here will offer to `import foo from './foo'`
This is great and finally makes default exports worth using in TypeScript, so thank you!
Also recently, TypeScript got native support for refactoring names of modules. Now, what would be really awesome is if the rename refactor for modules could take into account default exports, so that when we rename foo.ts to baz.ts this would happen in bar.ts:
-import foo from './foo';
+import baz from './baz';
-const x = 3 + foo;
+const x = 3 + baz;
Basically, try to preserve the cases where the name given to a default import matches that of the module being imported. For cases where a default export is imported with a name not matching the module, it would leave it alone:
-import customName from './foo';
+import customName from './baz';
const x = 3 + customName;
This would really make default exports exceptionally useful in TypeScript, because it would potentially reduce by half the number of refactoring gestures needed to rename a set of terms which are 1-to-1 with modules.
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. new expression-level syntax)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne im Refactoring zum Umbenennen von Modulen im language-service-Modul von TypeScript und verfolge das im Issue beschriebene bestehende Verhalten. Füge Abdeckung für übereinstimmende und nicht übereinstimmende Namen von Default-Imports hinzu; abgeschlossen ist dies, wenn das Umbenennen von foo.ts in baz.ts einen übereinstimmenden Import und dessen Verwendung aktualisiert, während für customName nur der Pfad geändert wird.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- developer-experience, tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 45/100