microsoft / microsoft/TypeScript
computed keys with private element and super call should not be hoisted when targeted to ES2022
Đang mở
@rbuckton đang làm issue này rồi.
Từ ngày 13/12/2023.
Bug
Domain: classes
Effort: Moderate
- Ngôn ngữ chính
- Go
- Star
- 111k
- Fork
- 14.4k
- Merge trung bình
- 1 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 117
Mô tả
🔎 Search Terms
Private element, computed key, super call
🕗 Version & Regression Information
- This is a crash
- This changed between versions ______ and _______
- This changed in commit or PR _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Classes
- I was unable to test this on prior versions because _______
⏯ Playground Link
💻 Code
let capturedFooAccess, result;
class B {
constructor(v) {
capturedFooAccess = v
}
}
new class C extends B {
constructor() {
class A {
static #foo = 42;
static [super((t) => t.#foo)];
};
result = capturedFooAccess(A);
}
}
console.log({ result });
🙁 Actual behavior
The transformed code throws "Private field '#foo' must be declared in an enclosing class" because the private key IIFE is hoisted before class A.
🙂 Expected behavior
It should print { result: 42 }
The input is already ES2022, TS could have left it as-is.
Additional information about the issue
We can dodge this issue in ES2022 target, but I haven't figured out how to deal with the decorator expression. Either we lost the #foo access or the super() is moved to the scope of the underived class A.
let capturedFooAccess, result;
class B {
constructor(v) {
capturedFooAccess = v
}
}
new class C extends B {
constructor() {
class A {
@(super((t) => t.#foo), v => v) #foo = 42;
};
result = capturedFooAccess(A);
}
}
console.log({ result });
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Đánh giá
Issue này chưa được đánh giá.