microsoft / microsoft/TypeScript
Add method host.createCustomSourceFile for custom file extensions
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
L’issue non nomina alcun file o test del repository; inizia tracciando il percorso di caricamento dei file dell’host e gli override fs esistenti usati con --allowArbitraryExtensions. Confronta il modo in cui vengono gestite le estensioni non supportate, quindi definisci il comportamento dell’API dell’host e i test per un callback createCustomSourceFile opzionale che fornisca istanze di SourceFile senza creare file nel filesystem.
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
- 35/100