microsoft / microsoft/TypeScript
Renaming a module with a default export should rename default imports which match the filename
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
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)
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en la refactorización de renombrado de módulos del módulo language-service de TypeScript y sigue el comportamiento existente descrito en el issue. Añade cobertura para nombres de importaciones default coincidentes y no coincidentes; se considera terminado cuando renombrar foo.ts a baz.ts actualiza una importación coincidente y su uso, mientras que para customName solo cambia la ruta.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- developer-experience, tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 45/100