Class static private field destructure set (#12917)
* fix: support static private field destructure set ([C.#p] = [0]) * 🚧 * fix: add compatibility warning for older @babel/helper versions * refactor: extract common routines among classPrivateFiled helpers * More 🚧
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
class Foo {
|
||||
static #client
|
||||
|
||||
constructor(props) {
|
||||
;([Foo.#client] = props);
|
||||
}
|
||||
|
||||
getClient() {
|
||||
return Foo.#client;
|
||||
}
|
||||
}
|
||||
|
||||
const foo = new Foo(['bar']);
|
||||
expect(foo.getClient()).toBe('bar');
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
static #client
|
||||
|
||||
constructor(props) {
|
||||
([Foo.#client] = props);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
var _client = babelHelpers.classPrivateFieldLooseKey("client");
|
||||
|
||||
var Foo = function Foo(props) {
|
||||
"use strict";
|
||||
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
[babelHelpers.classPrivateFieldLooseBase(Foo, _client)[_client]] = props;
|
||||
};
|
||||
|
||||
Object.defineProperty(Foo, _client, {
|
||||
writable: true,
|
||||
value: void 0
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
class Foo {
|
||||
static #client
|
||||
|
||||
constructor(props) {
|
||||
;({ client: Foo.#client } = props)
|
||||
}
|
||||
|
||||
getClient() {
|
||||
return Foo.#client;
|
||||
}
|
||||
}
|
||||
|
||||
const foo = new Foo({ client: 'bar' });
|
||||
expect(foo.getClient()).toBe('bar');
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
static #client
|
||||
|
||||
constructor(props) {
|
||||
({ client: Foo.#client } = props)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
var _client = babelHelpers.classPrivateFieldLooseKey("client");
|
||||
|
||||
var Foo = function Foo(props) {
|
||||
"use strict";
|
||||
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
({
|
||||
client: babelHelpers.classPrivateFieldLooseBase(Foo, _client)[_client]
|
||||
} = props);
|
||||
};
|
||||
|
||||
Object.defineProperty(Foo, _client, {
|
||||
writable: true,
|
||||
value: void 0
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
class Foo {
|
||||
static #client
|
||||
|
||||
constructor(props) {
|
||||
;([Foo.#client] = props);
|
||||
}
|
||||
|
||||
getClient() {
|
||||
return Foo.#client;
|
||||
}
|
||||
}
|
||||
|
||||
const foo = new Foo(['bar']);
|
||||
expect(foo.getClient()).toBe('bar');
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
static #client
|
||||
|
||||
constructor(props) {
|
||||
([Foo.#client] = props);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
var Foo = function Foo(props) {
|
||||
"use strict";
|
||||
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
[babelHelpers.classStaticPrivateFieldDestructureSet(Foo, Foo, _client).value] = props;
|
||||
};
|
||||
|
||||
var _client = {
|
||||
writable: true,
|
||||
value: void 0
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
class Foo {
|
||||
static #client
|
||||
|
||||
constructor(props) {
|
||||
;({ client: Foo.#client } = props)
|
||||
}
|
||||
|
||||
getClient() {
|
||||
return Foo.#client;
|
||||
}
|
||||
}
|
||||
|
||||
const foo = new Foo({ client: 'bar' });
|
||||
expect(foo.getClient()).toBe('bar');
|
||||
@@ -0,0 +1,7 @@
|
||||
class Foo {
|
||||
static #client
|
||||
|
||||
constructor(props) {
|
||||
({ client: Foo.#client } = props)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
var Foo = function Foo(props) {
|
||||
"use strict";
|
||||
|
||||
babelHelpers.classCallCheck(this, Foo);
|
||||
({
|
||||
client: babelHelpers.classStaticPrivateFieldDestructureSet(Foo, Foo, _client).value
|
||||
} = props);
|
||||
};
|
||||
|
||||
var _client = {
|
||||
writable: true,
|
||||
value: void 0
|
||||
};
|
||||
Reference in New Issue
Block a user