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

Do not use classPrivateMethodGet #16283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/babel-helper-create-class-features-plugin/src/fields.ts
Expand Up @@ -491,11 +491,14 @@ const privateNameHandlerSpec: Handler<PrivateNameState & Receiver> & Receiver =
t.cloneNode(getId),
]);
}
return t.callExpression(file.addHelper("classPrivateMethodGet"), [
this.receiver(member),
t.cloneNode(id),
t.cloneNode(methodId),
]);
return t.callExpression(
file.addHelper(
!process.env.BABEL_8_BREAKING && !newHelpers(file)
? "classPrivateMethodGet"
: "assertClassBrand",
),
[this.receiver(member), t.cloneNode(id), t.cloneNode(methodId)],
);
}
return t.callExpression(
process.env.BABEL_8_BREAKING || newHelpers(file)
Expand Down
Expand Up @@ -10,7 +10,7 @@ class Derived extends Base {
babelHelpers.classPrivateMethodInitSpec(this, _Derived_brand);
}
static get(obj) {
return babelHelpers.classPrivateMethodGet(obj, _Derived_brand, _foo).call(obj);
return babelHelpers.assertClassBrand(obj, _Derived_brand, _foo).call(obj);
}
}
function _foo() {
Expand Down
1 change: 1 addition & 0 deletions packages/babel-helpers/src/helpers.ts
Expand Up @@ -1728,6 +1728,7 @@ helpers.decorate = helper("7.1.5")`

`;

// TODO: Remove in Babel 8
helpers.classPrivateMethodGet = helper("7.1.6")`
import assertClassBrand from "assertClassBrand";
export default function _classPrivateMethodGet(receiver, privateSet, fn) {
Expand Down
Expand Up @@ -13,7 +13,7 @@ class Sub extends Base {
return 'bad';
}
publicMethod() {
return babelHelpers.classPrivateMethodGet(this, _Sub_brand, _privateMethod).call(this);
return babelHelpers.assertClassBrand(this, _Sub_brand, _privateMethod).call(this);
}
}
function _privateMethod() {
Expand Down
Expand Up @@ -2,7 +2,7 @@ var _A_brand = /*#__PURE__*/new WeakSet();
class A {
constructor() {
babelHelpers.classPrivateMethodInitSpec(this, _A_brand);
babelHelpers.classPrivateMethodGet(this, _A_brand, _method).call(this);
babelHelpers.assertClassBrand(this, _A_brand, _method).call(this);
babelHelpers.classPrivateGetter(this, _A_brand, _get_getter);
babelHelpers.classPrivateSetter(this, _A_brand, _set_setter, 1);
babelHelpers.classPrivateGetter(this, _A_brand, _get_getset);
Expand Down
Expand Up @@ -2,7 +2,7 @@ var _Foo_brand = /*#__PURE__*/new WeakSet();
class Foo {
constructor() {
babelHelpers.classPrivateMethodInitSpec(this, _Foo_brand);
this.publicField = babelHelpers.classPrivateMethodGet(this, _Foo_brand, _privateMethod).call(this);
this.publicField = babelHelpers.assertClassBrand(this, _Foo_brand, _privateMethod).call(this);
}
}
function _privateMethod() {
Expand Down
Expand Up @@ -4,7 +4,7 @@ class Cl {
babelHelpers.classPrivateMethodInitSpec(this, _Cl_brand);
}
test() {
return babelHelpers.classPrivateMethodGet(this, _Cl_brand, _foo).call(this);
return babelHelpers.assertClassBrand(this, _Cl_brand, _foo).call(this);
}
}
async function _foo() {
Expand Down
Expand Up @@ -3,8 +3,8 @@ var _Cl_brand = /*#__PURE__*/new WeakSet();
class Cl {
constructor() {
babelHelpers.classPrivateMethodInitSpec(this, _Cl_brand);
babelHelpers.defineProperty(this, "prop", babelHelpers.classPrivateMethodGet(this, _Cl_brand, _method).call(this, 1));
babelHelpers.classPrivateFieldInitSpec(this, _priv, babelHelpers.classPrivateMethodGet(this, _Cl_brand, _method).call(this, 2));
babelHelpers.defineProperty(this, "prop", babelHelpers.assertClassBrand(this, _Cl_brand, _method).call(this, 1));
babelHelpers.classPrivateFieldInitSpec(this, _priv, babelHelpers.assertClassBrand(this, _Cl_brand, _method).call(this, 2));
}
getPriv() {
return babelHelpers.classPrivateFieldGet2(this, _priv);
Expand Down
Expand Up @@ -4,7 +4,7 @@ console.log((_A_brand = /*#__PURE__*/new WeakSet(), class A {
babelHelpers.classPrivateMethodInitSpec(this, _A_brand);
}
method() {
babelHelpers.classPrivateMethodGet(this, _A_brand, _foo).call(this);
babelHelpers.assertClassBrand(this, _A_brand, _foo).call(this);
}
}));
function _foo() {}
Expand Up @@ -5,13 +5,13 @@ class Foo {
this.status = status;
}
getCurrentStatus() {
return babelHelpers.classPrivateMethodGet(this, _Foo_brand, _getStatus).call(this);
return babelHelpers.assertClassBrand(this, _Foo_brand, _getStatus).call(this);
}
setCurrentStatus(newStatus) {
this.status = newStatus;
}
getFakeStatus(fakeStatus) {
var fakeGetStatus = babelHelpers.classPrivateMethodGet(this, _Foo_brand, _getStatus);
var fakeGetStatus = babelHelpers.assertClassBrand(this, _Foo_brand, _getStatus);
return function () {
return fakeGetStatus.call({
status: fakeStatus
Expand All @@ -21,7 +21,7 @@ class Foo {
getFakeStatusFunc() {
return {
status: 'fake-status',
getFakeStatus: babelHelpers.classPrivateMethodGet(this, _Foo_brand, _getStatus)
getFakeStatus: babelHelpers.assertClassBrand(this, _Foo_brand, _getStatus)
};
}
}
Expand Down
Expand Up @@ -4,7 +4,7 @@ class Foo {
constructor() {
babelHelpers.classPrivateMethodInitSpec(this, _Foo_brand);
if (exfiltrated === undefined) {
exfiltrated = babelHelpers.classPrivateMethodGet(this, _Foo_brand, _privateMethod);
exfiltrated = babelHelpers.assertClassBrand(this, _Foo_brand, _privateMethod);
}
}
}
Expand Down
Expand Up @@ -4,7 +4,7 @@ class Cl {
babelHelpers.classPrivateMethodInitSpec(this, _Cl_brand);
}
test() {
return babelHelpers.classPrivateMethodGet(this, _Cl_brand, _foo).call(this);
return babelHelpers.assertClassBrand(this, _Cl_brand, _foo).call(this);
}
}
function* _foo() {
Expand Down
Expand Up @@ -14,7 +14,7 @@ class Sub extends Base {
return 'bad';
}
publicMethod() {
return babelHelpers.classPrivateMethodGet(this, _Sub_brand, _privateMethod).call(this);
return babelHelpers.assertClassBrand(this, _Sub_brand, _privateMethod).call(this);
}
}
_Sub = Sub;
Expand Down
Expand Up @@ -5,6 +5,6 @@ class Foo {
}
}
function _tag() {
babelHelpers.classPrivateMethodGet(this, _Foo_brand, _tag).bind(this)``;
babelHelpers.assertClassBrand(this, _Foo_brand, _tag).bind(this)``;
}
new Foo();