microsoft / microsoft/TypeScript
Incorrect reference `this` in static context with `experimentalDecorators` enabled
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
🔎 Search Terms
"static this", "experimental decorators"
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about static
⏯ Playground Link
💻 Code
function Decorator (target: Function, key: string | undefined, index: number) {}
class MyClass {
static readonly staticThisRef = this;
constructor(@Decorator foo: number) {}
}
🙁 Actual behavior
MyClass.staticThisRef = (void 0);
🙂 Expected behavior
staticThisRef points to the class.
Additional information about the issue
Enabling or disabling experimentalDecorators fixes the issue.
With experimentalDecorators:
let MyClass = class MyClass {
constructor(foo) { }
};
MyClass.staticThisRef = (void 0);
MyClass = __decorate([
__param(0, Decorator)
], MyClass);
Without experimentalDecorators:
class MyClass {
constructor(foo) { }
}
_a = MyClass;
MyCLass.staticThisRef = _a;
However only experimental decorators support decorating parameters.
Also TypeScript compiler behavior here is different from esbuild with experimentalDecorators feature enabled:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供されている TypeScript Playground の例から始め、experimentalDecorators を有効にした場合と無効にした場合の出力を比較します。デコレートされたコンストラクターパラメーターを持つクラスに対して、static な this 参照を出力するコンパイラーパスを調査します。experimental-decorator の出力によって staticThisRef が MyClass を指し、パラメーターのデコレーションのサポートが維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100