microsoft / microsoft/TypeScript

__esDecorate transpiled code uses "Symbol" even of this is shadowed by a local variable

Đang mở
#61,884 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Bug Domain: Decorators Help Wanted
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ả

### 🔎 Search Terms

helper symbol tslib

### 🕗 Version & Regression Information

- This changed between versions 5.1.6 and 5.2.2

Tested via playground and reading its debug output.

### ⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.0-dev.20250617#code/GYVwdgxgLglg9mABMOcAiBTCcBOBDKXAClxgHMYw8AbAWQygAs4ATALkTzAE8AaRbGCgYAHlA5duASkQBvAL4AoRaIAOuKAOp4AzjsQBlbgFsARnGpyBCHVBwhoxGbMTzXygAIp0WXAVwqIuo4mhDaeojG3ADC4fqyiohJgrb2jjhEzoiJSbkpmgD6YBgA7kbGiAC8iMUlhibm1JkA3DnuSkA

### 💻 Code

```ts
function fooDecorator(originalMethod: any, context: any) {}

export class Symbol { constructor() { } }

@fooDecorator
export class myClass {
constructor() {
const _newSym = new Symbol();
}
}
```

### 🙁 Actual behavior

The generated js code for `myClass` contains
```ts
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
```
Which will access my local variable `Symbol` instead of `window.Symbol`/`globalThis.Symbol`.

### 🙂 Expected behavior

The generated code should access `globalThis.Symbol` in any case or perhaps only if the file contains a local variable (from `class`, `const` or `import`) with a colliding name.

### Additional information about the issue

I found this with an `import { Symbol } from "./service";` call (roughly modelled via this [Bug Workbench](https://www.typescriptlang.org/dev/bug-workbench/#code/PTAEAEDMEsBsFMB2BDAtvAXKAzvATgG7QDG8AdAC7YBQwAVHaABKrSgDKAnqgEYD2sUHWDV4ADwAOfPBVDFYybNg7d+ggN6g5fRNgp4ArsQrSAFAEpQmgL6hr1WmChwkaTKGQSJlGtFRSZKxVeATtQSDw+VFAAIjJgXEISeBiAbgdIA0RjaB1wvj4AEXhiaWQTPFNS3X0jCqwAMSycnUt1eygC4tK8culRSWlZeUVlVE4AYQUlK2otbRrDYzM20Dn5rWq9UAB9SALQAF5QRHgAd2C1C3T5+3sgA)) but this should not change the main problem.

We started to use the class name `Symbol` in our code (and public API) since 2014.

Right now we circumvent this issue by using different names inside the local file via alias names in `import`/`export`
But this is hard to understand and maintain.

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

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

Hướng nghiên cứu

Bắt đầu với TypeScript playground được liên kết và kiểm tra mã __esDecorate được tạo ra để tìm khai báo hoặc import Symbol cục bộ. Theo dõi cách helper siêu dữ liệu của decorator chọn tham chiếu Symbol, sau đó xác minh rằng mã được sinh ra không còn phân giải binding cục bộ và vẫn xử lý được ví dụ decorator được hiển thị.

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

Đánh giá

Công nghệ
typescript
Lĩnh vực
compilers
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 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
45/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.