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:
parent
70c77e550c
commit
bdb207cb75
7
.github/workflows/release.yml
vendored
7
.github/workflows/release.yml
vendored
@ -49,7 +49,9 @@ jobs:
|
|||||||
git config user.email "babel-bot@users.noreply.github.com"
|
git config user.email "babel-bot@users.noreply.github.com"
|
||||||
|
|
||||||
- name: Create new version
|
- 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
|
- name: Push to GitHub
|
||||||
id: push
|
id: push
|
||||||
@ -167,5 +169,4 @@ jobs:
|
|||||||
|
|
||||||
- name: Delete temporary branch from GitHub
|
- name: Delete temporary branch from GitHub
|
||||||
if: needs.git-version.result == 'success'
|
if: needs.git-version.result == 'success'
|
||||||
run:
|
run: git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" :${{ needs.git-version.outputs.branch }}
|
||||||
git push "https://babel-bot:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" :${{ needs.git-version.outputs.branch }}
|
|
||||||
|
|||||||
14
Makefile
14
Makefile
@ -195,7 +195,21 @@ prepublish:
|
|||||||
$(MAKE) prepublish-build
|
$(MAKE) prepublish-build
|
||||||
IS_PUBLISH=true $(MAKE) test
|
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:
|
new-version:
|
||||||
|
$(MAKE) new-version-checklist
|
||||||
git pull --rebase
|
git pull --rebase
|
||||||
$(YARN) release-tool version -f @babel/standalone
|
$(YARN) release-tool version -f @babel/standalone
|
||||||
|
|
||||||
|
|||||||
@ -318,9 +318,30 @@ const privateNameHandlerSpec = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
destructureSet(member) {
|
destructureSet(member) {
|
||||||
const { privateNamesMap, file } = this;
|
const { classRef, privateNamesMap, file } = this;
|
||||||
const { name } = member.node.property.id;
|
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(
|
return t.memberExpression(
|
||||||
t.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [
|
t.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [
|
||||||
this.receiver(member),
|
this.receiver(member),
|
||||||
|
|||||||
@ -1299,11 +1299,81 @@ helpers.classPrivateFieldLooseBase = helper("7.0.0-beta.0")`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
helpers.classPrivateFieldGet = 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) {
|
export default function _classPrivateFieldGet(receiver, privateMap) {
|
||||||
var descriptor = privateMap.get(receiver);
|
var descriptor = classExtractFieldDescriptor(receiver, privateMap, "get");
|
||||||
if (!descriptor) {
|
return classApplyDescriptorGet(receiver, descriptor);
|
||||||
throw new TypeError("attempted to get private field on non-instance");
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
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) {
|
if (descriptor.get) {
|
||||||
return descriptor.get.call(receiver);
|
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")`
|
helpers.classApplyDescriptorSet = helper("7.99.0")`
|
||||||
export default function _classPrivateFieldSet(receiver, privateMap, value) {
|
export default function _classApplyDescriptorSet(receiver, descriptor, value) {
|
||||||
var descriptor = privateMap.get(receiver);
|
|
||||||
if (!descriptor) {
|
|
||||||
throw new TypeError("attempted to set private field on non-instance");
|
|
||||||
}
|
|
||||||
if (descriptor.set) {
|
if (descriptor.set) {
|
||||||
descriptor.set.call(receiver, value);
|
descriptor.set.call(receiver, value);
|
||||||
} else {
|
} else {
|
||||||
@ -1326,23 +1392,13 @@ helpers.classPrivateFieldSet = helper("7.0.0-beta.0")`
|
|||||||
// class bodies.
|
// class bodies.
|
||||||
throw new TypeError("attempted to set read only private field");
|
throw new TypeError("attempted to set read only private field");
|
||||||
}
|
}
|
||||||
|
|
||||||
descriptor.value = value;
|
descriptor.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
helpers.classPrivateFieldDestructureSet = helper("7.4.4")`
|
helpers.classApplyDescriptorDestructureSet = helper("7.99.0")`
|
||||||
export default function _classPrivateFieldDestructureSet(receiver, privateMap) {
|
export default function _classApplyDescriptorDestructureSet(receiver, descriptor) {
|
||||||
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);
|
|
||||||
if (descriptor.set) {
|
if (descriptor.set) {
|
||||||
if (!("__destrObj" in descriptor)) {
|
if (!("__destrObj" in descriptor)) {
|
||||||
descriptor.__destrObj = {
|
descriptor.__destrObj = {
|
||||||
@ -1365,57 +1421,30 @@ helpers.classPrivateFieldDestructureSet = helper("7.4.4")`
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
helpers.classStaticPrivateFieldSpecGet = helper("7.0.2")`
|
helpers.classStaticPrivateFieldDestructureSet = helper("7.99.0")`
|
||||||
export default function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
|
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) {
|
if (receiver !== classConstructor) {
|
||||||
throw new TypeError("Private static access of wrong provenance");
|
throw new TypeError("Private static access of wrong provenance");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
helpers.classCheckPrivateStaticFieldDescriptor = helper("7.99.0")`
|
||||||
|
export default function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {
|
||||||
if (descriptor === undefined) {
|
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");
|
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
};
|
||||||
@ -7,6 +7,7 @@ class Cl {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
expect(() => this.#privateFieldValue = 1).toThrow(TypeError);
|
expect(() => this.#privateFieldValue = 1).toThrow(TypeError);
|
||||||
|
expect(() => ([this.#privateFieldValue] = [1])).toThrow(TypeError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,5 +7,6 @@ class Cl {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.#privateFieldValue = 1;
|
this.#privateFieldValue = 1;
|
||||||
|
([this.#privateFieldValue] = [1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class Cl {
|
|||||||
value: 0
|
value: 0
|
||||||
});
|
});
|
||||||
babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue] = 1;
|
babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue] = 1;
|
||||||
|
[babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue]] = [1];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ class Cl {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
expect(() => this.#privateFieldValue = 1).toThrow(TypeError);
|
expect(() => this.#privateFieldValue = 1).toThrow(TypeError);
|
||||||
|
expect(() => ([this.#privateFieldValue] = [1])).toThrow(TypeError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,5 +7,6 @@ class Cl {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.#privateFieldValue = 1;
|
this.#privateFieldValue = 1;
|
||||||
|
([this.#privateFieldValue] = [1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class Cl {
|
|||||||
value: 0
|
value: 0
|
||||||
});
|
});
|
||||||
babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue] = 1;
|
babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue] = 1;
|
||||||
|
[babelHelpers.classPrivateFieldLooseBase(this, _privateFieldValue)[_privateFieldValue]] = [1];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,8 @@ class Cl {
|
|||||||
constructor() {
|
constructor() {
|
||||||
expect(() => this.self.#privateFieldValue = 1).toThrow(TypeError);
|
expect(() => this.self.#privateFieldValue = 1).toThrow(TypeError);
|
||||||
expect(this.counter).toBe(1);
|
expect(this.counter).toBe(1);
|
||||||
|
expect(() => ([this.self.#privateFieldValue] = [1])).toThrow(TypeError);
|
||||||
|
expect(this.counter).toBe(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ class Cl {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.self.#privateFieldValue = 1
|
this.self.#privateFieldValue = 1
|
||||||
|
([this.self.#privateFieldValue] = [1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@ class Cl {
|
|||||||
});
|
});
|
||||||
|
|
||||||
babelHelpers.defineProperty(this, "counter", 0);
|
babelHelpers.defineProperty(this, "counter", 0);
|
||||||
this.self, 1, babelHelpers.readOnlyError("#privateFieldValue");
|
this.self, 1([babelHelpers.classPrivateFieldDestructureSet(this.self, _privateFieldValue).value] = [1]), babelHelpers.readOnlyError("#privateFieldValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ class A {
|
|||||||
constructor() {
|
constructor() {
|
||||||
expect(() => this.self().#method = 2).toThrow(TypeError);
|
expect(() => this.self().#method = 2).toThrow(TypeError);
|
||||||
expect(this.counter).toBe(1);
|
expect(this.counter).toBe(1);
|
||||||
|
expect(() => ([this.#method] = [2])).toThrow(TypeError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,5 +8,6 @@ class A {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.self().#method = 2;
|
this.self().#method = 2;
|
||||||
|
([this.#method] = [2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,6 +11,7 @@ class A {
|
|||||||
|
|
||||||
babelHelpers.defineProperty(this, "counter", 0);
|
babelHelpers.defineProperty(this, "counter", 0);
|
||||||
this.self(), 2, babelHelpers.readOnlyError("#method");
|
this.self(), 2, babelHelpers.readOnlyError("#method");
|
||||||
|
[babelHelpers.classPrivateFieldDestructureSet(this, _method).value] = [2];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,10 @@
|
|||||||
|
class A {
|
||||||
|
static #method() {}
|
||||||
|
|
||||||
|
run() {
|
||||||
|
expect(() => A.#method = 2).toThrow(TypeError);
|
||||||
|
expect(() => ([A.#method] = [2])).toThrow(TypeError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,8 @@
|
|||||||
|
class A {
|
||||||
|
static #method() {}
|
||||||
|
|
||||||
|
run() {
|
||||||
|
A.#method = 2;
|
||||||
|
([A.#method] = [2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class A {
|
||||||
|
run() {
|
||||||
|
babelHelpers.classStaticPrivateMethodSet(A, A, _method, 2);
|
||||||
|
[babelHelpers.classStaticPrivateFieldDestructureSet(A, A, _method).value] = [2];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
var _method = function _method() {};
|
||||||
@ -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;
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class C {
|
||||||
|
static set #p(v) { C.#q = v }
|
||||||
|
static #q;
|
||||||
|
constructor() {
|
||||||
|
([C.#p] = [0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new C;
|
||||||
@ -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();
|
||||||
@ -1,13 +1,14 @@
|
|||||||
class Cl {
|
class Cl {
|
||||||
static #PRIVATE_STATIC_FIELD = 0;
|
static #privateField = 0;
|
||||||
|
|
||||||
static get #privateStaticFieldValue() {
|
static get #privateFieldValue() {
|
||||||
return Cl.#PRIVATE_STATIC_FIELD;
|
return this.#privateField;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
Cl.#privateStaticFieldValue = 1;
|
expect(() => Cl.#privateFieldValue = 1).toThrow(TypeError);
|
||||||
|
expect(() => ([Cl.#privateFieldValue] = [1])).toThrow(TypeError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(() => Cl.setPrivateStaticFieldValue()).toThrow(TypeError);
|
const cl = new Cl();
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
class Cl {
|
class Cl {
|
||||||
static #PRIVATE_STATIC_FIELD = 0;
|
static #privateField = 0;
|
||||||
|
|
||||||
static get #privateStaticFieldValue() {
|
static get #privateFieldValue() {
|
||||||
return Cl.#PRIVATE_STATIC_FIELD;
|
return this.#privateField;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
Cl.#privateStaticFieldValue = 1;
|
Cl.#privateFieldValue = 1;
|
||||||
|
([Cl.#privateFieldValue] = [1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cl = new Cl();
|
||||||
|
|
||||||
|
|||||||
@ -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 {
|
class Cl {
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
babelHelpers.classPrivateFieldLooseBase(Cl, _privateStaticFieldValue)[_privateStaticFieldValue] = 1;
|
babelHelpers.classPrivateFieldLooseBase(Cl, _privateFieldValue)[_privateFieldValue] = 1;
|
||||||
|
[babelHelpers.classPrivateFieldLooseBase(Cl, _privateFieldValue)[_privateFieldValue]] = [1];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _get_privateStaticFieldValue = function () {
|
var _get_privateFieldValue = function () {
|
||||||
return babelHelpers.classPrivateFieldLooseBase(Cl, _PRIVATE_STATIC_FIELD)[_PRIVATE_STATIC_FIELD];
|
return babelHelpers.classPrivateFieldLooseBase(this, _privateField)[_privateField];
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperty(Cl, _PRIVATE_STATIC_FIELD, {
|
Object.defineProperty(Cl, _privateField, {
|
||||||
writable: true,
|
writable: true,
|
||||||
value: 0
|
value: 0
|
||||||
});
|
});
|
||||||
Object.defineProperty(Cl, _privateStaticFieldValue, {
|
Object.defineProperty(Cl, _privateFieldValue, {
|
||||||
get: _get_privateStaticFieldValue,
|
get: _get_privateFieldValue,
|
||||||
set: void 0
|
set: void 0
|
||||||
});
|
});
|
||||||
|
var cl = new Cl();
|
||||||
|
|||||||
@ -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;
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class C {
|
||||||
|
static set #p(v) { C.#q = v }
|
||||||
|
static #q;
|
||||||
|
constructor() {
|
||||||
|
([C.#p] = [0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new C;
|
||||||
@ -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();
|
||||||
@ -1,13 +1,14 @@
|
|||||||
class Cl {
|
class Cl {
|
||||||
static #PRIVATE_STATIC_FIELD = 0;
|
static #privateField = 0;
|
||||||
|
|
||||||
static get #privateStaticFieldValue() {
|
static get #privateFieldValue() {
|
||||||
return Cl.#PRIVATE_STATIC_FIELD;
|
return this.#privateField;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
Cl.#privateStaticFieldValue = 1;
|
expect(() => Cl.#privateFieldValue = 1).toThrow(TypeError);
|
||||||
|
expect(() => ([Cl.#privateFieldValue] = [1])).toThrow(TypeError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(() => Cl.setPrivateStaticFieldValue()).toThrow(TypeError);
|
const cl = new Cl();
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
class Cl {
|
class Cl {
|
||||||
static #PRIVATE_STATIC_FIELD = 0;
|
static #privateField = 0;
|
||||||
|
|
||||||
static get #privateStaticFieldValue() {
|
static get #privateFieldValue() {
|
||||||
return Cl.#PRIVATE_STATIC_FIELD;
|
return this.#privateField;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
Cl.#privateStaticFieldValue = 1;
|
Cl.#privateFieldValue = 1;
|
||||||
|
([Cl.#privateFieldValue] = [1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cl = new Cl();
|
||||||
|
|
||||||
|
|||||||
@ -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 {
|
class Cl {
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
babelHelpers.classPrivateFieldLooseBase(Cl, _privateStaticFieldValue)[_privateStaticFieldValue] = 1;
|
babelHelpers.classPrivateFieldLooseBase(Cl, _privateFieldValue)[_privateFieldValue] = 1;
|
||||||
|
[babelHelpers.classPrivateFieldLooseBase(Cl, _privateFieldValue)[_privateFieldValue]] = [1];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _get_privateStaticFieldValue = function () {
|
var _get_privateFieldValue = function () {
|
||||||
return babelHelpers.classPrivateFieldLooseBase(Cl, _PRIVATE_STATIC_FIELD)[_PRIVATE_STATIC_FIELD];
|
return babelHelpers.classPrivateFieldLooseBase(this, _privateField)[_privateField];
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.defineProperty(Cl, _PRIVATE_STATIC_FIELD, {
|
Object.defineProperty(Cl, _privateField, {
|
||||||
writable: true,
|
writable: true,
|
||||||
value: 0
|
value: 0
|
||||||
});
|
});
|
||||||
Object.defineProperty(Cl, _privateStaticFieldValue, {
|
Object.defineProperty(Cl, _privateFieldValue, {
|
||||||
get: _get_privateStaticFieldValue,
|
get: _get_privateFieldValue,
|
||||||
set: void 0
|
set: void 0
|
||||||
});
|
});
|
||||||
|
const cl = new Cl();
|
||||||
|
|||||||
@ -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;
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
class C {
|
||||||
|
static set #p(v) { C.#q = v }
|
||||||
|
static #q;
|
||||||
|
constructor() {
|
||||||
|
([C.#p] = [0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
new C;
|
||||||
@ -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();
|
||||||
@ -1,13 +1,14 @@
|
|||||||
class Cl {
|
class Cl {
|
||||||
static #PRIVATE_STATIC_FIELD = 0;
|
static #privateField = 0;
|
||||||
|
|
||||||
static get #privateStaticFieldValue() {
|
static get #privateFieldValue() {
|
||||||
return Cl.#PRIVATE_STATIC_FIELD;
|
return this.#privateField;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
Cl.#privateStaticFieldValue = 1;
|
expect(() => Cl.#privateFieldValue = 1).toThrow(TypeError);
|
||||||
|
expect(() => ([Cl.#privateFieldValue] = [1])).toThrow(TypeError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(() => Cl.setPrivateStaticFieldValue()).toThrow(TypeError);
|
const cl = new Cl();
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
class Cl {
|
class Cl {
|
||||||
static #PRIVATE_STATIC_FIELD = 0;
|
static #privateField = 0;
|
||||||
|
|
||||||
static get #privateStaticFieldValue() {
|
static get #privateFieldValue() {
|
||||||
return Cl.#PRIVATE_STATIC_FIELD;
|
return this.#privateField;
|
||||||
}
|
}
|
||||||
|
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
Cl.#privateStaticFieldValue = 1;
|
Cl.#privateFieldValue = 1;
|
||||||
|
([Cl.#privateFieldValue] = [1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cl = new Cl();
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,21 @@
|
|||||||
class Cl {
|
class Cl {
|
||||||
static setPrivateStaticFieldValue() {
|
constructor() {
|
||||||
babelHelpers.classStaticPrivateFieldSpecSet(Cl, Cl, _privateStaticFieldValue, 1);
|
babelHelpers.classStaticPrivateFieldSpecSet(Cl, Cl, _privateFieldValue, 1);
|
||||||
|
[babelHelpers.classStaticPrivateFieldDestructureSet(Cl, Cl, _privateFieldValue).value] = [1];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _get_privateStaticFieldValue = function () {
|
var _get_privateFieldValue = function () {
|
||||||
return babelHelpers.classStaticPrivateFieldSpecGet(Cl, Cl, _PRIVATE_STATIC_FIELD);
|
return babelHelpers.classStaticPrivateFieldSpecGet(this, Cl, _privateField);
|
||||||
};
|
};
|
||||||
|
|
||||||
var _PRIVATE_STATIC_FIELD = {
|
var _privateField = {
|
||||||
writable: true,
|
writable: true,
|
||||||
value: 0
|
value: 0
|
||||||
};
|
};
|
||||||
var _privateStaticFieldValue = {
|
var _privateFieldValue = {
|
||||||
get: _get_privateStaticFieldValue,
|
get: _get_privateFieldValue,
|
||||||
set: void 0
|
set: void 0
|
||||||
};
|
};
|
||||||
|
var cl = new Cl();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user