microsoft / microsoft/TypeScript
Code generated for optional call could be optimized when the result is unused
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
The generated code for optional chaining is a little verbose when the "return" value of the expression is not being used. For example, when simply calling a function:
maybe.close?.()
Here is a more complete example.
The second example generates:
(_c = (_b = perhaps.maybe) === null || _b === void 0 ? void 0 : _b.close) === null || _c === void 0 ? void 0 : _c.call(_b);
But could be optimized to:
(_b = perhaps.maybe) !== null && _b !== void 0 && (_c = _b.close) !== null && _c !== void 0 && _c.call(_b);
It's not a huge difference, but it saves 8 characters for each link in the chain.
While the spec says something like: "the expression short-circuits with a return value of undefined", when the return value is meaningless, then only the "short-circuit" part is important.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、optional chaining を変換する TypeScript コンパイラーのコードを見つけ、現在の JavaScript 出力と望ましい JavaScript 出力の基準として issue の例を使用します。未使用の optional call の結果が、optional chaining の動作を維持したまま、より短い短絡評価の形式になることを確認し、その後、示されたケースのコンパイラーテストを追加または更新します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers, performance
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100