Private class methods stage 3 (#8654)
* Add private method syntax support * Add private method spec support * Add private method loose support * Throw error if static private method is used * Add more isStatic & isMethod checks * Remove `writable:false` from private method inits `writable` is false by default. * Add private method func obj equality check * Throw if private accessor is used * Add check for fields === private method loose mode * Throw buildCodeFrameErrors instead of Errors * Move obj destructuring inside for loop * Remove "computed" from ClassPrivateMethod type def
This commit is contained in:
committed by
Justin Ridgewell
parent
6e39b58f8a
commit
0859535b62
11
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/exec.js
vendored
Normal file
11
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/exec.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
class Foo {
|
||||
constructor() {
|
||||
this.publicField = this.#privateMethod();
|
||||
}
|
||||
|
||||
#privateMethod() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
|
||||
expect((new Foo).publicField).toEqual(42);
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
constructor() {
|
||||
this.publicField = this.#privateMethod();
|
||||
}
|
||||
|
||||
#privateMethod() {
|
||||
return 42;
|
||||
}
|
||||
}
|
||||
15
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js
vendored
Normal file
15
packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
var Foo = function Foo() {
|
||||
"use strict";
|
||||
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
|
||||
_privateMethod.add(this);
|
||||
|
||||
this.publicField = babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this);
|
||||
};
|
||||
|
||||
var _privateMethod = new WeakSet();
|
||||
|
||||
var _privateMethod2 = function _privateMethod2() {
|
||||
return 42;
|
||||
};
|
||||
Reference in New Issue
Block a user