[private methods] Define private methods before executing initializers (#9248)

This commit is contained in:
Nicolò Ribaudo
2019-01-03 20:33:44 +01:00
committed by GitHub
parent 49f52bbcb3
commit 865eb93c2d
7 changed files with 127 additions and 2 deletions

View File

@@ -0,0 +1,16 @@
class Cl {
prop = this.#method(1);
#priv = this.#method(2);
#method(x) {
return x;
}
getPriv() {
return this.#priv;
}
}
expect(new Cl().prop).toBe(1);
expect(new Cl().getPriv()).toBe(2);

View File

@@ -0,0 +1,13 @@
class Cl {
prop = this.#method(1);
#priv = this.#method(2);
#method(x) {
return x;
}
getPriv() {
return this.#priv;
}
}

View File

@@ -0,0 +1,34 @@
var Cl =
/*#__PURE__*/
function () {
"use strict";
function Cl() {
babelHelpers.classCallCheck(this, Cl);
_method.add(this);
babelHelpers.defineProperty(this, "prop", babelHelpers.classPrivateMethodGet(this, _method, _method2).call(this, 1));
_priv.set(this, {
writable: true,
value: babelHelpers.classPrivateMethodGet(this, _method, _method2).call(this, 2)
});
}
babelHelpers.createClass(Cl, [{
key: "getPriv",
value: function getPriv() {
return babelHelpers.classPrivateFieldGet(this, _priv);
}
}]);
return Cl;
}();
var _priv = new WeakMap();
var _method = new WeakSet();
var _method2 = function _method2(x) {
return x;
};