microsoft / microsoft/TypeScript
Add method host.createCustomSourceFile for custom file extensions
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue ではリポジトリ内のファイルもテストも指定されていません。まず、ホストのファイル読み込み経路と、--allowArbitraryExtensions で使用されている既存の fs オーバーライドを追跡してください。サポートされていない拡張子がどのように処理されるかを比較し、そのうえで、ファイルシステム上にファイルを作成せずに SourceFile インスタンスを提供する、オプションの createCustomSourceFile callback に対するホスト API の動作とテストを定義してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- api, compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100