-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Description
Bug Report
π Search Terms
static accessor this
π Version & Regression Information
- This is the behavior since ES Decorators were introduced in 5.0
β― Playground Link
Playground link with relevant code
π» Code
// @experimentalDecorators: false
// @target: es2021
@((t, c) => t)
class C {
static #a = 0;
static get a() { return this.#a; }
static set a(v) { this.#a = v; }
static accessor b = 0;
}
// correctly errors at runtime.
Object.getOwnPropertyDescriptor(C, "a")!.get!.call({});
// correctly errors at runtime.
Object.getOwnPropertyDescriptor(C, "a")!.set!.call({}, 1);
// should error at runtime, but does not.
Object.getOwnPropertyDescriptor(C, "b")!.get!.call({});
// should error at runtime, but does not.
Object.getOwnPropertyDescriptor(C, "b")!.set!.call({}, 1);π Actual behavior
The emit for static accessor b incorrectly transforms a this into _classThis:
let C = (() => {
...
var C = _classThis = class {
static get a() { return __classPrivateFieldGet(this, _classThis, "f", _a); }
static set a(v) { __classPrivateFieldSet(this, _classThis, v, "f", _a); }
static get b() { return __classPrivateFieldGet(_classThis, _classThis, "f", _b_accessor_storage); }
static set b(value) { __classPrivateFieldSet(_classThis, _classThis, value, "f", _b_accessor_storage); }
};
...
})();The result is that the actual this isn't correctly brand-checked.
π Expected behavior
let C = (() => {
...
var C = _classThis = class {
static get a() { return __classPrivateFieldGet(this, _classThis, "f", _a); }
static set a(v) { __classPrivateFieldSet(this, _classThis, v, "f", _a); }
static get b() { return __classPrivateFieldGet(this, _classThis, "f", _b_accessor_storage); }
static set b(value) { __classPrivateFieldSet(this, _classThis, value, "f", _b_accessor_storage); }
};
...
})();Metadata
Metadata
Assignees
Labels
No labels