Skip to content

Inner classes don't inherit private class member mangling #14209

@lukaslihotzki

Description

@lukaslihotzki

Inner scopes can inherit identifiers of private class members, and also shadow them. This is similar to regular block-scopes identifiers. For example, the following code outputs "foo":

class X {
    constructor() {
        this.#foo = "foo";
    }
    get y() {
        let self = this;
        return class Y {
            constructor() {
                console.log(self.#foo);
            }
        };
    }
    #foo; // Note that private identifiers are also inherited by preceding inner `class` scopes. 
}

new new X().y();

The mangler currently breaks this code by transforming #foo in the outer scope only:

class X{constructor(){this.#e=`foo`}get y(){let e=this;return class{constructor(){console.log(e.#foo)}}}#e}new new X().y;

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions