Justin Ridgewell 27c39c512d
Class private properties (#7842)
* Update member-expression-to-functions

1. Babel using British spellings, so `memoise`
2. Provide a helper `AssignmentMemoiser` class, which will assign the memo'd value with the `n`th access.

* Private properties!

* Fixes

* Tests

* Update helper name

* Fix privates that reference other privates

* Don't extend a builtin

* Rebase
2018-05-18 14:03:23 -04:00

36 lines
473 B
JavaScript

class Foo {
#bar = "foo";
test() {
return this.#bar;
}
update() {
this.#bar++;
}
set(val) {
this.#bar = val;
}
static test(foo) {
return foo.#bar;
}
static update(foo) {
foo.#bar **= 2;
}
}
const f = new Foo();
expect(f.test()).toBe("foo");
expect(Foo.test(f)).toBe("foo");
expect("bar" in f).toBe(false);
f.set(1);
expect(f.test()).toBe(1);
f.update();
expect(Foo.test(f)).toBe(2);
Foo.update(f);
expect(f.test()).toBe(4);