Skip to content

Support for private field declarations? #3128

@greggman

Description

@greggman
  • Rollup Version: 1.21.4
  • Operating System (or Browser): N/A
  • Node Version: 12.6.0

How Do We Reproduce?

rollup this code

class Foo {
  #p;
  constructor(v) {
    this.#p = v;
  }
  getV() {
    return this.#p;
  }
};

const a = new Foo('hello');
const b = new Foo('world');
console.log(a.getV(), b.getV());

repl

Expected Behavior

It rolls up

Actual Behavior

It gets a syntax error

Note: the code snippet above works in Chrome https://jsfiddle.net/greggman/z5w1pd9m/ and in node 12

$ node
Welcome to Node.js v12.6.0.
Type ".help" for more information.
> class Foo {
...   #p;
...   constructor(v) {
.....     this.#p = v;
.....   }
...   getV() {
.....     return this.#p;
.....   }
... };
undefined
> 
> const a = new Foo('hello');
undefined
> const b = new Foo('world');
undefined
> console.log(a.getV(), b.getV());
hello world
undefined
> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions