This is similar to ec69b4bb1256c061ac76f53dfed09c4283ec6a31, which was about private instance fields. Private properties can be non-writable (thanks to decorators), or have get/set accessors. If we stored this information on the `privateClass` object, we would need to always use `Object.getOwnPropertyDescriptor` before reading or writing a property because accessors need to be called with the correct `this` context (it should be the actual class, not the object hat stores the private properties). This commit simplifies that operation a bit by removing the container object. It also have another advantage, which instance fields already have thanks to the use of separate weakmaps: unused private static fields can be tree-shaken away or garbage-collected, while properties of an object can't. Also, they can be easilier minified.
38 lines
697 B
JavaScript
38 lines
697 B
JavaScript
class Base {
|
|
static getThis() {
|
|
return babelHelpers.classStaticPrivateFieldSpecGet(this, Base, _foo);
|
|
}
|
|
|
|
static updateThis(val) {
|
|
return babelHelpers.classStaticPrivateFieldSpecSet(this, Base, _foo, val);
|
|
}
|
|
|
|
static getClass() {
|
|
return babelHelpers.classStaticPrivateFieldSpecGet(Base, Base, _foo);
|
|
}
|
|
|
|
static updateClass(val) {
|
|
return babelHelpers.classStaticPrivateFieldSpecSet(Base, Base, _foo, val);
|
|
}
|
|
|
|
}
|
|
|
|
var _foo = {
|
|
writable: true,
|
|
value: 1
|
|
};
|
|
|
|
class Sub1 extends Base {
|
|
static update(val) {
|
|
return babelHelpers.classStaticPrivateFieldSpecSet(this, Sub1, _foo2, val);
|
|
}
|
|
|
|
}
|
|
|
|
var _foo2 = {
|
|
writable: true,
|
|
value: 2
|
|
};
|
|
|
|
class Sub2 extends Base {}
|