microsoft / microsoft/TypeScript

__decorate helper should not use `this` when targeting modules

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

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

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

TypeScript Version: 3.7.x-dev.201xxxxx

Search Terms: __decorate this module

Code

class Foo {
  @property() x = 1;
}

Expected behavior:
Top-level this reference is not emitted.

Actual behavior:

The __decrate variable is declared like:

var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {

Since top-level this is always undefined in modules, (this && this.__decorate) || can be omitted. It's only a few bytes, but the presence of top-level this also causes warnings in other downstream tools like Rollup.

A few other things could be fixed for an ES6+ helper, btw:

  • Use const instead of var (allows for some VM optimizations)
  • Remove Reflect.decorate
  • Don't use arguments

Playground Link: https://www.typescriptlang.org/play/?ts=Nightly#code/MYGwhgzhAEBiD29oG8BQ1oAEAOAne2AprgC4CeAFAJTQAe0AvNAIwDcqAvkA

Related Issues: None?

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

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

はじめの一歩

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

調査の方向性

リンク先の TypeScript Playground の例を、報告された 3.7.x-dev バージョンまたは現在のコンパイラーを使って再現し、出力された __decorate ヘルパーを調査します。このヘルパーを出力するコンパイラーのエントリポイントを追跡します。モジュール出力にトップレベルの this 参照が含まれなくなり、デコレーターの動作が維持されていれば完了です。

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

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
42/100

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

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