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

Using recent TypeScript features (e.g. private fields) #255

Closed
lgarron opened this issue Dec 15, 2020 · 3 comments
Closed

Using recent TypeScript features (e.g. private fields) #255

lgarron opened this issue Dec 15, 2020 · 3 comments
Labels
compat CJS/UMD/etc enhancement New feature or request upstream Related to or blocked on an upstream project

Comments

@lgarron
Copy link

lgarron commented Dec 15, 2020

If I modify the demo to do the following:

class WithPrivateField {
  #privateField: number = 0;

  increment(): number {
    return this.#privateField++;
  }
}

const c = new WithPrivateField();
console.log(c.increment());

...this causes Uncaught SyntaxError: Private field '#privateField' must be declared in an enclosing class

If I try to use it for an existing project:

git clone https://github.com/cubing/cubing.js
cd cubing.js
git checkout wmr
npm install
npx wmr --public src/
# Open http://localhost:8080/demo/twisty/mkbhd.html or http://localhost:8080/cubing/twisty/dom/viewers/Twisty3DCanvas.ts

...I get errors like:

Error: Usage of undeclared private name (cubing/twisty/dom/viewers/Twisty3DCanvas.ts:168:14)
  166 |
  167 |     if (this.#invisible) {
---------------------^
  168 |       this.contentWrapper.classList.remove("invisible");
500 ./src/cubing/twisty/dom/viewers/Twisty3DCanvas.ts  - Usage of undeclared private name (cubing/twisty/dom/viewers/Twisty3DCanvas.ts:168:14)
  166 |

The project in question has a recent enough TypeScript as a dependency, but I gather that wmr is using something else. I'd love to try out wmr, but being able to use recent TypeScript without fuss is rather important. Is this something that is meant to be supported, and/or is there something simple I can do to enable it?

@lgarron lgarron changed the title Using recent TypeScript feature (e.g. private fields) Using recent TypeScript features (e.g. private fields) Dec 15, 2020
@developit
Copy link
Member

Here's the upstream issue for fixing this in Sucrase: alangpierce/sucrase#560

@developit developit added compat CJS/UMD/etc enhancement New feature or request upstream Related to or blocked on an upstream project labels Dec 15, 2020
@marvinhagemeister
Copy link
Member

Fixed by #428

@lgarron
Copy link
Author

lgarron commented Jun 25, 2021

Fixed by #428

I gave wmr another try, but it seems that private methods aren't working in wmr 3.1.1. But these were implemented by the same PR to sucrase, which indicates to me they should be working. Am I missing something?

EDIT: now filed at #708

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat CJS/UMD/etc enhancement New feature or request upstream Related to or blocked on an upstream project
Projects
None yet
Development

No branches or pull requests

3 participants