microsoft / microsoft/TypeScript

Add a modifier for "closed" blocks and functions

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

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

Awaiting More Feedback Suggestion
主要言語
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
  })
}

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

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

はじめの一歩

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

調査の方向性

ファイル、テスト、またはコンパイラのエントリポイントは指定されていません。まず、提案されている closed および closed inline 構文と、シリアライゼーションおよび webpack worker のユースケースを確認してください。外側のスコープからキャプチャされた値が拒否され、明示的な import が機能し、要求された inline の動作が定義・実装されれば完了です。

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

評価

技術スタック
typescript, webpack
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

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

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