Skip to content

this incorrectly transformed to _classThis in downlevel static accessorΒ #54473

@rbuckton

Description

@rbuckton

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions