microsoft / microsoft/TypeScript
Avoid nesting IIFE for nested namespaces
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
iife namespace nest
Suggestion
Produce a single IIFE for a nested namespace, where applicable.
The point is to reduce onion-like layering in scenarios where it is both trivial and safe to do. There would still be at least 1 level of IIFE wrapping. Every aspect of runtime/semantic/scoping behaviours is preserved as in the current emit.
Example
| TypeScript | JavaScript |
|---|---|
|
|
| desired JavaScript | |
|
Use Cases
Nested IIFE can affect performance, epecially in older/constrained environments. Of course, in general case they cannot be avoided, as they create lexical scopes and may have code living in all those nesting levels.
But there are several easy-to-detect scenarios where avoiding IIFE infestation is cheap and easy:
namespace A.B.Cwith single statement of dot-separated nest chainnamespace A { namespace B {} }with namespace having a single AST node child of another namespace- may have 2 slightly different cases depends on
exportmodifier
- may have 2 slightly different cases depends on
- combination of the above
Note that this feature only affects JS emits, but not parsing neither declaration handling.
Also, this may feel related to #447 Partial modules and output optimization, but the suggestion there is much more broad and heavy to implementation.
Here I do not suggest merging of scopes, just eliminating an easy-to-detect subset of empty scopes that have no code in them.
Non-targeted cases
- This feature explicitly DOES NOT suggest merging consecutive scopes, whether in one file or multiple (that may be a valid thing to do elsewhere).
- This feature explicitly DOES NOT suggest eliding scopes that have code in them (that would be an error, and should be tested against by a valid implementation).
- This feature explicitly DOES NOT intend to elide all possible scopes/layers, only a very few specific easy to check cases.
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, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue にはソースファイル、テスト、エントリポイントが記載されていません。まず、ネストされた namespace を出力するコンパイラーパスと、既存の namespace 出力テストを見つけ、一覧にあるケースについて現在の JavaScript と期待する JavaScript を比較してください。指定された空の IIFE 層だけを削除し、動作が維持されていることをテストで示せれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100