microsoft / microsoft/TypeScript
`--explainFiles` differentiate `import type ...` vs `import`
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Suggestion
explainFiles "import type"
✅ Viability 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. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
I would like the --explainFiles behavior to differentiate between import type and import runtime imports in its printout.
📃 Motivating Example
c:/project/src/server-side/contract
Imported Types via '../server-side/contract' from file 'c:/project/src/client-side/app.tsx'
^^^^^
💻 Use Cases
I am looking for suspected non-import type ... imports that are poisoning our build, bleeding code from non-client files ultimately into client bundles (before maybe tree-shaking them out again). At best, this impacts build performance. I know that better code organization could help avoid confusing import chains and improper imports - that's what I'm trying to untangle it for.
I am using the output from --explainFiles to recognize the various patterns and reconstitute a dependency graph:
const targetPattern = /^(?!\s)(.*)/;
const importedViaPattern = /^ Imported via (['"])(.*)\1 from file '([^']*)'/;
const includePattern = /^ Matched by include pattern (['"])(.*)\1 in '([^']*)'/;
const referencedViaPattern = /^ Referenced via (['"])(.*)\1 from file '([^']*)'/;
const libReferencesPattern = /^ Library referenced via (['"])(.*)\1 from file '([^']*)'/;
const typeLibraryPattern = /^ Type library referenced via (['"])(.*)\1 from file '([^']*)'/;
const fileRedirectsPattern = /^ File redirects to file '([^']*)'/
const compilerOptionsPattern = /^ Library '(.*)' specified in compilerOptions/;
const filesPattern = /^ Part of 'files' list in/;
const implicitTypeLibraryPattern = /^ Entry point for implicit type library/;
There seems to be no difference in the output between an import and an import type so my dependency graph can't cull the type imports that won't be emitted to the next stage in the build pipeline.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
--explainFiles エントリポイントから始め、インポートされたファイルがその出力でどのように表現されているかを追跡します。この issue にはソースファイルもテストパスもありません。出力が import type と実行時の import を区別し、コンシューマーが型専用の依存関係をグラフから除外できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100