microsoft / microsoft/TypeScript
Add method host.createCustomSourceFile for custom file extensions
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.4k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Suggestion
Hello, I like the new option --allowArbitraryExtensions in 5 TS, but this only works for created files on the file system or overriding a set of fs methods (readDirectory , readFile , etc).
Generating files on real time is not very efficient, so we have to override different methods so that the TS receives the created instance SourceFile without creating a file on filesystem.
I propose to add a new method createCustomSourceFile to the host, which is undefined by default, if the user has defined this method in the host, then the TS should call it for all files with extensions that the TS does not support (.css, .svg, .vue, etc).
📃 Motivating Example
host.createCustomSourceFile = function (fileName, sourceText): SourceFile {
switch (fileName.slice(fileName.lastIndexOf('.'))) {
case '.css':
return ts.createSourceFile(fileName, getDtsOfCss(sourceText));
case '.svg':
return ts.createSourceFile(fileName, getDtsOfSvg(sourceText));
}
};
💻 Use Cases
- Bundle systems that always take care of importing files that TS doesn't support.
- Custom language servers.
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
El issue no menciona ningún archivo ni prueba del repositorio; empieza siguiendo el flujo de carga de archivos del host y los overrides de fs existentes que se usan con --allowArbitraryExtensions. Compara cómo se gestionan las extensiones no compatibles y, después, define el comportamiento de la API del host y las pruebas para un callback opcional createCustomSourceFile que proporcione instancias de SourceFile sin crear archivos en el sistema de archivos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- api, compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100