microsoft / microsoft/TypeScript

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

Aperta
#28,365 4 commenti 7 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Domain: API In Discussion Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

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)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da src/services/transpile.ts e dall’entry point transpileModule indicato nell’issue. Esamina come l’attuale API basata su stringhe ottiene il proprio SourceFile e gestisce le opzioni interne elencate. Il lavoro è completato quando un’API supportata accetta un TypeScript.SourceFile e le opzioni di transpilation e restituisce TypeScript.TranspileOutput senza richiedere di analizzare nuovamente l’AST del chiamante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
api, compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
28/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.