microsoft / microsoft/TypeScript
Expose serializers from TypeScript transformer (ts.ts)
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
With the introduction of the Transform API some of the logic in transformers/ts.ts needs to be exposed. (and maybe from other places...)
I'll explain by example:
@SomeDecorator()
export class MyClass {
constructor(public myInterface: MyInterface, public myClass: MyOtherClass) {}
}
If I want to transform the code so all parameter type metadata will be on a static property of the class. (this is angular DI)
@SomeDecorator()
export class MyClass {
constructor(public myInterface: MyInterface, public myClass: MyOtherClass) { }
static ctorParams: [Object, MyOtherClass];
}
This operation is currently impossible.
To get the right identifier for each type I need to serialize the type with some logic so MyInterface will become Object since it's not really a value.
The native TypeScript transformer has a lot of code for handling the logic of type serialization and it's not something one will want to copy, its huge.
Even if someone decided to replicate the logic, there's not access to the EmitResolver which is the "type checker" used by the native transformer to serialize the types.
TransformationContext.getEmitResolver() is @internal
The workaround is to actually run another Program process to get access to a TypeChecker.
It's not even possible to get a hold of the current running Program instance since TransformerFactory does not get access to it.
Is it possible to expose the serializatoin logic in the TypeScript transformer? I know it's complex, recursing and state dependant (scope) but it seems like not being able to serialize a type to create a literal is something basic
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
src/compiler/transformers/ts.ts と Transform API から始め、次に TransformationContext.getEmitResolver() と、issue で説明されている EmitResolver の使用方法を調査します。カスタム transformer で型のシリアライズを再利用するために必要な公開 API の境界を特定し、MyInterface のようなパラメーター型が 2 つ目の Program を必要とせずに Object としてシリアライズされることを検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100