Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for private field declarations? #3128

Closed
greggman opened this issue Sep 23, 2019 · 4 comments
Closed

Support for private field declarations? #3128

greggman opened this issue Sep 23, 2019 · 4 comments

Comments

@greggman
Copy link

greggman commented Sep 23, 2019

  • 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
> 
@keithamus
Copy link
Contributor

You can use the acornInjectPlugins option coupled with the acorn private class elements plugin to handle this:

import acornPrivateFields from 'acorn-private-class-elements'
export default {
    // … other options …
    acornInjectPlugins: [
        acornPrivateFields()
    ]
};

FWIW Private Fields are still a TC39 Stage 3 proposal and are not standardised ECMAScript (yet).

@greggman
Copy link
Author

Oh, I thought the Chromium team had a policy not to ship any unapproved JavaScript features unless they were behind a flag (--experimental-javascript). Since they shipped private class fields not behind a flag in v74 I assumed that must mean the feature had passed some threshold of "approved" otherwise it would still be behind the flag

@lukastaegert
Copy link
Member

I believe support in a major browser is a prerequisite for a Stage 3 feature to become Stage 4.

@shellscape
Copy link
Contributor

Closing this one as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants