microsoft / microsoft/TypeScript

API: Allow passing TypeScript.SourceFile / AST directly to transpileModule

Abierto
#28,365 4 comentarios 7 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Domain: API In Discussion Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

Search Terms

transpileModule directly AST SourceFile source performance

Suggestion

Currently, TypeScript.transpileModule accepts string and option as parameters. It would be nice to have another method like this which can accept TypeScript.SourceFile directly.

Use Cases

Currently I'm building a parser which accepts JS for scanning whether ECMAScript syntax above user's project language level / tsconfig.json:target is used. (For example: Your project targets ES2015 but one of the library imported uses ES2017 async-await syntax)

When benchmarked, simply scanning the AST is faster (medium-sized project: 2s. no scan: 1 second) rather than straight-up transpiling every single library in node_modules (same project: 8s). Then, I only need to transpile JS files above project target level for optimal build performance!

It would be nice if I can pass the AST which I obtained from above process straight to transpileModule to prevent double parsing. (Especially since transpileModule uses some internal options such as suppressOutputPathCheck and allowNonTsExtensions)

Examples

Proposed API:

transpileModuleAst(source: TypeScript.SourceFile, transpileOptions: TypeScript.transpileOptions): TypeScript.TranspileOutput

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

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

Comienza con src/services/transpile.ts y el punto de entrada transpileModule mencionado en el issue. Revisa cómo la API actual basada en strings obtiene su SourceFile y gestiona las opciones internas indicadas. Se considera terminado cuando una API compatible acepta un TypeScript.SourceFile y opciones de transpilación, y devuelve TypeScript.TranspileOutput sin requerir que se vuelva a analizar el AST de quien llama.

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
28/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.