microsoft / microsoft/TypeScript

__decorate helper should not use `this` when targeting modules

Đang mở
#35,802 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Awaiting More Feedback Suggestion
Ngôn ngữ chính
Go
Star
111k
Fork
14.3k
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
132

Mô tả

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?

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Tái hiện ví dụ từ TypeScript Playground được liên kết bằng phiên bản 3.7.x-dev đã báo cáo hoặc compiler hiện tại, và kiểm tra helper __decorate được phát ra. Truy tìm entry point của compiler phát ra helper này; công việc được hoàn tất khi output của module không còn bao gồm tham chiếu this ở cấp cao nhất, trong khi hành vi của decorator vẫn được giữ nguyên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript, typescript
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.