[private methods] Define private methods before executing initializers (#9248)
This commit is contained in:
parent
49f52bbcb3
commit
865eb93c2d
@ -366,7 +366,7 @@ export function buildFieldsInitNodes(
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case isInstance && isPrivate && isMethod && loose:
|
case isInstance && isPrivate && isMethod && loose:
|
||||||
instanceNodes.push(
|
instanceNodes.unshift(
|
||||||
buildPrivateMethodInitLoose(
|
buildPrivateMethodInitLoose(
|
||||||
t.thisExpression(),
|
t.thisExpression(),
|
||||||
prop,
|
prop,
|
||||||
@ -378,7 +378,7 @@ export function buildFieldsInitNodes(
|
|||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case isInstance && isPrivate && isMethod && !loose:
|
case isInstance && isPrivate && isMethod && !loose:
|
||||||
instanceNodes.push(
|
instanceNodes.unshift(
|
||||||
buildPrivateInstanceMethodInitSpec(
|
buildPrivateInstanceMethodInitSpec(
|
||||||
t.thisExpression(),
|
t.thisExpression(),
|
||||||
prop,
|
prop,
|
||||||
|
|||||||
@ -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);
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
class Cl {
|
||||||
|
prop = this.#method(1);
|
||||||
|
|
||||||
|
#priv = this.#method(2);
|
||||||
|
|
||||||
|
#method(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPriv() {
|
||||||
|
return this.#priv;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,33 @@
|
|||||||
|
var Cl =
|
||||||
|
/*#__PURE__*/
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function Cl() {
|
||||||
|
babelHelpers.classCallCheck(this, Cl);
|
||||||
|
Object.defineProperty(this, _method, {
|
||||||
|
value: _method2
|
||||||
|
});
|
||||||
|
this.prop = babelHelpers.classPrivateFieldLooseBase(this, _method)[_method](1);
|
||||||
|
Object.defineProperty(this, _priv, {
|
||||||
|
writable: true,
|
||||||
|
value: babelHelpers.classPrivateFieldLooseBase(this, _method)[_method](2)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
babelHelpers.createClass(Cl, [{
|
||||||
|
key: "getPriv",
|
||||||
|
value: function getPriv() {
|
||||||
|
return babelHelpers.classPrivateFieldLooseBase(this, _priv)[_priv];
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
return Cl;
|
||||||
|
}();
|
||||||
|
|
||||||
|
var _priv = babelHelpers.classPrivateFieldLooseKey("priv");
|
||||||
|
|
||||||
|
var _method = babelHelpers.classPrivateFieldLooseKey("method");
|
||||||
|
|
||||||
|
var _method2 = function _method2(x) {
|
||||||
|
return x;
|
||||||
|
};
|
||||||
@ -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);
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
class Cl {
|
||||||
|
prop = this.#method(1);
|
||||||
|
|
||||||
|
#priv = this.#method(2);
|
||||||
|
|
||||||
|
#method(x) {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPriv() {
|
||||||
|
return this.#priv;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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;
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user