microsoft / microsoft/TypeScript

Add method host.createCustomSourceFile for custom file extensions

Abierto
#52,983 10 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
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

  1. Bundle systems that always take care of importing files that TS doesn't support.
  2. Custom language servers.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.