microsoft / microsoft/TypeScript
Compiler API: allow retrieving Symbols for anonymous function and classes
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔍 Search Terms
"compiler api anonymous"
"anonymous getSymbolAtLocation"
✅ Viability Checklist
- 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, new syntax sugar for JS, etc.)
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
⭐ Suggestion
Today when working with AST tree it's convenient to retrieve Symbols of function/classes/variables and use them to represent program "entities". For named function and classes Symbol can be retrieved from a node using typeChecker.getSymbolAtLocation(node.name). Unfortunately for anonymous nodes there doesn't seem to be a way to get Symbol. Even though Symbol is present on the Node object but it's not in public API.
Additionally mentally it's easier to assume that all functions, classes and variables have Symbols.
This is similar to https://github.com/microsoft/TypeScript/issues/26511
Example using ts-ast-viewer:
📃 Motivating Example
No motivating example really. It's pretty niche compiler API improvement that makes working with Compiler more consistent and helps to avoid implementing workarounds.
💻 Use Cases
-
What do you want to use this for?
It's needed for proper implementation of TS indexer in kythe.io. -
What shortcomings exist with current approaches?
Code indexing is built around having Symbols. Places where Symbol is possible to retrieve using public API (e.g. anonymous functions) require hacks or introducing custom symbol-like entity. -
What workarounds are you using in the meantime?
Acessing internalNode.symbolproperty.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
公開エントリポイント typeChecker.getSymbolAtLocation から始め、issue で説明されている内部の Node.symbol プロパティと比較します。関連する issue #26511 を確認し、匿名関数と匿名クラスに必要な公開 API の形を判断します。内部プロパティにアクセスせずにそれらの Symbols を取得できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100