Skip to content

@babel/plugin-proposal-class properties: .name incorrect for private fields #10175

@mheiber

Description

@mheiber

Bug Report

Current Behavior

When a function is assigned to a private field, its name property should (I think) be name of the private field. Instead, the name is always value.

Input Code

class A {
    #foo = function () {};
    constructor () {
        console.log(this.#foo.name);
    }
}

new A(); // should log something else (see below)

Expected behavior/code

The code above should log 'foo'.
The code above should log '#foo'

see comment below, I think I read the spec wrong before

Babel Configuration (.babelrc, package.json, cli command)

repl link

Possible Solution

The function generated WeakMap entry could use the name of the private field ('foo' in this case instead of 'value'). per the spec proposal

  _foo.set(this, {
    writable: true,
    value: function value() {}
  });

Side note: not sure what the 'writable' part is doing: what's a read-only private field?

Additional context/Screenshots

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions