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:
Huáng Jùnliàng
2021-03-03 16:38:16 -05:00
committed by GitHub
parent 70c77e550c
commit bdb207cb75
49 changed files with 520 additions and 134 deletions

View File

@@ -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');

View File

@@ -0,0 +1,7 @@
class Foo {
static #client
constructor(props) {
([Foo.#client] = props);
}
}

View File

@@ -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
});

View File

@@ -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');

View File

@@ -0,0 +1,7 @@
class Foo {
static #client
constructor(props) {
({ client: Foo.#client } = props)
}
}

View File

@@ -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
});

View File

@@ -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');

View File

@@ -0,0 +1,7 @@
class Foo {
static #client
constructor(props) {
([Foo.#client] = props);
}
}

View File

@@ -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
};

View File

@@ -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');

View File

@@ -0,0 +1,7 @@
class Foo {
static #client
constructor(props) {
({ client: Foo.#client } = props)
}
}

View File

@@ -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
};