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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 520 additions and 134 deletions

View File

@ -49,7 +49,9 @@ jobs:
git config user.email "babel-bot@users.noreply.github.com"
- name: Create new version
run: yarn release-tool version -f @babel/standalone --yes patch
run: |
make new-version-checklist
yarn release-tool version -f @babel/standalone --yes patch
- name: Push to GitHub
id: push
@ -167,5 +169,4 @@ jobs:
- name: Delete temporary branch from GitHub
if: needs.git-version.result == 'success'
run:
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" :${{ needs.git-version.outputs.branch }}
run: git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" :${{ needs.git-version.outputs.branch }}

View File

@ -195,7 +195,21 @@ prepublish:
$(MAKE) prepublish-build
IS_PUBLISH=true $(MAKE) test
new-version-checklist:
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
@echo "!!!!!! !!!!!!"
@echo "!!!!!! Update classStaticPrivateFieldDestructureSet !!!!!!"
@echo "!!!!!! helper version in !!!!!!"
@echo "!!!!!! packages/babel-helpers/src/helpers.js !!!!!!"
@echo "!!!!!! packages/babel-helper-create-class-features-plugin/src/fields.js"
@echo "!!!!!! !!!!!!"
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
@echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
@exit 1
new-version:
$(MAKE) new-version-checklist
git pull --rebase
$(YARN) release-tool version -f @babel/standalone

View File

@ -318,9 +318,30 @@ const privateNameHandlerSpec = {
},
destructureSet(member) {
const { privateNamesMap, file } = this;
const { classRef, privateNamesMap, file } = this;
const { name } = member.node.property.id;
const { id } = privateNamesMap.get(name);
const { id, static: isStatic } = privateNamesMap.get(name);
if (isStatic) {
try {
// classStaticPrivateFieldDestructureSet was introduced in 7.99.0
// eslint-disable-next-line no-var
var helper = file.addHelper("classStaticPrivateFieldDestructureSet");
} catch {
throw new Error(
"Babel can not transpile `[C.#p] = [0]` with @babel/helpers < 7.99.0, \n" +
"please update @babel/helpers to the latest version.",
);
}
return t.memberExpression(
t.callExpression(helper, [
this.receiver(member),
t.cloneNode(classRef),
t.cloneNode(id),
]),
t.identifier("value"),
);
}
return t.memberExpression(
t.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [
this.receiver(member),

View File

@ -1299,11 +1299,81 @@ helpers.classPrivateFieldLooseBase = helper("7.0.0-beta.0")`
`;
helpers.classPrivateFieldGet = helper("7.0.0-beta.0")`
import classApplyDescriptorGet from "classApplyDescriptorGet";
import classExtractFieldDescriptor from "classExtractFieldDescriptor";
export default function _classPrivateFieldGet(receiver, privateMap) {
var descriptor = privateMap.get(receiver);
if (!descriptor) {
throw new TypeError("attempted to get private field on non-instance");
var descriptor = classExtractFieldDescriptor(receiver, privateMap, "get");
return classApplyDescriptorGet(receiver, descriptor);
}
`;
helpers.classPrivateFieldSet = helper("7.0.0-beta.0")`
import classApplyDescriptorSet from "classApplyDescriptorSet";
import classExtractFieldDescriptor from "classExtractFieldDescriptor";
export default function _classPrivateFieldSet(receiver, privateMap, value) {
var descriptor = classExtractFieldDescriptor(receiver, privateMap, "set");
classApplyDescriptorSet(receiver, descriptor, value);
return value;
}
`;
helpers.classPrivateFieldDestructureSet = helper("7.4.4")`
import classApplyDescriptorDestructureSet from "classApplyDescriptorDestructureSet";
import classExtractFieldDescriptor from "classExtractFieldDescriptor";
export default function _classPrivateFieldDestructureSet(receiver, privateMap) {
var descriptor = classExtractFieldDescriptor(receiver, privateMap, "set");
return classApplyDescriptorDestructureSet(receiver, descriptor);
}
`;
helpers.classExtractFieldDescriptor = helper("7.99.0")`
export default function _classExtractFieldDescriptor(receiver, privateMap, action) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to " + action + " private field on non-instance");
}
return privateMap.get(receiver);
}
`;
helpers.classStaticPrivateFieldSpecGet = helper("7.0.2")`
import classApplyDescriptorGet from "classApplyDescriptorGet";
import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess";
import classCheckPrivateStaticFieldDescriptor from "classCheckPrivateStaticFieldDescriptor";
export default function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
classCheckPrivateStaticAccess(receiver, classConstructor);
classCheckPrivateStaticFieldDescriptor(descriptor, "get");
return classApplyDescriptorGet(receiver, descriptor);
}
`;
helpers.classStaticPrivateFieldSpecSet = helper("7.0.2")`
import classApplyDescriptorSet from "classApplyDescriptorSet";
import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess";
import classCheckPrivateStaticFieldDescriptor from "classCheckPrivateStaticFieldDescriptor";
export default function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) {
classCheckPrivateStaticAccess(receiver, classConstructor);
classCheckPrivateStaticFieldDescriptor(descriptor, "set");
classApplyDescriptorSet(receiver, descriptor, value);
return value;
}
`;
helpers.classStaticPrivateMethodGet = helper("7.3.2")`
import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess";
export default function _classStaticPrivateMethodGet(receiver, classConstructor, method) {
classCheckPrivateStaticAccess(receiver, classConstructor);
return method;
}
`;
helpers.classStaticPrivateMethodSet = helper("7.3.2")`
export default function _classStaticPrivateMethodSet() {
throw new TypeError("attempted to set read only static private field");
}
`;
helpers.classApplyDescriptorGet = helper("7.99.0")`
export default function _classApplyDescriptorGet(receiver, descriptor) {
if (descriptor.get) {
return descriptor.get.call(receiver);
}
@ -1311,12 +1381,8 @@ helpers.classPrivateFieldGet = helper("7.0.0-beta.0")`
}
`;
helpers.classPrivateFieldSet = helper("7.0.0-beta.0")`
export default function _classPrivateFieldSet(receiver, privateMap, value) {
var descriptor = privateMap.get(receiver);
if (!descriptor) {
throw new TypeError("attempted to set private field on non-instance");
}
helpers.classApplyDescriptorSet = helper("7.99.0")`
export default function _classApplyDescriptorSet(receiver, descriptor, value) {
if (descriptor.set) {
descriptor.set.call(receiver, value);
} else {
@ -1326,23 +1392,13 @@ helpers.classPrivateFieldSet = helper("7.0.0-beta.0")`
// class bodies.
throw new TypeError("attempted to set read only private field");
}
descriptor.value = value;
}
return value;
}
`;
helpers.classPrivateFieldDestructureSet = helper("7.4.4")`
export default function _classPrivateFieldDestructureSet(receiver, privateMap) {
if (privateMap === undefined) {
throw new TypeError("attempted to set private static field before its declaration");
}
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
var descriptor = privateMap.get(receiver);
helpers.classApplyDescriptorDestructureSet = helper("7.99.0")`
export default function _classApplyDescriptorDestructureSet(receiver, descriptor) {
if (descriptor.set) {
if (!("__destrObj" in descriptor)) {
descriptor.__destrObj = {
@ -1365,57 +1421,30 @@ helpers.classPrivateFieldDestructureSet = helper("7.4.4")`
}
`;
helpers.classStaticPrivateFieldSpecGet = helper("7.0.2")`
export default function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
helpers.classStaticPrivateFieldDestructureSet = helper("7.99.0")`
import classApplyDescriptorDestructureSet from "classApplyDescriptorDestructureSet";
import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess";
import classCheckPrivateStaticFieldDescriptor from "classCheckPrivateStaticFieldDescriptor";
export default function _classStaticPrivateFieldDestructureSet(receiver, classConstructor, descriptor) {
classCheckPrivateStaticAccess(receiver, classConstructor);
classCheckPrivateStaticFieldDescriptor(descriptor, "set");
return classApplyDescriptorDestructureSet(receiver, descriptor);
}
`;
helpers.classCheckPrivateStaticAccess = helper("7.99.0")`
export default function _classCheckPrivateStaticAccess(receiver, classConstructor) {
if (receiver !== classConstructor) {
throw new TypeError("Private static access of wrong provenance");
}
}
`;
helpers.classCheckPrivateStaticFieldDescriptor = helper("7.99.0")`
export default function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {
if (descriptor === undefined) {
throw new TypeError("attempted to get private static field before its declaration");
throw new TypeError("attempted to " + action + " private static field before its declaration");
}
if (descriptor.get) {
return descriptor.get.call(receiver);
}
return descriptor.value;
}
`;
helpers.classStaticPrivateFieldSpecSet = helper("7.0.2")`
export default function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) {
if (receiver !== classConstructor) {
throw new TypeError("Private static access of wrong provenance");
}
if (descriptor === undefined) {
throw new TypeError("attempted to set private static field before its declaration");
}
if (descriptor.set) {
descriptor.set.call(receiver, value);
} else {
if (!descriptor.writable) {
// This should only throw in strict mode, but class bodies are
// always strict and private fields can only be used inside
// class bodies.
throw new TypeError("attempted to set read only private field");
}
descriptor.value = value;
}
return value;
}
`;
helpers.classStaticPrivateMethodGet = helper("7.3.2")`
export default function _classStaticPrivateMethodGet(receiver, classConstructor, method) {
if (receiver !== classConstructor) {
throw new TypeError("Private static access of wrong provenance");
}
return method;
}
`;
helpers.classStaticPrivateMethodSet = helper("7.3.2")`
export default function _classStaticPrivateMethodSet() {
throw new TypeError("attempted to set read only static private field");
}
`;

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

View File

@ -7,6 +7,7 @@ class Cl {
constructor() {
expect(() => this.#privateFieldValue = 1).toThrow(TypeError);
expect(() => ([this.#privateFieldValue] = [1])).toThrow(TypeError);
}
}

View File

@ -7,5 +7,6 @@ class Cl {
constructor() {
this.#privateFieldValue = 1;
([this.#privateFieldValue] = [1]);
}
}

View File

@ -13,6 +13,7 @@ class Cl {
value: 0
});
babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue] = 1;
[babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue]] = [1];
}
}

View File

@ -7,6 +7,7 @@ class Cl {
constructor() {
expect(() => this.#privateFieldValue = 1).toThrow(TypeError);
expect(() => ([this.#privateFieldValue] = [1])).toThrow(TypeError);
}
}

View File

@ -7,5 +7,6 @@ class Cl {
constructor() {
this.#privateFieldValue = 1;
([this.#privateFieldValue] = [1]);
}
}

View File

@ -13,6 +13,7 @@ class Cl {
value: 0
});
babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue] = 1;
[babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue]] = [1];
}
}

View File

@ -14,6 +14,8 @@ class Cl {
constructor() {
expect(() => this.self.#privateFieldValue = 1).toThrow(TypeError);
expect(this.counter).toBe(1);
expect(() => ([this.self.#privateFieldValue] = [1])).toThrow(TypeError);
expect(this.counter).toBe(2);
}
}

View File

@ -13,6 +13,7 @@ class Cl {
constructor() {
this.self.#privateFieldValue = 1
([this.self.#privateFieldValue] = [1]);
}
}

View File

@ -20,7 +20,7 @@ class Cl {
});
babelHelpers.defineProperty(this, "counter", 0);
this.self, 1, babelHelpers.readOnlyError("#privateFieldValue");
this.self, 1([babelHelpers.classPrivateFieldDestructureSet(this.self, _privateFieldValue).value] = [1]), babelHelpers.readOnlyError("#privateFieldValue");
}
}

View File

@ -9,6 +9,7 @@ class A {
constructor() {
expect(() => this.self().#method = 2).toThrow(TypeError);
expect(this.counter).toBe(1);
expect(() => ([this.#method] = [2])).toThrow(TypeError);
}
}

View File

@ -8,5 +8,6 @@ class A {
constructor() {
this.self().#method = 2;
([this.#method] = [2]);
}
}

View File

@ -11,6 +11,7 @@ class A {
babelHelpers.defineProperty(this, "counter", 0);
this.self(), 2, babelHelpers.readOnlyError("#method");
[babelHelpers.classPrivateFieldDestructureSet(this, _method).value] = [2];
}
}

View File

@ -0,0 +1,10 @@
class A {
static #method() {}
run() {
expect(() => A.#method = 2).toThrow(TypeError);
expect(() => ([A.#method] = [2])).toThrow(TypeError);
}
}

View File

@ -0,0 +1,8 @@
class A {
static #method() {}
run() {
A.#method = 2;
([A.#method] = [2]);
}
}

View File

@ -0,0 +1,9 @@
class A {
run() {
babelHelpers.classStaticPrivateMethodSet(A, A, _method, 2);
[babelHelpers.classStaticPrivateFieldDestructureSet(A, A, _method).value] = [2];
}
}
var _method = function _method() {};

View File

@ -0,0 +1,10 @@
class C {
static set #p(v) { C.#q = v }
static #q;
constructor() {
([C.#p] = [0]);
expect(C.#q).toBe(0);
}
}
new C;

View File

@ -0,0 +1,9 @@
class C {
static set #p(v) { C.#q = v }
static #q;
constructor() {
([C.#p] = [0]);
}
}
new C;

View File

@ -0,0 +1,24 @@
var _p = babelHelpers.classPrivateFieldLooseKey("p");
var _q = babelHelpers.classPrivateFieldLooseKey("q");
class C {
constructor() {
[babelHelpers.classPrivateFieldLooseBase(C, _p)[_p]] = [0];
}
}
var _set_p = function (v) {
babelHelpers.classPrivateFieldLooseBase(C, _q)[_q] = v;
};
Object.defineProperty(C, _p, {
get: void 0,
set: _set_p
});
Object.defineProperty(C, _q, {
writable: true,
value: void 0
});
new C();

View File

@ -1,13 +1,14 @@
class Cl {
static #PRIVATE_STATIC_FIELD = 0;
static #privateField = 0;
static get #privateStaticFieldValue() {
return Cl.#PRIVATE_STATIC_FIELD;
static get #privateFieldValue() {
return this.#privateField;
}
static setPrivateStaticFieldValue() {
Cl.#privateStaticFieldValue = 1;
constructor() {
expect(() => Cl.#privateFieldValue = 1).toThrow(TypeError);
expect(() => ([Cl.#privateFieldValue] = [1])).toThrow(TypeError);
}
}
expect(() => Cl.setPrivateStaticFieldValue()).toThrow(TypeError);
const cl = new Cl();

View File

@ -1,11 +1,15 @@
class Cl {
static #PRIVATE_STATIC_FIELD = 0;
static #privateField = 0;
static get #privateStaticFieldValue() {
return Cl.#PRIVATE_STATIC_FIELD;
static get #privateFieldValue() {
return this.#privateField;
}
static setPrivateStaticFieldValue() {
Cl.#privateStaticFieldValue = 1;
constructor() {
Cl.#privateFieldValue = 1;
([Cl.#privateFieldValue] = [1]);
}
}
const cl = new Cl();

View File

@ -1,23 +1,25 @@
var _PRIVATE_STATIC_FIELD = babelHelpers.classPrivateFieldLooseKey("PRIVATE_STATIC_FIELD");
var _privateField = babelHelpers.classPrivateFieldLooseKey("privateField");
var _privateStaticFieldValue = babelHelpers.classPrivateFieldLooseKey("privateStaticFieldValue");
var _privateFieldValue = babelHelpers.classPrivateFieldLooseKey("privateFieldValue");
class Cl {
static setPrivateStaticFieldValue() {
babelHelpers.classPrivateFieldLooseBase(Cl, _privateStaticFieldValue)[_privateStaticFieldValue] = 1;
constructor() {
babelHelpers.classPrivateFieldLooseBase(Cl, _privateFieldValue)[_privateFieldValue] = 1;
[babelHelpers.classPrivateFieldLooseBase(Cl, _privateFieldValue)[_privateFieldValue]] = [1];
}
}
var _get_privateStaticFieldValue = function () {
return babelHelpers.classPrivateFieldLooseBase(Cl, _PRIVATE_STATIC_FIELD)[_PRIVATE_STATIC_FIELD];
var _get_privateFieldValue = function () {
return babelHelpers.classPrivateFieldLooseBase(this, _privateField)[_privateField];
};
Object.defineProperty(Cl, _PRIVATE_STATIC_FIELD, {
Object.defineProperty(Cl, _privateField, {
writable: true,
value: 0
});
Object.defineProperty(Cl, _privateStaticFieldValue, {
get: _get_privateStaticFieldValue,
Object.defineProperty(Cl, _privateFieldValue, {
get: _get_privateFieldValue,
set: void 0
});
var cl = new Cl();

View File

@ -0,0 +1,10 @@
class C {
static set #p(v) { C.#q = v }
static #q;
constructor() {
([C.#p] = [0]);
expect(C.#q).toBe(0);
}
}
new C;

View File

@ -0,0 +1,9 @@
class C {
static set #p(v) { C.#q = v }
static #q;
constructor() {
([C.#p] = [0]);
}
}
new C;

View File

@ -0,0 +1,24 @@
var _p = babelHelpers.classPrivateFieldLooseKey("p");
var _q = babelHelpers.classPrivateFieldLooseKey("q");
class C {
constructor() {
[babelHelpers.classPrivateFieldLooseBase(C, _p)[_p]] = [0];
}
}
var _set_p = function (v) {
babelHelpers.classPrivateFieldLooseBase(C, _q)[_q] = v;
};
Object.defineProperty(C, _p, {
get: void 0,
set: _set_p
});
Object.defineProperty(C, _q, {
writable: true,
value: void 0
});
new C();

View File

@ -1,13 +1,14 @@
class Cl {
static #PRIVATE_STATIC_FIELD = 0;
static #privateField = 0;
static get #privateStaticFieldValue() {
return Cl.#PRIVATE_STATIC_FIELD;
static get #privateFieldValue() {
return this.#privateField;
}
static setPrivateStaticFieldValue() {
Cl.#privateStaticFieldValue = 1;
constructor() {
expect(() => Cl.#privateFieldValue = 1).toThrow(TypeError);
expect(() => ([Cl.#privateFieldValue] = [1])).toThrow(TypeError);
}
}
expect(() => Cl.setPrivateStaticFieldValue()).toThrow(TypeError);
const cl = new Cl();

View File

@ -1,11 +1,15 @@
class Cl {
static #PRIVATE_STATIC_FIELD = 0;
static #privateField = 0;
static get #privateStaticFieldValue() {
return Cl.#PRIVATE_STATIC_FIELD;
static get #privateFieldValue() {
return this.#privateField;
}
static setPrivateStaticFieldValue() {
Cl.#privateStaticFieldValue = 1;
constructor() {
Cl.#privateFieldValue = 1;
([Cl.#privateFieldValue] = [1]);
}
}
const cl = new Cl();

View File

@ -1,23 +1,25 @@
var _PRIVATE_STATIC_FIELD = babelHelpers.classPrivateFieldLooseKey("PRIVATE_STATIC_FIELD");
var _privateField = babelHelpers.classPrivateFieldLooseKey("privateField");
var _privateStaticFieldValue = babelHelpers.classPrivateFieldLooseKey("privateStaticFieldValue");
var _privateFieldValue = babelHelpers.classPrivateFieldLooseKey("privateFieldValue");
class Cl {
static setPrivateStaticFieldValue() {
babelHelpers.classPrivateFieldLooseBase(Cl, _privateStaticFieldValue)[_privateStaticFieldValue] = 1;
constructor() {
babelHelpers.classPrivateFieldLooseBase(Cl, _privateFieldValue)[_privateFieldValue] = 1;
[babelHelpers.classPrivateFieldLooseBase(Cl, _privateFieldValue)[_privateFieldValue]] = [1];
}
}
var _get_privateStaticFieldValue = function () {
return babelHelpers.classPrivateFieldLooseBase(Cl, _PRIVATE_STATIC_FIELD)[_PRIVATE_STATIC_FIELD];
var _get_privateFieldValue = function () {
return babelHelpers.classPrivateFieldLooseBase(this, _privateField)[_privateField];
};
Object.defineProperty(Cl, _PRIVATE_STATIC_FIELD, {
Object.defineProperty(Cl, _privateField, {
writable: true,
value: 0
});
Object.defineProperty(Cl, _privateStaticFieldValue, {
get: _get_privateStaticFieldValue,
Object.defineProperty(Cl, _privateFieldValue, {
get: _get_privateFieldValue,
set: void 0
});
const cl = new Cl();

View File

@ -0,0 +1,10 @@
class C {
static set #p(v) { C.#q = v }
static #q;
constructor() {
([C.#p] = [0]);
expect(C.#q).toBe(0);
}
}
new C;

View File

@ -0,0 +1,9 @@
class C {
static set #p(v) { C.#q = v }
static #q;
constructor() {
([C.#p] = [0]);
}
}
new C;

View File

@ -0,0 +1,20 @@
class C {
constructor() {
[babelHelpers.classStaticPrivateFieldDestructureSet(C, C, _p).value] = [0];
}
}
var _set_p = function (v) {
babelHelpers.classStaticPrivateFieldSpecSet(C, C, _q, v);
};
var _p = {
get: void 0,
set: _set_p
};
var _q = {
writable: true,
value: void 0
};
new C();

View File

@ -1,13 +1,14 @@
class Cl {
static #PRIVATE_STATIC_FIELD = 0;
static #privateField = 0;
static get #privateStaticFieldValue() {
return Cl.#PRIVATE_STATIC_FIELD;
static get #privateFieldValue() {
return this.#privateField;
}
static setPrivateStaticFieldValue() {
Cl.#privateStaticFieldValue = 1;
constructor() {
expect(() => Cl.#privateFieldValue = 1).toThrow(TypeError);
expect(() => ([Cl.#privateFieldValue] = [1])).toThrow(TypeError);
}
}
expect(() => Cl.setPrivateStaticFieldValue()).toThrow(TypeError);
const cl = new Cl();

View File

@ -1,11 +1,15 @@
class Cl {
static #PRIVATE_STATIC_FIELD = 0;
static #privateField = 0;
static get #privateStaticFieldValue() {
return Cl.#PRIVATE_STATIC_FIELD;
static get #privateFieldValue() {
return this.#privateField;
}
static setPrivateStaticFieldValue() {
Cl.#privateStaticFieldValue = 1;
constructor() {
Cl.#privateFieldValue = 1;
([Cl.#privateFieldValue] = [1]);
}
}
const cl = new Cl();

View File

@ -1,19 +1,21 @@
class Cl {
static setPrivateStaticFieldValue() {
babelHelpers.classStaticPrivateFieldSpecSet(Cl, Cl, _privateStaticFieldValue, 1);
constructor() {
babelHelpers.classStaticPrivateFieldSpecSet(Cl, Cl, _privateFieldValue, 1);
[babelHelpers.classStaticPrivateFieldDestructureSet(Cl, Cl, _privateFieldValue).value] = [1];
}
}
var _get_privateStaticFieldValue = function () {
return babelHelpers.classStaticPrivateFieldSpecGet(Cl, Cl, _PRIVATE_STATIC_FIELD);
var _get_privateFieldValue = function () {
return babelHelpers.classStaticPrivateFieldSpecGet(this, Cl, _privateField);
};
var _PRIVATE_STATIC_FIELD = {
var _privateField = {
writable: true,
value: 0
};
var _privateStaticFieldValue = {
get: _get_privateStaticFieldValue,
var _privateFieldValue = {
get: _get_privateFieldValue,
set: void 0
};
var cl = new Cl();