microsoft / microsoft/TypeScript
The module namespace object returned by __importStar is not the same when import the same module multiple times
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
__importStarmodule objectnamespace object
🕗 Version & Regression Information
- Version: 6.0.2
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "namespace import". I did not found any information related to this.
⏯ Playground Link
💻 Code
let p1 = import("fs");
let p2 = import("fs");
Promise.all([p1, p2]).then(([fs1, fs2]) => {
console.log(fs1 === fs2); // expected true
});
🙁 Actual behavior
When the compiled code with node is run, false is printed. This means that the two imported module namespace object is different. each __importStar call create a new module namespace object.
🙂 Expected behavior
true should be printed. The module namespace objects of these two import("fs") should be the same object.
If we run this script directly by node without compiled, true will be printed.
Additional information about the issue
To reproduce this issue, "module" in "tsconfig.json" need to be set to "commonjs". This makes tsc use __importStar and require to import the module.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
__importStar ヘルパーと issue に記載されている CommonJS モジュールパスから始め、リンクされている Playground の例と Node.js の実行を再現手順として使用します。2 つの Promise の結果を比較し、import("fs") の呼び出しを繰り返すと namespace オブジェクトがどのように作成されるかを追跡します。コンパイルされた CommonJS のケースが Node.js の直接的な動作と一致し、同じオブジェクトを返せば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- node.js, typescript
- 領域
- build-system, compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 52/100