microsoft / microsoft/TypeScript
Add a modifier for "closed" blocks and functions
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Search Terms
puppeteer, worker, webpack
Suggestion
Add a closed clause to create blocks/functions that cannot capture any value outside the scope of the block. Any dependencies must be imported explicitly within the block. These dependencies can be inlined to form a self-contained block (using an extra inline keyword in the closed statement or through a boolean field in the compiler options). The resulting inline block can be optimized and unused code can be removed.
Use Cases
Serialize functions
Tools like puppeteer provide functions to perform a callback in the browser context. These callbacks are serialized. This can cause problems with functions in TypeScript, since the language uses tslib and errors like awaiter is not defined can occur. Also, the compiler will not report an error when any value is captured within the callback, but these values will not be available within the browser context.
Workers in webpack
There are some problems when using workers with webpack. The emitted code for the import|require statements contains functions that will not be available in the worker scope. With a closed inline block, these problems are resolved without needs to use any extra plugin or loader.
Examples
const path = require('path')
closed {
const pathSeparator = path.sep // Compiler error - `path` is not defined
import('path').then(module => { // The right way
// ...
})
}
closed inline {
const pathSeparator = path.sep // Compiler error - `path` is not defined
import('path').then(module => { // The right way
// The path module will be inlined within the `closed inline` block
})
}
closed function foo() {
const pathSeparator = path.sep // Compiler error - `path` is not defined
import('path').then(module => { // The right way
// ...
})
}
closed inline foo() {
const pathSeparator = path.sep // Compiler error - `path` is not defined
import('path').then(module => { // The right way
// The path module will be inlined within the `closed inline` function
})
}
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
ファイル、テスト、またはコンパイラのエントリポイントは指定されていません。まず、提案されている closed および closed inline 構文と、シリアライゼーションおよび webpack worker のユースケースを確認してください。外側のスコープからキャプチャされた値が拒否され、明示的な import が機能し、要求された inline の動作が定義・実装されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript, webpack
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100