microsoft / microsoft/TypeScript

__decorate helper should not use `this` when targeting modules

未关闭
#35,802 0 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Awaiting More Feedback Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
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. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用报告的 3.7.x-dev 版本或当前 compiler 重现链接的 TypeScript Playground 示例,并检查生成的 __decorate helper。追踪生成此 helper 的 compiler 入口点;当模块输出不再包含顶层的 this 引用,同时 decorator 行为保持不变时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, typescript
领域
compilers
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。