microsoft / microsoft/TypeScript

Code generated for optional call could be optimized when the result is unused

オープン
#38,835 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Effort: Moderate Experience Enhancement Help Wanted Suggestion
主要言語
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、optional chaining を変換する TypeScript コンパイラーのコードを見つけ、現在の JavaScript 出力と望ましい JavaScript 出力の基準として issue の例を使用します。未使用の optional call の結果が、optional chaining の動作を維持したまま、より短い短絡評価の形式になることを確認し、その後、示されたケースのコンパイラーテストを追加または更新します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
javascript, typescript
領域
compilers, performance
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。