From d9092422be8a2041bd4b65869b3e8f7ed789d699 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 19 Jul 2021 11:33:56 -0300 Subject: [PATCH 01/30] Reproduced error for member properties --- .../fixtures/field-reinitialization/exec.js | 25 +++++++++++++++++++ .../fixtures/field-reinitialization/input.js | 13 ++++++++++ .../field-reinitialization/options.json | 7 ++++++ 3 files changed, 45 insertions(+) create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/exec.js create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/input.js create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/options.json diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/exec.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/exec.js new file mode 100644 index 000000000000..cda2dab35e9b --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/exec.js @@ -0,0 +1,25 @@ +import { assert } from "console"; + +class Base { + constructor(obj) { + return obj; + } +} + +let counter = 1; +class Derived extends Base { + #field = counter; + static get(obj) { + return obj.#field; + } +} + +const obj = {}; +new Derived(obj); +assert.equals(Derived.get(obj), 1); + +assert.throws(() => { + new Derived(obj); +}); + +assert.equals(Derived.get(foo), 1); diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/input.js new file mode 100644 index 000000000000..0c40f7d25cd5 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/input.js @@ -0,0 +1,13 @@ +class Base { + constructor(obj) { + return obj; + } +} + +let counter = 1; +class Derived extends Base { + #field = counter; + static get(obj) { + return obj.#field; + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/options.json new file mode 100644 index 000000000000..153fb2cbff96 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/options.json @@ -0,0 +1,7 @@ +{ + "shippedProposals": true, + "targets": { + "chrome": "75" + }, + "throws": "Error" +} From 5d643ddff888bdb698bbb6943b44beb74f48f1cc Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 26 Jul 2021 13:07:52 -0300 Subject: [PATCH 02/30] Fixed tests --- .../fixtures/field-reinitialization/exec.js | 25 --------- .../field-reinitialization/options.json | 7 --- .../{ => private-field}/input.js | 6 +- .../private-field/options.json | 6 ++ .../private-field/output.js | 55 +++++++++++++++++++ 5 files changed, 64 insertions(+), 35 deletions(-) delete mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/exec.js delete mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/options.json rename packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/{ => private-field}/input.js (65%) create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/options.json create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/exec.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/exec.js deleted file mode 100644 index cda2dab35e9b..000000000000 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/exec.js +++ /dev/null @@ -1,25 +0,0 @@ -import { assert } from "console"; - -class Base { - constructor(obj) { - return obj; - } -} - -let counter = 1; -class Derived extends Base { - #field = counter; - static get(obj) { - return obj.#field; - } -} - -const obj = {}; -new Derived(obj); -assert.equals(Derived.get(obj), 1); - -assert.throws(() => { - new Derived(obj); -}); - -assert.equals(Derived.get(foo), 1); diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/options.json deleted file mode 100644 index 153fb2cbff96..000000000000 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/options.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "shippedProposals": true, - "targets": { - "chrome": "75" - }, - "throws": "Error" -} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/input.js similarity index 65% rename from packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/input.js rename to packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/input.js index 0c40f7d25cd5..902695e4e932 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/input.js +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/input.js @@ -4,10 +4,10 @@ class Base { } } -let counter = 1; +let counter = 0; class Derived extends Base { - #field = counter; + #foo = ++counter; static get(obj) { - return obj.#field; + return obj.#foo; } } diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/options.json new file mode 100644 index 000000000000..608f30af0eb3 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/options.json @@ -0,0 +1,6 @@ +{ + "presets": [["env", { "shippedProposals": true }]], + "targets": { + "chrome": "75" + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js new file mode 100644 index 000000000000..032643df198e --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js @@ -0,0 +1,55 @@ +'use strict'; + +function _classPrivateFieldGet(receiver, privateMap) { + var descriptor = _classExtractFieldDescriptor(receiver, privateMap, 'get'); + return _classApplyDescriptorGet(receiver, descriptor); +} + +function _classExtractFieldDescriptor(receiver, privateMap, action) { + if (!privateMap.has(receiver)) { + throw new TypeError( + 'attempted to ' + action + ' private field on non-instance' + ); + } + return privateMap.get(receiver); +} + +function _classApplyDescriptorGet(receiver, descriptor) { + if (descriptor.get) { + return descriptor.get.call(receiver); + } + return descriptor.value; +} + +function _checkPrivateFieldInitSpec(obj, privateMap) { + if (privateMap.has(obj)) { + throw new TypeError(); + } +} + +class Base { + constructor(obj) { + return obj; + } + +} + +let counter = 0; + +var _foo = /*#__PURE__*/new WeakMap(); + +class Derived extends Base { + constructor(...args) { + super(...args); + + _checkPrivateFieldInitSpec(this, _foo); + _foo.set(this, { + writable: true, + value: ++counter + }); + } + + static get(obj) { + return babelHelpers._classPrivateFieldGet(obj, _foo); + } +} \ No newline at end of file From 53e82d88289ae5911568996cf050eadce1f076f5 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 26 Jul 2021 19:25:01 -0300 Subject: [PATCH 03/30] Added private fields check --- .../src/fields.ts | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 29e94d746ef9..800ac9183214 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -449,16 +449,26 @@ function buildPrivateFieldInitLoose(ref, prop, privateNamesMap) { `; } +function buildPrivateInstaceFieldCheckInitSpec(ref, prop, privateNamesMap) { + const { id } = privateNamesMap.get(prop.node.key.id.name); + const newNode = t.cloneNode(id); + + return template.statement + .ast`_checkPrivateFieldInitSpec(${ref}, ${newNode});`; +} + function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap) { const { id } = privateNamesMap.get(prop.node.key.id.name); const value = prop.node.value || prop.scope.buildUndefinedNode(); + const newNode = t.cloneNode(id); - return template.statement.ast`${t.cloneNode(id)}.set(${ref}, { - // configurable is always false for private elements - // enumerable is always false for private elements - writable: true, - value: ${value}, - })`; + return template.statement.ast` + ${newNode}.set(${ref}, { + // configurable is always false for private elements + // enumerable is always false for private elements + writable: true, + value: ${value}, + })`; } function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) { @@ -804,6 +814,13 @@ export function buildFieldsInitNodes( ); break; case isInstance && isPrivate && isField && !privateFieldsAsProperties: + instanceNodes.push( + buildPrivateInstaceFieldCheckInitSpec( + t.thisExpression(), + prop, + privateNamesMap, + ), + ); instanceNodes.push( buildPrivateInstanceFieldInitSpec( t.thisExpression(), From 9ecbcf3483554a3380a964d92465c41118e68397 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 28 Jul 2021 08:22:37 -0300 Subject: [PATCH 04/30] Updated field initializtion --- .../src/fields.ts | 20 +++---------------- .../private-field/output.js | 5 ++--- packages/babel-helpers/src/helpers.js | 8 ++++++++ 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 800ac9183214..34d40f2ca84f 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -449,26 +449,19 @@ function buildPrivateFieldInitLoose(ref, prop, privateNamesMap) { `; } -function buildPrivateInstaceFieldCheckInitSpec(ref, prop, privateNamesMap) { - const { id } = privateNamesMap.get(prop.node.key.id.name); - const newNode = t.cloneNode(id); - - return template.statement - .ast`_checkPrivateFieldInitSpec(${ref}, ${newNode});`; -} - function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap) { const { id } = privateNamesMap.get(prop.node.key.id.name); const value = prop.node.value || prop.scope.buildUndefinedNode(); const newNode = t.cloneNode(id); return template.statement.ast` - ${newNode}.set(${ref}, { + _privateFieldInitSpec(${ref}, ${newNode}, { // configurable is always false for private elements // enumerable is always false for private elements writable: true, value: ${value}, - })`; + }); + `; } function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) { @@ -814,13 +807,6 @@ export function buildFieldsInitNodes( ); break; case isInstance && isPrivate && isField && !privateFieldsAsProperties: - instanceNodes.push( - buildPrivateInstaceFieldCheckInitSpec( - t.thisExpression(), - prop, - privateNamesMap, - ), - ); instanceNodes.push( buildPrivateInstanceFieldInitSpec( t.thisExpression(), diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js index 032643df198e..20f0db15ed7c 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js @@ -42,10 +42,9 @@ class Derived extends Base { constructor(...args) { super(...args); - _checkPrivateFieldInitSpec(this, _foo); - _foo.set(this, { + _privateFieldInitSpec(this, _foo, { writable: true, - value: ++counter + value: ++counter, }); } diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index 4397c0f817bb..3b57ec6c5e35 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -1219,6 +1219,14 @@ helpers.classExtractFieldDescriptor = helper("7.13.10")` } `; +helpers.classCheckPrivateFieldInitSpec = helper("7.14.1")` + export default function _classCheckPrivateFieldInitSpec(obj, privateMap) { + if (privateMap.has(obj)) { + throw new TypeError("Identifier has already been declared"); + } + } +`; + helpers.classStaticPrivateFieldSpecGet = helper("7.0.2")` import classApplyDescriptorGet from "classApplyDescriptorGet"; import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess"; From 90f39e5f0f783e1bdf020700077d76836a892a2a Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 28 Jul 2021 08:29:08 -0300 Subject: [PATCH 05/30] Updated helpers --- packages/babel-helpers/src/helpers.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index 3b57ec6c5e35..f6acdb3921fb 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -1219,11 +1219,12 @@ helpers.classExtractFieldDescriptor = helper("7.13.10")` } `; -helpers.classCheckPrivateFieldInitSpec = helper("7.14.1")` - export default function _classCheckPrivateFieldInitSpec(obj, privateMap) { +helpers.classPrivateFieldInitSpec = helper("7.14.1")` + export default function _privateFieldInitSpec(obj, privateMap, value) { if (privateMap.has(obj)) { - throw new TypeError("Identifier has already been declared"); + throw new TypeError(); } + privateMap.set(obj, value); } `; From ce05c09420f3f4ad27439eb4ff3e7b9f869a60b9 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 30 Jul 2021 10:05:40 -0300 Subject: [PATCH 06/30] Added helper call --- .../src/fields.ts | 19 ++++++++++++++++--- packages/babel-helpers/src/helpers.js | 2 +- packages/babel-runtime-corejs2/package.json | 9 +++++++++ packages/babel-runtime-corejs3/package.json | 9 +++++++++ packages/babel-runtime/package.json | 9 +++++++++ 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 34d40f2ca84f..3136dcab0c12 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -449,11 +449,23 @@ function buildPrivateFieldInitLoose(ref, prop, privateNamesMap) { `; } -function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap) { +function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap, state) { const { id } = privateNamesMap.get(prop.node.key.id.name); const value = prop.node.value || prop.scope.buildUndefinedNode(); - const newNode = t.cloneNode(id); + const helper = state.addHelper("classPrivateFieldInitSpec"); + const expr = t.callExpression(helper, [ + t.thisExpression(), + t.cloneNode(id), + template.expression.ast`{ + writable: true, + value: ${value} + }`, + ]); + + return expr; + + /* return template.statement.ast` _privateFieldInitSpec(${ref}, ${newNode}, { // configurable is always false for private elements @@ -461,7 +473,7 @@ function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap) { writable: true, value: ${value}, }); - `; + `;*/ } function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) { @@ -812,6 +824,7 @@ export function buildFieldsInitNodes( t.thisExpression(), prop, privateNamesMap, + state, ), ); break; diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index f6acdb3921fb..bd017257c91f 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -1220,7 +1220,7 @@ helpers.classExtractFieldDescriptor = helper("7.13.10")` `; helpers.classPrivateFieldInitSpec = helper("7.14.1")` - export default function _privateFieldInitSpec(obj, privateMap, value) { + export default function _classPrivateFieldInitSpec(obj, privateMap, value) { if (privateMap.has(obj)) { throw new TypeError(); } diff --git a/packages/babel-runtime-corejs2/package.json b/packages/babel-runtime-corejs2/package.json index ac42b0603f8c..e385af6cfa40 100644 --- a/packages/babel-runtime-corejs2/package.json +++ b/packages/babel-runtime-corejs2/package.json @@ -693,6 +693,15 @@ "./helpers/classExtractFieldDescriptor.js" ], "./helpers/esm/classExtractFieldDescriptor": "./helpers/esm/classExtractFieldDescriptor.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", "./helpers/classStaticPrivateFieldSpecGet": [ { "node": "./helpers/classStaticPrivateFieldSpecGet.js", diff --git a/packages/babel-runtime-corejs3/package.json b/packages/babel-runtime-corejs3/package.json index 6bedcd959c8f..b2335f2b2bc1 100644 --- a/packages/babel-runtime-corejs3/package.json +++ b/packages/babel-runtime-corejs3/package.json @@ -692,6 +692,15 @@ "./helpers/classExtractFieldDescriptor.js" ], "./helpers/esm/classExtractFieldDescriptor": "./helpers/esm/classExtractFieldDescriptor.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", "./helpers/classStaticPrivateFieldSpecGet": [ { "node": "./helpers/classStaticPrivateFieldSpecGet.js", diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index 48a6c149fe62..ba00bb02e805 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -692,6 +692,15 @@ "./helpers/classExtractFieldDescriptor.js" ], "./helpers/esm/classExtractFieldDescriptor": "./helpers/esm/classExtractFieldDescriptor.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", "./helpers/classStaticPrivateFieldSpecGet": [ { "node": "./helpers/classStaticPrivateFieldSpecGet.js", From 06300db45d617986c85831fb3876a09bed87c9e2 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 30 Jul 2021 10:25:41 -0300 Subject: [PATCH 07/30] Fixed unit test --- .../private-field/output.js | 37 ++----------------- 1 file changed, 4 insertions(+), 33 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js index 20f0db15ed7c..59fe05cc06db 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-field/output.js @@ -1,32 +1,3 @@ -'use strict'; - -function _classPrivateFieldGet(receiver, privateMap) { - var descriptor = _classExtractFieldDescriptor(receiver, privateMap, 'get'); - return _classApplyDescriptorGet(receiver, descriptor); -} - -function _classExtractFieldDescriptor(receiver, privateMap, action) { - if (!privateMap.has(receiver)) { - throw new TypeError( - 'attempted to ' + action + ' private field on non-instance' - ); - } - return privateMap.get(receiver); -} - -function _classApplyDescriptorGet(receiver, descriptor) { - if (descriptor.get) { - return descriptor.get.call(receiver); - } - return descriptor.value; -} - -function _checkPrivateFieldInitSpec(obj, privateMap) { - if (privateMap.has(obj)) { - throw new TypeError(); - } -} - class Base { constructor(obj) { return obj; @@ -41,14 +12,14 @@ var _foo = /*#__PURE__*/new WeakMap(); class Derived extends Base { constructor(...args) { super(...args); - - _privateFieldInitSpec(this, _foo, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, - value: ++counter, + value: ++counter }); } static get(obj) { - return babelHelpers._classPrivateFieldGet(obj, _foo); + return babelHelpers.classPrivateFieldGet(obj, _foo); } + } \ No newline at end of file From 0f5a4e738198b8bc1e8c93c8fc08de0f6f94c156 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 2 Aug 2021 08:53:10 -0300 Subject: [PATCH 08/30] Removed commented code --- .../src/fields.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 3136dcab0c12..cabeeec81053 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -464,16 +464,6 @@ function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap, state) { ]); return expr; - - /* - return template.statement.ast` - _privateFieldInitSpec(${ref}, ${newNode}, { - // configurable is always false for private elements - // enumerable is always false for private elements - writable: true, - value: ${value}, - }); - `;*/ } function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) { From 086c12d547930e223960d4bb6275843e131827c3 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 2 Aug 2021 09:00:30 -0300 Subject: [PATCH 09/30] Handle unavailable helper --- .../src/fields.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index cabeeec81053..88a99fc6d3cb 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -453,6 +453,15 @@ function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap, state) { const { id } = privateNamesMap.get(prop.node.key.id.name); const value = prop.node.value || prop.scope.buildUndefinedNode(); + if (!state.availableHelper("classPrivateFieldInitSpec")) { + return template.statement.ast`${t.cloneNode(id)}.set(${ref}, { + // configurable is always false for private elements + // enumerable is always false for private elements + writable: true, + value: ${value}, + })`; + } + const helper = state.addHelper("classPrivateFieldInitSpec"); const expr = t.callExpression(helper, [ t.thisExpression(), From a975111f2ac35a96fe4e47a28b2e3b3466f54d01 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 2 Aug 2021 09:24:26 -0300 Subject: [PATCH 10/30] Updated error statement --- packages/babel-helpers/src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index bd017257c91f..299dd5ce2637 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -1222,7 +1222,7 @@ helpers.classExtractFieldDescriptor = helper("7.13.10")` helpers.classPrivateFieldInitSpec = helper("7.14.1")` export default function _classPrivateFieldInitSpec(obj, privateMap, value) { if (privateMap.has(obj)) { - throw new TypeError(); + throw new TypeError("the Identifier " + Object.keys({ privateMap }).pop() + " has already been declared"); } privateMap.set(obj, value); } From 454c2cc78922435058da12bb4935d0f60ca0c19b Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 2 Aug 2021 09:34:09 -0300 Subject: [PATCH 11/30] Updated error text --- packages/babel-helpers/src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index 299dd5ce2637..8e45ee15f39f 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -1222,7 +1222,7 @@ helpers.classExtractFieldDescriptor = helper("7.13.10")` helpers.classPrivateFieldInitSpec = helper("7.14.1")` export default function _classPrivateFieldInitSpec(obj, privateMap, value) { if (privateMap.has(obj)) { - throw new TypeError("the Identifier " + Object.keys({ privateMap }).pop() + " has already been declared"); + throw new TypeError("redeclared identifier"); } privateMap.set(obj, value); } From dbc25c4676ebad75b2d0a608bcb34904f6f30453 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 2 Aug 2021 10:06:32 -0300 Subject: [PATCH 12/30] Added private method helper --- .../src/fields.ts | 12 +++++++-- .../private-method/input.js | 15 +++++++++++ .../private-method/options.json | 6 +++++ .../private-method/output.js | 24 +++++++++++++++++ packages/babel-helpers/src/helpers.js | 27 ++++++++++++------- packages/babel-runtime-corejs2/package.json | 27 ++++++++++++------- packages/babel-runtime-corejs3/package.json | 27 ++++++++++++------- packages/babel-runtime/package.json | 27 ++++++++++++------- 8 files changed, 127 insertions(+), 38 deletions(-) create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/input.js create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/options.json create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 88a99fc6d3cb..4237931b829e 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -544,7 +544,7 @@ function buildPrivateMethodInitLoose(ref, prop, privateNamesMap) { } } -function buildPrivateInstanceMethodInitSpec(ref, prop, privateNamesMap) { +function buildPrivateInstanceMethodInitSpec(ref, prop, privateNamesMap, state) { const privateName = privateNamesMap.get(prop.node.key.id.name); const { id, getId, setId, initAdded } = privateName; @@ -564,7 +564,14 @@ function buildPrivateInstanceMethodInitSpec(ref, prop, privateNamesMap) { }); `; } - return template.statement.ast`${id}.add(${ref})`; + + if (!state.availableHelper("classPrivateMethodInitSpec")) { + template.statement.ast`${id}.add(${ref})`; + } + + const helper = state.addHelper("classPrivateMethodInitSpec"); + const expr = t.callExpression(helper, [t.thisExpression(), t.cloneNode(id)]); + return expr; } function buildPublicFieldInitLoose(ref, prop) { @@ -849,6 +856,7 @@ export function buildFieldsInitNodes( t.thisExpression(), prop, privateNamesMap, + state, ), ); pureStaticNodes.push( diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/input.js new file mode 100644 index 000000000000..1d6529040694 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/input.js @@ -0,0 +1,15 @@ +class Base { + constructor(obj) { + return obj; + } +} + +class Derived extends Base { + #foo() { + return 'bar'; + } + + static get(obj) { + return obj.#foo(); + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/options.json new file mode 100644 index 000000000000..608f30af0eb3 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/options.json @@ -0,0 +1,6 @@ +{ + "presets": [["env", { "shippedProposals": true }]], + "targets": { + "chrome": "75" + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js new file mode 100644 index 000000000000..006ac80fa27c --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js @@ -0,0 +1,24 @@ +class Base { + constructor(obj) { + return obj; + } + +} + +var _foo = /*#__PURE__*/ new WeakSet(); + +class Derived extends Base { + constructor(...args) { + super(...args); + babelHelpers.classPrivateMethodInitSpec(this, _foo); + } + + static get(obj) { + return _classPrivateMethodGet(obj, _foo, _foo2).call(obj); + } + +} + +function _foo2() { + return "bar"; +} \ No newline at end of file diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index 8e45ee15f39f..1f8c6b9b7c13 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -1219,15 +1219,6 @@ helpers.classExtractFieldDescriptor = helper("7.13.10")` } `; -helpers.classPrivateFieldInitSpec = helper("7.14.1")` - export default function _classPrivateFieldInitSpec(obj, privateMap, value) { - if (privateMap.has(obj)) { - throw new TypeError("redeclared identifier"); - } - privateMap.set(obj, value); - } -`; - helpers.classStaticPrivateFieldSpecGet = helper("7.0.2")` import classApplyDescriptorGet from "classApplyDescriptorGet"; import classCheckPrivateStaticAccess from "classCheckPrivateStaticAccess"; @@ -2024,6 +2015,24 @@ helpers.classPrivateMethodGet = helper("7.1.6")` } `; +helpers.classPrivateFieldInitSpec = helper("7.14.1")` + export default function _classPrivateFieldInitSpec(obj, privateMap, value) { + if (privateMap.has(obj)) { + throw new TypeError("redeclared private field identifier"); + } + privateMap.set(obj, value); + } +`; + +helpers.classPrivateMethodInitSpec = helper("7.14.1")` + export default function _classPrivateMethodInitSpec(obj, privateSet) { + if (privateSet.has(obj)) { + throw new TypeError("redeclared private method identifier"); + } + privateSet.add(obj); + } +`; + if (!process.env.BABEL_8_BREAKING) { // Use readOnlyError instead helpers.classPrivateMethodSet = helper("7.1.6")` diff --git a/packages/babel-runtime-corejs2/package.json b/packages/babel-runtime-corejs2/package.json index e385af6cfa40..2aff1f0b1586 100644 --- a/packages/babel-runtime-corejs2/package.json +++ b/packages/babel-runtime-corejs2/package.json @@ -693,15 +693,6 @@ "./helpers/classExtractFieldDescriptor.js" ], "./helpers/esm/classExtractFieldDescriptor": "./helpers/esm/classExtractFieldDescriptor.js", - "./helpers/classPrivateFieldInitSpec": [ - { - "node": "./helpers/classPrivateFieldInitSpec.js", - "import": "./helpers/esm/classPrivateFieldInitSpec.js", - "default": "./helpers/classPrivateFieldInitSpec.js" - }, - "./helpers/classPrivateFieldInitSpec.js" - ], - "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", "./helpers/classStaticPrivateFieldSpecGet": [ { "node": "./helpers/classStaticPrivateFieldSpecGet.js", @@ -810,6 +801,24 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", + "./helpers/classPrivateMethodInitSpec": [ + { + "node": "./helpers/classPrivateMethodInitSpec.js", + "import": "./helpers/esm/classPrivateMethodInitSpec.js", + "default": "./helpers/classPrivateMethodInitSpec.js" + }, + "./helpers/classPrivateMethodInitSpec.js" + ], + "./helpers/esm/classPrivateMethodInitSpec": "./helpers/esm/classPrivateMethodInitSpec.js", "./helpers/classPrivateMethodSet": [ { "node": "./helpers/classPrivateMethodSet.js", diff --git a/packages/babel-runtime-corejs3/package.json b/packages/babel-runtime-corejs3/package.json index b2335f2b2bc1..884361db97dd 100644 --- a/packages/babel-runtime-corejs3/package.json +++ b/packages/babel-runtime-corejs3/package.json @@ -692,15 +692,6 @@ "./helpers/classExtractFieldDescriptor.js" ], "./helpers/esm/classExtractFieldDescriptor": "./helpers/esm/classExtractFieldDescriptor.js", - "./helpers/classPrivateFieldInitSpec": [ - { - "node": "./helpers/classPrivateFieldInitSpec.js", - "import": "./helpers/esm/classPrivateFieldInitSpec.js", - "default": "./helpers/classPrivateFieldInitSpec.js" - }, - "./helpers/classPrivateFieldInitSpec.js" - ], - "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", "./helpers/classStaticPrivateFieldSpecGet": [ { "node": "./helpers/classStaticPrivateFieldSpecGet.js", @@ -809,6 +800,24 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", + "./helpers/classPrivateMethodInitSpec": [ + { + "node": "./helpers/classPrivateMethodInitSpec.js", + "import": "./helpers/esm/classPrivateMethodInitSpec.js", + "default": "./helpers/classPrivateMethodInitSpec.js" + }, + "./helpers/classPrivateMethodInitSpec.js" + ], + "./helpers/esm/classPrivateMethodInitSpec": "./helpers/esm/classPrivateMethodInitSpec.js", "./helpers/classPrivateMethodSet": [ { "node": "./helpers/classPrivateMethodSet.js", diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index ba00bb02e805..ef7590dae32c 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -692,15 +692,6 @@ "./helpers/classExtractFieldDescriptor.js" ], "./helpers/esm/classExtractFieldDescriptor": "./helpers/esm/classExtractFieldDescriptor.js", - "./helpers/classPrivateFieldInitSpec": [ - { - "node": "./helpers/classPrivateFieldInitSpec.js", - "import": "./helpers/esm/classPrivateFieldInitSpec.js", - "default": "./helpers/classPrivateFieldInitSpec.js" - }, - "./helpers/classPrivateFieldInitSpec.js" - ], - "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", "./helpers/classStaticPrivateFieldSpecGet": [ { "node": "./helpers/classStaticPrivateFieldSpecGet.js", @@ -809,6 +800,24 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/classPrivateFieldInitSpec": [ + { + "node": "./helpers/classPrivateFieldInitSpec.js", + "import": "./helpers/esm/classPrivateFieldInitSpec.js", + "default": "./helpers/classPrivateFieldInitSpec.js" + }, + "./helpers/classPrivateFieldInitSpec.js" + ], + "./helpers/esm/classPrivateFieldInitSpec": "./helpers/esm/classPrivateFieldInitSpec.js", + "./helpers/classPrivateMethodInitSpec": [ + { + "node": "./helpers/classPrivateMethodInitSpec.js", + "import": "./helpers/esm/classPrivateMethodInitSpec.js", + "default": "./helpers/classPrivateMethodInitSpec.js" + }, + "./helpers/classPrivateMethodInitSpec.js" + ], + "./helpers/esm/classPrivateMethodInitSpec": "./helpers/esm/classPrivateMethodInitSpec.js", "./helpers/classPrivateMethodSet": [ { "node": "./helpers/classPrivateMethodSet.js", From 5770b460dc198bfff965350219faca6cb2516e7a Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Thu, 5 Aug 2021 10:20:53 -0300 Subject: [PATCH 13/30] Update packages/babel-helpers/src/helpers.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolò Ribaudo --- packages/babel-helpers/src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index 1f8c6b9b7c13..f653086f11e2 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -2018,7 +2018,7 @@ helpers.classPrivateMethodGet = helper("7.1.6")` helpers.classPrivateFieldInitSpec = helper("7.14.1")` export default function _classPrivateFieldInitSpec(obj, privateMap, value) { if (privateMap.has(obj)) { - throw new TypeError("redeclared private field identifier"); + throw new TypeError("Initializing an object twice is an error with private fields"); } privateMap.set(obj, value); } From 2e6f07a615b297afc143650cd033423b011c3eeb Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Thu, 5 Aug 2021 10:22:16 -0300 Subject: [PATCH 14/30] Added babel 8 breaking guard --- .../babel-helper-create-class-features-plugin/src/fields.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 4237931b829e..6395f7eca130 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -453,7 +453,10 @@ function buildPrivateInstanceFieldInitSpec(ref, prop, privateNamesMap, state) { const { id } = privateNamesMap.get(prop.node.key.id.name); const value = prop.node.value || prop.scope.buildUndefinedNode(); - if (!state.availableHelper("classPrivateFieldInitSpec")) { + if ( + !process.env.BABEL_8_BREAKING && + !state.availableHelper("classPrivateFieldInitSpec") + ) { return template.statement.ast`${t.cloneNode(id)}.set(${ref}, { // configurable is always false for private elements // enumerable is always false for private elements From 13f8014e28a2119357af955f050520dc67b28801 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Thu, 5 Aug 2021 10:47:30 -0300 Subject: [PATCH 15/30] Fixed typings error --- .../babel-helper-create-class-features-plugin/src/fields.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index a7a40ce7363b..a8cfa3930278 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -865,8 +865,8 @@ export function buildFieldsInitNodes( ) { let needsClassRef = false; let injectSuperRef: t.Identifier; - const staticNodes: t.Statement[] = []; - const instanceNodes: t.Statement[] = []; + const staticNodes: Array = []; + const instanceNodes: Array = []; // These nodes are pure and can be moved to the closest statement position const pureStaticNodes: t.FunctionDeclaration[] = []; From 894b70a22dee6743eb6fb24581fc55baf2b5e591 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 6 Aug 2021 09:20:14 -0300 Subject: [PATCH 16/30] Fixed return types --- .../src/fields.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index a8cfa3930278..c506a4764bf0 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -515,16 +515,15 @@ function buildPrivateInstanceFieldInitSpec( const { id } = privateNamesMap.get(prop.node.key.id.name); const value = prop.node.value || prop.scope.buildUndefinedNode(); - if ( - !process.env.BABEL_8_BREAKING && - !state.availableHelper("classPrivateFieldInitSpec") - ) { - return template.statement.ast`${t.cloneNode(id)}.set(${ref}, { + if (!process.env.BABEL_8_BREAKING) { + if (!state.availableHelper("classPrivateFieldInitSpec")) { + return template.statement.ast`${t.cloneNode(id)}.set(${ref}, { // configurable is always false for private elements // enumerable is always false for private elements writable: true, value: ${value}, })`; + } } const helper = state.addHelper("classPrivateFieldInitSpec"); @@ -537,7 +536,7 @@ function buildPrivateInstanceFieldInitSpec( }`, ]); - return expr; + return t.expressionStatement(expr); } function buildPrivateStaticFieldInitSpec( @@ -648,7 +647,7 @@ function buildPrivateInstanceMethodInitSpec( const helper = state.addHelper("classPrivateMethodInitSpec"); const expr = t.callExpression(helper, [t.thisExpression(), t.cloneNode(id)]); - return expr; + return t.expressionStatement(expr); } function buildPublicFieldInitLoose( @@ -865,8 +864,8 @@ export function buildFieldsInitNodes( ) { let needsClassRef = false; let injectSuperRef: t.Identifier; - const staticNodes: Array = []; - const instanceNodes: Array = []; + const staticNodes: t.Statement[] = []; + const instanceNodes: t.Statement[] = []; // These nodes are pure and can be moved to the closest statement position const pureStaticNodes: t.FunctionDeclaration[] = []; From 90087c25a50864394262410a67809adac660f26f Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 6 Aug 2021 09:21:04 -0300 Subject: [PATCH 17/30] Added babel 8 check --- .../babel-helper-create-class-features-plugin/src/fields.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index c506a4764bf0..bcde57edfc56 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -641,8 +641,10 @@ function buildPrivateInstanceMethodInitSpec( `; } - if (!state.availableHelper("classPrivateMethodInitSpec")) { - template.statement.ast`${id}.add(${ref})`; + if (!process.env.BABEL_8_BREAKING) { + if (!state.availableHelper("classPrivateMethodInitSpec")) { + return template.statement.ast`${id}.add(${ref})`; + } } const helper = state.addHelper("classPrivateMethodInitSpec"); From 7ba6f5eb8cea939fd384ccc29d5344d16549b5d7 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 6 Aug 2021 09:33:22 -0300 Subject: [PATCH 18/30] Added check redeclaration helper --- packages/babel-helpers/src/helpers.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index f653086f11e2..2c961c3d459b 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -2015,20 +2015,28 @@ helpers.classPrivateMethodGet = helper("7.1.6")` } `; -helpers.classPrivateFieldInitSpec = helper("7.14.1")` - export default function _classPrivateFieldInitSpec(obj, privateMap, value) { +helpers.checkPrivateRedeclaration = helper("7.14.1")` + export default function _checkPrivateRedeclaration(obj, privateMap) { if (privateMap.has(obj)) { - throw new TypeError("Initializing an object twice is an error with private fields"); + throw new TypeError("redeclared identifier"); } + } +`; + +helpers.classPrivateFieldInitSpec = helper("7.14.1")` + import checkPrivateRedeclaration from "checkPrivateRedeclaration"; + + export default function _classPrivateFieldInitSpec(obj, privateMap, value) { + checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); } `; helpers.classPrivateMethodInitSpec = helper("7.14.1")` + import checkPrivateRedeclaration from "checkPrivateRedeclaration"; + export default function _classPrivateMethodInitSpec(obj, privateSet) { - if (privateSet.has(obj)) { - throw new TypeError("redeclared private method identifier"); - } + checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); } `; From 3e81c566409698cd068ccbfb909940d25910f08d Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 6 Aug 2021 09:42:30 -0300 Subject: [PATCH 19/30] Fixed test --- .../field-reinitialization/private-method/output.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js index 006ac80fa27c..f5dd07cc5ed5 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-method/output.js @@ -5,7 +5,7 @@ class Base { } -var _foo = /*#__PURE__*/ new WeakSet(); +var _foo = /*#__PURE__*/new WeakSet(); class Derived extends Base { constructor(...args) { @@ -14,11 +14,11 @@ class Derived extends Base { } static get(obj) { - return _classPrivateMethodGet(obj, _foo, _foo2).call(obj); + return babelHelpers.classPrivateMethodGet(obj, _foo, _foo2).call(obj); } } function _foo2() { - return "bar"; + return 'bar'; } \ No newline at end of file From 3e28e0d6ebc5c98f9b0ee7cad8630d1d067081c9 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 6 Aug 2021 10:03:25 -0300 Subject: [PATCH 20/30] Updated var name --- packages/babel-helpers/src/helpers.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index 2c961c3d459b..60bd2f4129c4 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -2016,8 +2016,8 @@ helpers.classPrivateMethodGet = helper("7.1.6")` `; helpers.checkPrivateRedeclaration = helper("7.14.1")` - export default function _checkPrivateRedeclaration(obj, privateMap) { - if (privateMap.has(obj)) { + export default function _checkPrivateRedeclaration(obj, privateCollection) { + if (privateCollection.has(obj)) { throw new TypeError("redeclared identifier"); } } From 932b2efed61a4fa89f92ebc8bdd9a8e3051b3103 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 6 Aug 2021 10:09:45 -0300 Subject: [PATCH 21/30] Fixed tests --- .../plugin-proposal-private-methods/loose-false/output.js | 2 +- .../test/fixtures/replace-supers/method/output.js | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js index 6e921bc9e05b..c74df0f555e0 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/plugin-proposal-private-methods/loose-false/output.js @@ -2,7 +2,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class X { constructor() { - _privateMethod.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); } } diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/output.js index af58f2d3c9a8..07429bb7b2d2 100644 --- a/packages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/output.js +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/replace-supers/method/output.js @@ -3,8 +3,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class A extends B { constructor(...args) { super(...args); - - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } } From c275da72efba6a6f9cfa23708360d70029a9499b Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Fri, 6 Aug 2021 11:25:23 -0300 Subject: [PATCH 22/30] Handle private accessor method --- .../src/fields.ts | 62 +++++++++++++++++-- .../private-accessor/input.js | 19 ++++++ .../private-accessor/options.json | 6 ++ .../private-accessor/output.js | 31 ++++++++++ 4 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/input.js create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/options.json create mode 100644 packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/output.js diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index bcde57edfc56..69dea6cd6d44 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -622,25 +622,75 @@ function buildPrivateInstanceMethodInitSpec( state, ) { const privateName = privateNamesMap.get(prop.node.key.id.name); - const { id, getId, setId, initAdded } = privateName; + const { getId, setId, initAdded } = privateName; if (initAdded) return; const isAccessor = getId || setId; if (isAccessor) { - privateNamesMap.set(prop.node.key.id.name, { - ...privateName, - initAdded: true, - }); + return buildPrivateAccessorInitialization( + ref, + prop, + privateNamesMap, + state, + ); + } - return template.statement.ast` + return buildPrivateInstanceMethodInitalization( + ref, + prop, + privateNamesMap, + state, + ); +} + +function buildPrivateAccessorInitialization( + ref: t.Expression, + prop: NodePath, + privateNamesMap: PrivateNamesMap, + state, +) { + const privateName = privateNamesMap.get(prop.node.key.id.name); + const { id, getId, setId } = privateName; + + privateNamesMap.set(prop.node.key.id.name, { + ...privateName, + initAdded: true, + }); + + if (!process.env.BABEL_8_BREAKING) { + if (!state.availableHelper("classPrivateFieldInitSpec")) { + return template.statement.ast` ${id}.set(${ref}, { get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} }); `; + } } + const helper = state.addHelper("classPrivateFieldInitSpec"); + const expr = t.callExpression(helper, [ + t.thisExpression(), + t.cloneNode(id), + template.expression.ast`{ + get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, + set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} + }`, + ]); + + return t.expressionStatement(expr); +} + +function buildPrivateInstanceMethodInitalization( + ref: t.Expression, + prop: NodePath, + privateNamesMap: PrivateNamesMap, + state, +) { + const privateName = privateNamesMap.get(prop.node.key.id.name); + const { id } = privateName; + if (!process.env.BABEL_8_BREAKING) { if (!state.availableHelper("classPrivateMethodInitSpec")) { return template.statement.ast`${id}.add(${ref})`; diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/input.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/input.js new file mode 100644 index 000000000000..8bc707067391 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/input.js @@ -0,0 +1,19 @@ +class Base { + constructor(obj) { + return obj; + } +} + +class Derived extends Base { + get #foo() { + return 'bar'; + } + + set #foo(value) { + this.#foo = value; + } + + static get(obj) { + return obj.#foo(); + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/options.json b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/options.json new file mode 100644 index 000000000000..608f30af0eb3 --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/options.json @@ -0,0 +1,6 @@ +{ + "presets": [["env", { "shippedProposals": true }]], + "targets": { + "chrome": "75" + } +} diff --git a/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/output.js b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/output.js new file mode 100644 index 000000000000..f1710074613f --- /dev/null +++ b/packages/babel-helper-create-class-features-plugin/test/fixtures/field-reinitialization/private-accessor/output.js @@ -0,0 +1,31 @@ +class Base { + constructor(obj) { + return obj; + } + +} + +var _foo = /*#__PURE__*/new WeakMap(); + +class Derived extends Base { + constructor(...args) { + super(...args); + babelHelpers.classPrivateFieldInitSpec(this, _foo, { + get: _get_foo, + set: _set_foo + }); + } + + static get(obj) { + return babelHelpers.classPrivateFieldGet(obj, _foo).call(obj); + } + +} + +function _get_foo() { + return 'bar'; +} + +function _set_foo(value) { + babelHelpers.classPrivateFieldSet(this, _foo, value); +} From 01e2e0b54da23f3a1232f9c5161342a111c4fcf0 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Sat, 7 Aug 2021 14:59:31 -0300 Subject: [PATCH 23/30] Overwritten tests --- .../output.mjs | 3 +-- .../basic/class-private-integration/output.mjs | 3 +-- .../async-generators/class-private-method/output.js | 2 +- .../1-helpermemberexpressionfunction/output.js | 12 ++++-------- .../test/fixtures/private/assignment/output.js | 3 +-- .../test/fixtures/private/call/output.js | 3 +-- .../test/fixtures/private/canonical/output.js | 7 ++----- .../fixtures/private/constructor-collision/output.js | 4 +--- .../fixtures/private/declaration-order/output.js | 3 +-- .../private/derived-multiple-supers/output.js | 6 ++---- .../test/fixtures/private/derived/output.js | 7 ++----- .../private/destructuring-array-pattern-1/output.js | 4 +--- .../private/destructuring-array-pattern-2/output.js | 4 +--- .../private/destructuring-array-pattern-3/output.js | 4 +--- .../private/destructuring-array-pattern/output.js | 4 +--- .../private/destructuring-object-pattern-1/output.js | 4 +--- .../private/destructuring-object-pattern-2/output.js | 4 +--- .../private/destructuring-object-pattern-3/output.js | 4 +--- .../private/destructuring-object-pattern/output.js | 4 +--- .../test/fixtures/private/extracted-this/output.js | 6 ++---- .../test/fixtures/private/foobar/output.js | 4 +--- .../fixtures/private/instance-undefined/output.js | 3 +-- .../test/fixtures/private/instance/output.js | 3 +-- .../fixtures/private/logical-assignment/output.js | 8 +++----- .../test/fixtures/private/multiple/output.js | 6 ++---- .../test/fixtures/private/native-classes/output.js | 2 +- .../nested-class-computed-redeclared/output.js | 6 ++---- .../fixtures/private/nested-class-computed/output.js | 3 +-- .../output.js | 11 +++-------- .../private/nested-class-extends-computed/output.js | 7 ++----- .../private/nested-class-other-redeclared/output.js | 9 +++------ .../private/nested-class-redeclared/output.js | 6 ++---- .../test/fixtures/private/nested-class/output.js | 3 +-- .../output.js | 2 +- .../fixtures/private/private-in-derived/output.js | 3 +-- .../test/fixtures/private/reevaluated/output.js | 2 +- .../private/reference-in-other-property/output.js | 10 +++------- .../fixtures/private/regression-T7364/output.mjs | 6 +++--- .../test/fixtures/private/super-call/output.js | 4 +--- .../test/fixtures/private/super-expression/output.js | 2 +- .../test/fixtures/private/super-statement/output.js | 4 +--- .../test/fixtures/private/tagged-template/output.js | 3 +-- .../test/fixtures/private/update/output.js | 3 +-- .../test/fixtures/regression/8882/output.js | 3 +-- .../test/fixtures/accessors/basic/output.js | 6 ++---- .../fixtures/accessors/get-only-setter/output.js | 6 ++---- .../test/fixtures/accessors/reassignment/output.js | 3 +-- .../fixtures/accessors/set-only-getter/output.js | 6 ++---- .../fixtures/accessors/tagged-template/output.js | 3 +-- .../test/fixtures/accessors/updates/output.js | 6 ++---- .../private-method-super/output.js | 3 +-- .../test/fixtures/duplicated-names/get-set/output.js | 5 ++--- .../test/fixtures/duplicated-names/set-get/output.js | 5 ++--- .../fixtures/private-method/assignment/output.js | 3 +-- .../test/fixtures/private-method/async/output.js | 2 +- .../fixtures/private-method/before-fields/output.js | 6 ++---- .../private-method/class-expression/output.js | 2 +- .../test/fixtures/private-method/context/output.js | 3 +-- .../fixtures/private-method/exfiltrated/output.js | 2 +- .../test/fixtures/private-method/generator/output.js | 2 +- .../test/fixtures/private-method/read-only/output.js | 3 +-- .../fixtures/private-method/reassignment/output.js | 3 +-- .../test/fixtures/private-method/super/output.js | 3 +-- .../private-method/tagged-template/output.js | 2 +- .../fixtures/private-loose/native-classes/output.js | 2 +- .../test/fixtures/private/accessor/output.js | 3 +-- .../test/fixtures/private/field/output.js | 3 +-- .../test/fixtures/private/method/output.js | 3 +-- .../test/fixtures/private/native-classes/output.js | 2 +- .../private/nested-class-other-redeclared/output.js | 9 +++------ .../private/nested-class-redeclared/output.js | 6 ++---- .../test/fixtures/private/nested-class/output.js | 3 +-- .../preset-not-loose-no-plugins/output.js | 3 +-- .../output.js | 3 +-- .../properties-not-loose-preset-loose/output.js | 3 +-- .../new-class-features-firefox-70/output.js | 2 +- packages/babel-runtime-corejs2/package.json | 9 +++++++++ packages/babel-runtime-corejs3/package.json | 9 +++++++++ packages/babel-runtime/package.json | 9 +++++++++ 79 files changed, 134 insertions(+), 213 deletions(-) diff --git a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration-optional-chaining/output.mjs b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration-optional-chaining/output.mjs index b9c029038b14..982de805006b 100644 --- a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration-optional-chaining/output.mjs +++ b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration-optional-chaining/output.mjs @@ -4,11 +4,10 @@ class C { constructor() { var _babelHelpers$classPr; - _m.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _m, { writable: true, value: void 0 }); - const o = null; const n = this; const p = o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldGet(o, _m).call(o, ...c, 1); diff --git a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration/output.mjs b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration/output.mjs index b9c029038b14..982de805006b 100644 --- a/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration/output.mjs +++ b/packages/babel-plugin-bugfix-v8-spread-parameters-in-optional-chaining/test/fixtures/basic/class-private-integration/output.mjs @@ -4,11 +4,10 @@ class C { constructor() { var _babelHelpers$classPr; - _m.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _m, { writable: true, value: void 0 }); - const o = null; const n = this; const p = o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldGet(o, _m).call(o, ...c, 1); diff --git a/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js index edaf639ec2f7..92c4e90b13c8 100644 --- a/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js +++ b/packages/babel-plugin-proposal-async-generator-functions/test/fixtures/async-generators/class-private-method/output.js @@ -2,7 +2,7 @@ var _g = /*#__PURE__*/new WeakSet(); class C { constructor() { - _g.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _g); } } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/1-helpermemberexpressionfunction/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/1-helpermemberexpressionfunction/output.js index 89ad20142e0e..ff85bfa4598f 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/1-helpermemberexpressionfunction/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/1-helpermemberexpressionfunction/output.js @@ -5,8 +5,7 @@ var D = /*#__PURE__*/function () { function D() { babelHelpers.classCallCheck(this, D); - - _arr.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _arr, { writable: true, value: void 0 }); @@ -30,8 +29,7 @@ var C = /*#__PURE__*/function () { function C() { babelHelpers.classCallCheck(this, C); - - _p.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _p, { writable: true, value: void 0 }); @@ -55,8 +53,7 @@ var E = /*#__PURE__*/function () { function E() { babelHelpers.classCallCheck(this, E); - - _arr2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _arr2, { writable: true, value: void 0 }); @@ -80,8 +77,7 @@ var F = /*#__PURE__*/function () { function F() { babelHelpers.classCallCheck(this, F); - - _ar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _ar, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/assignment/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/assignment/output.js index a7817db0ff01..e0c46183b855 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/assignment/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/assignment/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/call/output.js index 27947d1df63f..2b12c7ae9bac 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/call/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: function () { return this; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/canonical/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/canonical/output.js index e41035c44796..5fc50758bc10 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/canonical/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/canonical/output.js @@ -7,17 +7,14 @@ var Point = /*#__PURE__*/function () { function Point(x = 0, y = 0) { babelHelpers.classCallCheck(this, Point); - - _x.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _x, { writable: true, value: void 0 }); - - _y.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _y, { writable: true, value: void 0 }); - babelHelpers.classPrivateFieldSet(this, _x, +x); babelHelpers.classPrivateFieldSet(this, _y, +y); } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/output.js index 05d01f4911b9..134fb98bdedf 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/constructor-collision/output.js @@ -6,11 +6,9 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: foo }); - var _foo = "foo"; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/declaration-order/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/declaration-order/output.js index b2c777ecc3ef..f3620fbdc887 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/declaration-order/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/declaration-order/output.js @@ -5,8 +5,7 @@ var C = function C() { babelHelpers.classCallCheck(this, C); babelHelpers.defineProperty(this, "y", babelHelpers.classPrivateFieldGet(this, _x)); - - _x.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _x, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived-multiple-supers/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived-multiple-supers/output.js index 06197e31d481..692b0bf2c253 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived-multiple-supers/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived-multiple-supers/output.js @@ -14,15 +14,13 @@ var Foo = /*#__PURE__*/function (_Bar) { if (condition) { _this = _super.call(this); - - _bar.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" }); } else { _this = _super.call(this); - - _bar.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived/output.js index 97251962ae41..d21589418236 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/derived/output.js @@ -4,8 +4,7 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _prop.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _prop, { writable: true, value: "foo" }); @@ -25,12 +24,10 @@ var Bar = /*#__PURE__*/function (_Foo) { babelHelpers.classCallCheck(this, Bar); _this = _super.call(this, ...args); - - _prop2.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _prop2, { writable: true, value: "bar" }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-1/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-1/output.js index 1b13a2e595c3..f8813d3f0212 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-1/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-1/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - babelHelpers.classPrivateFieldSet(this, _client, 1); [this.x = babelHelpers.classPrivateFieldGet(this, _client), babelHelpers.classPrivateFieldDestructureSet(this, _client).value, this.y = babelHelpers.classPrivateFieldGet(this, _client)] = props; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-2/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-2/output.js index 2ace67a331c0..9f88740d8363 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-2/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-2/output.js @@ -4,11 +4,9 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - [x, ...babelHelpers.classPrivateFieldDestructureSet(this, _client).value] = props; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-3/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-3/output.js index 6b9882ec1bc7..091bdecc0da9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-3/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern-3/output.js @@ -4,11 +4,9 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - [babelHelpers.classPrivateFieldDestructureSet(this, _client).value = 5] = props; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern/output.js index ffeb7c001e44..eeae89405a83 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-array-pattern/output.js @@ -4,11 +4,9 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - [babelHelpers.classPrivateFieldDestructureSet(this, _client).value] = props; }; diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-1/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-1/output.js index bb48cc08e11b..2522895f077e 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-1/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-1/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - babelHelpers.classPrivateFieldSet(this, _client, 'foo'); ({ x: this.x = babelHelpers.classPrivateFieldGet(this, _client), diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-2/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-2/output.js index 1ffd2fe58ffa..94f7111188c4 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-2/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-2/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - ({ x, ...babelHelpers.classPrivateFieldDestructureSet(this, _client).value diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-3/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-3/output.js index 0c4192589582..071bae2f50d7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-3/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern-3/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - ({ x: babelHelpers.classPrivateFieldDestructureSet(this, _client).value = 5 } = props); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern/output.js index 7459b76bc979..6366d6e7f5a5 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/destructuring-object-pattern/output.js @@ -4,12 +4,10 @@ var Foo = function Foo(props) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _client.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _client, { writable: true, value: void 0 }); - ({ client: babelHelpers.classPrivateFieldDestructureSet(this, _client).value } = props); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/extracted-this/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/extracted-this/output.js index 1fb7de2ab41d..5bbb120d1a6a 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/extracted-this/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/extracted-this/output.js @@ -8,13 +8,11 @@ var Foo = function Foo(_foo) { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: this }); - - _baz.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _baz, { writable: true, value: foo }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/foobar/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/foobar/output.js index 2ae9b573b32d..496503850a30 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/foobar/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/foobar/output.js @@ -12,14 +12,12 @@ var Child = /*#__PURE__*/function (_Parent) { babelHelpers.classCallCheck(this, Child); _this = _super.call(this); - - _scopedFunctionWithThis.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _scopedFunctionWithThis, { writable: true, value: () => { _this.name = {}; } }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance-undefined/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance-undefined/output.js index 8c8ba57dec55..dfa75cf39d8c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance-undefined/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance-undefined/output.js @@ -4,8 +4,7 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance/output.js index c7208f4d74b2..c30d93994e22 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/instance/output.js @@ -4,8 +4,7 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: "foo" }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js index e61da807cef9..012356bcec0c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/logical-assignment/output.js @@ -6,17 +6,15 @@ var _or = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _nullish.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _nullish, { writable: true, value: 0 }); - - _and.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _and, { writable: true, value: 0 }); - - _or.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _or, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/multiple/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/multiple/output.js index fd609d445893..de23ee50d176 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/multiple/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/multiple/output.js @@ -6,13 +6,11 @@ var Foo = function Foo() { "use strict"; babelHelpers.classCallCheck(this, Foo); - - _x.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _x, { writable: true, value: 0 }); - - _y.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _y, { writable: true, value: babelHelpers.classPrivateFieldGet(this, _x) }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/native-classes/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/native-classes/output.js index 98f497349993..cca3df0b1e97 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/native-classes/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/native-classes/output.js @@ -2,7 +2,7 @@ var _bar = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: "bar" }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js index 1dd4c23b4a31..1f1a88576bf3 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed-redeclared/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -24,8 +23,7 @@ var Foo = /*#__PURE__*/function () { var Nested = /*#__PURE__*/function (_babelHelpers$classPr2) { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _foo2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/output.js index e5d21a94663d..73762088ae78 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-computed/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/output.js index 816f80cbeb00..05370b34fc85 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed-redeclared/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -31,12 +30,10 @@ var Foo = /*#__PURE__*/function () { babelHelpers.classCallCheck(this, Nested); _this = _super.call(this, ...args); - - _foo2.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _foo2, { writable: true, value: 3 }); - return _this; } @@ -44,12 +41,10 @@ var Foo = /*#__PURE__*/function () { }((_foo3 = /*#__PURE__*/new WeakMap(), _babelHelpers$classPr = babelHelpers.classPrivateFieldGet(this, _foo3), /*#__PURE__*/function () { function _class2() { babelHelpers.classCallCheck(this, _class2); - - _foo3.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo3, { writable: true, value: 2 }); - babelHelpers.defineProperty(this, _babelHelpers$classPr, 2); } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/output.js index dddde36ed4d4..378e354e71d6 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-extends-computed/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -29,12 +28,10 @@ var Foo = /*#__PURE__*/function () { babelHelpers.classCallCheck(this, Nested); _this = _super.call(this, ...args); - - _foo2.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _foo2, { writable: true, value: 3 }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-other-redeclared/output.js index 080795751a9a..134b4cab21c9 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-other-redeclared/output.js @@ -7,13 +7,11 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: 1 }); @@ -27,8 +25,7 @@ var Foo = /*#__PURE__*/function () { var Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _bar2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-redeclared/output.js index 1030037c7a75..a507af4249b1 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class-redeclared/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -20,8 +19,7 @@ var Foo = /*#__PURE__*/function () { var Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _foo2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class/output.js index 69123eded43d..df432fc79aa7 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/nested-class/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-spread-arguments/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-spread-arguments/output.js index 593a5772ca7b..58e1533d26df 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-spread-arguments/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-member-optional-call-spread-arguments/output.js @@ -2,7 +2,7 @@ var _m = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _m.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _m, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/private-in-derived/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/private-in-derived/output.js index 1e5799660027..f2c1dbcfb016 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/private-in-derived/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/private-in-derived/output.js @@ -4,8 +4,7 @@ var Outer = function Outer() { "use strict"; babelHelpers.classCallCheck(this, Outer); - - _outer.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _outer, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js index 8c6a9554122f..6c22c5c9bf08 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reevaluated/output.js @@ -3,7 +3,7 @@ function classFactory() { return _temp = (_foo = /*#__PURE__*/new WeakMap(), _class = class Foo { constructor() { - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: "foo" }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reference-in-other-property/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reference-in-other-property/output.js index 0b7476ce49a0..6c3d52803c44 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reference-in-other-property/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/reference-in-other-property/output.js @@ -9,20 +9,16 @@ var Foo = function Foo() { babelHelpers.classCallCheck(this, Foo); babelHelpers.defineProperty(this, "one", babelHelpers.classPrivateFieldGet(this, _private)); - - _two.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _two, { writable: true, value: babelHelpers.classPrivateFieldGet(this, _private) }); - - _private.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _private, { writable: true, value: 0 }); - babelHelpers.defineProperty(this, "three", babelHelpers.classPrivateFieldGet(this, _private)); - - _four.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _four, { writable: true, value: babelHelpers.classPrivateFieldGet(this, _private) }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T7364/output.mjs b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T7364/output.mjs index ae07dabb7896..7d23ce353bbc 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T7364/output.mjs +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/regression-T7364/output.mjs @@ -4,7 +4,7 @@ class MyClass { constructor() { var _this = this; - _myAsyncMethod.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod, { writable: true, value: function () { var _ref = babelHelpers.asyncToGenerator(function* () { @@ -26,7 +26,7 @@ var _myAsyncMethod2 = /*#__PURE__*/new WeakMap(); constructor() { var _this2 = this; - _myAsyncMethod2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod2, { writable: true, value: function () { var _ref2 = babelHelpers.asyncToGenerator(function* () { @@ -48,7 +48,7 @@ export default class MyClass3 { constructor() { var _this3 = this; - _myAsyncMethod3.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _myAsyncMethod3, { writable: true, value: function () { var _ref3 = babelHelpers.asyncToGenerator(function* () { diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-call/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-call/output.js index 78bcdf3764a0..c329d248e38c 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-call/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-call/output.js @@ -28,12 +28,10 @@ var B = /*#__PURE__*/function (_A) { babelHelpers.classCallCheck(this, B); _this = _super.call(this, ...args); - - _foo.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _foo, { writable: true, value: babelHelpers.get((_thisSuper = babelHelpers.assertThisInitialized(_this), babelHelpers.getPrototypeOf(B.prototype)), "foo", _thisSuper).call(_thisSuper) }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js index 1f17e973a223..d3b2bb1e9ed1 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-expression/output.js @@ -11,7 +11,7 @@ var Foo = /*#__PURE__*/function (_Bar) { var _temp, _this; babelHelpers.classCallCheck(this, Foo); - foo((_temp = _this = _super.call(this), _bar.set(babelHelpers.assertThisInitialized(_this), { + foo((_temp = _this = _super.call(this), babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" }), _temp)); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-statement/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-statement/output.js index e652b376af27..310bfc691ca5 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-statement/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/super-statement/output.js @@ -12,12 +12,10 @@ var Foo = /*#__PURE__*/function (_Bar) { babelHelpers.classCallCheck(this, Foo); _this = _super.call(this); - - _bar.set(babelHelpers.assertThisInitialized(_this), { + babelHelpers.classPrivateFieldInitSpec(babelHelpers.assertThisInitialized(_this), _bar, { writable: true, value: "foo" }); - return _this; } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js index b06497c1fcdc..530024699bfe 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/tagged-template/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _tag.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _tag, { writable: true, value: void 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/update/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/update/output.js index 59d092de2de4..cab004ed47e6 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/update/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/update/output.js @@ -5,8 +5,7 @@ var Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js index f41cc8189c3d..fc17c143e229 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/regression/8882/output.js @@ -8,8 +8,7 @@ for (let i = 0; i <= 10; ++i) { classes.push((_temp = (_bar = /*#__PURE__*/new WeakMap(), _i = i, _class = class A { constructor() { babelHelpers.defineProperty(this, _i, `computed field ${i}`); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: `private field ${i}` }); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/basic/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/basic/output.js index 658554a063b1..4b64a3333d2f 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/basic/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/basic/output.js @@ -4,16 +4,14 @@ var _privateFieldValue = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: _get_privateFieldValue, set: _set_privateFieldValue }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: "top secret string" }); - this.publicField = "not secret string"; } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/get-only-setter/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/get-only-setter/output.js index 2a0691beefac..6c95f5f1bbdd 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/get-only-setter/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/get-only-setter/output.js @@ -4,16 +4,14 @@ var _privateFieldValue = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: void 0, set: _set_privateFieldValue }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: 0 }); - this.publicField = (this, babelHelpers.writeOnlyError("#privateFieldValue")); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/output.js index 4ee6f05ac82d..3cd48da10e76 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/reassignment/output.js @@ -4,11 +4,10 @@ var _privateFieldValue = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: _get_privateFieldValue, set: void 0 }); - this.self, results.push(2), babelHelpers.readOnlyError("#privateFieldValue"); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/output.js index 52a97f6ec2bd..99848e09ac72 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/set-only-getter/output.js @@ -9,16 +9,14 @@ class Cl { } constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: _get_privateFieldValue, set: void 0 }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: 0 }); - babelHelpers.defineProperty(this, "counter", 0); this.self, 1([babelHelpers.classPrivateFieldDestructureSet(this.self, _privateFieldValue).value] = [1]), babelHelpers.readOnlyError("#privateFieldValue"); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js index 90a909b22bbe..c8b534f929cf 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/tagged-template/output.js @@ -2,11 +2,10 @@ var _tag = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _tag.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _tag, { get: _get_tag, set: void 0 }); - babelHelpers.classPrivateFieldGet(this, _tag).bind(this)``; } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates/output.js index 0da9a9fc0775..a3e609e11f35 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/accessors/updates/output.js @@ -4,16 +4,14 @@ var _privateFieldValue = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _privateFieldValue.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateFieldValue, { get: _get_privateFieldValue, set: _set_privateFieldValue }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: "top secret string" }); - this.publicField = "not secret string"; } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/assumption-constantSuper/private-method-super/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/assumption-constantSuper/private-method-super/output.js index 74762cfc049b..b0c6dcfb4a85 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/assumption-constantSuper/private-method-super/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/assumption-constantSuper/private-method-super/output.js @@ -10,8 +10,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class Sub extends Base { constructor(...args) { super(...args); - - _privateMethod.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); } superMethod() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-set/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-set/output.js index 995151f76286..e4e64c0f3494 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-set/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/get-set/output.js @@ -4,12 +4,11 @@ var _getSet = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _getSet.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _getSet, { get: _get_getSet, set: _set_getSet }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-get/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-get/output.js index 3c26592e7614..10379c8a3700 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-get/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/duplicated-names/set-get/output.js @@ -4,12 +4,11 @@ var _getSet = /*#__PURE__*/new WeakMap(); class Cl { constructor() { - _getSet.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _getSet, { get: _get_getSet, set: _set_getSet }); - - _privateField.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _privateField, { writable: true, value: 0 }); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js index 0c4c7958abdc..368062ce9a74 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/assignment/output.js @@ -2,8 +2,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class Foo { constructor() { - _privateMethod.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); this.publicField = babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/async/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/async/output.js index 256f7fe629c0..13ee286f7c87 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/async/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/async/output.js @@ -2,7 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class Cl { constructor() { - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } test() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/before-fields/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/before-fields/output.js index 447aba2a5082..fe5a04321881 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/before-fields/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/before-fields/output.js @@ -4,11 +4,9 @@ var _method = /*#__PURE__*/new WeakSet(); class Cl { constructor() { - _method.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _method); babelHelpers.defineProperty(this, "prop", babelHelpers.classPrivateMethodGet(this, _method, _method2).call(this, 1)); - - _priv.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _priv, { writable: true, value: babelHelpers.classPrivateMethodGet(this, _method, _method2).call(this, 2) }); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/class-expression/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/class-expression/output.js index f0c034edfe8c..b177284a7867 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/class-expression/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/class-expression/output.js @@ -2,7 +2,7 @@ var _foo; console.log((_foo = /*#__PURE__*/new WeakSet(), class A { constructor() { - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } method() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/context/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/context/output.js index 0be6a465b0b9..9d96c81401a5 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/context/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/context/output.js @@ -2,8 +2,7 @@ var _getStatus = /*#__PURE__*/new WeakSet(); class Foo { constructor(status) { - _getStatus.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _getStatus); this.status = status; } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/exfiltrated/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/exfiltrated/output.js index 88d1606b8f96..cac29e2bd16f 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/exfiltrated/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/exfiltrated/output.js @@ -4,7 +4,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class Foo { constructor() { - _privateMethod.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); if (exfiltrated === undefined) { exfiltrated = babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2); diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/generator/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/generator/output.js index 2d3984fd5d5a..565cde34ac84 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/generator/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/generator/output.js @@ -2,7 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class Cl { constructor() { - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } test() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/read-only/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/read-only/output.js index 9b9b5db27968..cf55c305310b 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/read-only/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/read-only/output.js @@ -7,8 +7,7 @@ class A { } constructor() { - _method.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _method); babelHelpers.defineProperty(this, "counter", 0); this.self(), 2, babelHelpers.readOnlyError("#method"); [babelHelpers.classPrivateFieldDestructureSet(this, _method).value] = [2]; diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/reassignment/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/reassignment/output.js index d06ddb53ec2b..6fc9d8e6bc40 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/reassignment/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/reassignment/output.js @@ -4,8 +4,7 @@ var _privateFieldValue = /*#__PURE__*/new WeakSet(); class Foo { constructor() { - _privateFieldValue.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _privateFieldValue); this.self, results.push(2), babelHelpers.readOnlyError("#privateFieldValue"); } diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js index 475654149f6a..25ba5547ffb6 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/super/output.js @@ -10,8 +10,7 @@ var _privateMethod = /*#__PURE__*/new WeakSet(); class Sub extends Base { constructor(...args) { super(...args); - - _privateMethod.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _privateMethod); } superMethod() { diff --git a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js index 21029095ae9a..fb9580a3f92b 100644 --- a/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js +++ b/packages/babel-plugin-proposal-private-methods/test/fixtures/private-method/tagged-template/output.js @@ -2,7 +2,7 @@ var _tag = /*#__PURE__*/new WeakSet(); class Foo { constructor() { - _tag.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _tag); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js index 13ebbe421023..51e66218a8ab 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js @@ -2,7 +2,7 @@ var _bar = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: "bar" }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js index 75a7587782a9..a5a7d2bc3703 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { get: _get_foo, set: void 0 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js index c83e48bcd86d..b5206a1f38e3 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js index ac675cbf7d85..32edd0cc6acf 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.add(this); + babelHelpers.classPrivateMethodInitSpec(this, _foo); } babelHelpers.createClass(Foo, [{ diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js index 13ebbe421023..51e66218a8ab 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js @@ -2,7 +2,7 @@ var _bar = /*#__PURE__*/new WeakMap(); class Foo { constructor() { - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: "bar" }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js index a54b7a6691f1..82f59fa0b443 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js @@ -7,13 +7,11 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); - - _bar.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar, { writable: true, value: 1 }); @@ -27,8 +25,7 @@ let Foo = /*#__PURE__*/function () { let Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _bar2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _bar2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js index 20a7183234aa..b9c7cf225570 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); @@ -20,8 +19,7 @@ let Foo = /*#__PURE__*/function () { let Nested = /*#__PURE__*/function () { function Nested() { babelHelpers.classCallCheck(this, Nested); - - _foo2.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo2, { writable: true, value: 2 }); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js index 2c52c716a1ee..57550078e7fc 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js @@ -5,8 +5,7 @@ let Foo = /*#__PURE__*/function () { function Foo() { babelHelpers.classCallCheck(this, Foo); - - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: 1 }); diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/preset-not-loose-no-plugins/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/preset-not-loose-no-plugins/output.js index f3de7b04fc78..e411740434d3 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/preset-not-loose-no-plugins/output.js +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/preset-not-loose-no-plugins/output.js @@ -2,8 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class A { constructor() { - _foo.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _foo); babelHelpers.defineProperty(this, "x", 2); } diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/output.js index f3de7b04fc78..e411740434d3 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/output.js +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-and-methods-not-loose-preset-loose/output.js @@ -2,8 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class A { constructor() { - _foo.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _foo); babelHelpers.defineProperty(this, "x", 2); } diff --git a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/output.js b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/output.js index f3de7b04fc78..e411740434d3 100644 --- a/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/output.js +++ b/packages/babel-preset-env/test/fixtures/loose-class-features-precedence/properties-not-loose-preset-loose/output.js @@ -2,8 +2,7 @@ var _foo = /*#__PURE__*/new WeakSet(); class A { constructor() { - _foo.add(this); - + babelHelpers.classPrivateMethodInitSpec(this, _foo); babelHelpers.defineProperty(this, "x", 2); } diff --git a/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js b/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js index 458142957dda..1cb775441ef3 100644 --- a/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js +++ b/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js @@ -2,7 +2,7 @@ var _foo = /*#__PURE__*/new WeakMap(); class A { constructor() { - _foo.set(this, { + babelHelpers.classPrivateFieldInitSpec(this, _foo, { writable: true, value: void 0 }); diff --git a/packages/babel-runtime-corejs2/package.json b/packages/babel-runtime-corejs2/package.json index de8654a8b56c..9438ef229a06 100644 --- a/packages/babel-runtime-corejs2/package.json +++ b/packages/babel-runtime-corejs2/package.json @@ -801,6 +801,15 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/checkPrivateRedeclaration": [ + { + "node": "./helpers/checkPrivateRedeclaration.js", + "import": "./helpers/esm/checkPrivateRedeclaration.js", + "default": "./helpers/checkPrivateRedeclaration.js" + }, + "./helpers/checkPrivateRedeclaration.js" + ], + "./helpers/esm/checkPrivateRedeclaration": "./helpers/esm/checkPrivateRedeclaration.js", "./helpers/classPrivateFieldInitSpec": [ { "node": "./helpers/classPrivateFieldInitSpec.js", diff --git a/packages/babel-runtime-corejs3/package.json b/packages/babel-runtime-corejs3/package.json index c739420520e9..187dd4093c10 100644 --- a/packages/babel-runtime-corejs3/package.json +++ b/packages/babel-runtime-corejs3/package.json @@ -800,6 +800,15 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/checkPrivateRedeclaration": [ + { + "node": "./helpers/checkPrivateRedeclaration.js", + "import": "./helpers/esm/checkPrivateRedeclaration.js", + "default": "./helpers/checkPrivateRedeclaration.js" + }, + "./helpers/checkPrivateRedeclaration.js" + ], + "./helpers/esm/checkPrivateRedeclaration": "./helpers/esm/checkPrivateRedeclaration.js", "./helpers/classPrivateFieldInitSpec": [ { "node": "./helpers/classPrivateFieldInitSpec.js", diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index ada0f37859f8..15c424230126 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -800,6 +800,15 @@ "./helpers/classPrivateMethodGet.js" ], "./helpers/esm/classPrivateMethodGet": "./helpers/esm/classPrivateMethodGet.js", + "./helpers/checkPrivateRedeclaration": [ + { + "node": "./helpers/checkPrivateRedeclaration.js", + "import": "./helpers/esm/checkPrivateRedeclaration.js", + "default": "./helpers/checkPrivateRedeclaration.js" + }, + "./helpers/checkPrivateRedeclaration.js" + ], + "./helpers/esm/checkPrivateRedeclaration": "./helpers/esm/checkPrivateRedeclaration.js", "./helpers/classPrivateFieldInitSpec": [ { "node": "./helpers/classPrivateFieldInitSpec.js", From 4047989b6b7d6a481c63687f8bfd7ed5166f317a Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Thu, 12 Aug 2021 13:13:21 -0300 Subject: [PATCH 24/30] Updated error message --- packages/babel-helpers/src/helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/babel-helpers/src/helpers.js b/packages/babel-helpers/src/helpers.js index 60bd2f4129c4..945bc98624c3 100644 --- a/packages/babel-helpers/src/helpers.js +++ b/packages/babel-helpers/src/helpers.js @@ -2018,7 +2018,7 @@ helpers.classPrivateMethodGet = helper("7.1.6")` helpers.checkPrivateRedeclaration = helper("7.14.1")` export default function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { - throw new TypeError("redeclared identifier"); + throw new TypeError("Cannot initialize the same private elements twice on an object"); } } `; From 8e5e4049921c83ef9ff5872f23b663376771b1a6 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 16 Aug 2021 17:52:32 -0300 Subject: [PATCH 25/30] Update packages/babel-helper-create-class-features-plugin/src/fields.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolò Ribaudo --- .../src/fields.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 69dea6cd6d44..bcbd87cc1f90 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -518,11 +518,11 @@ function buildPrivateInstanceFieldInitSpec( if (!process.env.BABEL_8_BREAKING) { if (!state.availableHelper("classPrivateFieldInitSpec")) { return template.statement.ast`${t.cloneNode(id)}.set(${ref}, { - // configurable is always false for private elements - // enumerable is always false for private elements - writable: true, - value: ${value}, - })`; + // configurable is always false for private elements + // enumerable is always false for private elements + writable: true, + value: ${value}, + })`; } } From 1f6b26c2f270b9020b10895e45f8b39bc1e2e69d Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Mon, 16 Aug 2021 17:52:40 -0300 Subject: [PATCH 26/30] Update packages/babel-helper-create-class-features-plugin/src/fields.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Nicolò Ribaudo --- .../babel-helper-create-class-features-plugin/src/fields.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index bcbd87cc1f90..4710705a1141 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -531,9 +531,9 @@ function buildPrivateInstanceFieldInitSpec( t.thisExpression(), t.cloneNode(id), template.expression.ast`{ - writable: true, - value: ${value} - }`, + writable: true, + value: ${value} + }`, ]); return t.expressionStatement(expr); From d187a7756944664763ff537f06aac728cbece931 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 18 Aug 2021 07:12:22 -0300 Subject: [PATCH 27/30] Update packages/babel-helper-create-class-features-plugin/src/fields.ts Co-authored-by: Justin Ridgewell --- .../src/fields.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 4710705a1141..c374ffb28a43 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -670,16 +670,14 @@ function buildPrivateAccessorInitialization( } const helper = state.addHelper("classPrivateFieldInitSpec"); - const expr = t.callExpression(helper, [ - t.thisExpression(), - t.cloneNode(id), - template.expression.ast`{ - get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, - set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} - }`, - ]); - - return t.expressionStatement(expr); + return template.statement.ast`${helper}( + ${t.thisExpression()}, + ${id}, + { + get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, + set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} + }, + )`; } function buildPrivateInstanceMethodInitalization( From 1d33cf2bf0c9359c77c4365030b016b8ea6cec4c Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 18 Aug 2021 07:12:30 -0300 Subject: [PATCH 28/30] Update packages/babel-helper-create-class-features-plugin/src/fields.ts Co-authored-by: Justin Ridgewell --- .../babel-helper-create-class-features-plugin/src/fields.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index c374ffb28a43..9d513f670ad2 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -696,8 +696,7 @@ function buildPrivateInstanceMethodInitalization( } const helper = state.addHelper("classPrivateMethodInitSpec"); - const expr = t.callExpression(helper, [t.thisExpression(), t.cloneNode(id)]); - return t.expressionStatement(expr); + return template.statement.ast`${helper}(${t.thisExpression()}, ${id})`; } function buildPublicFieldInitLoose( From f9eb76aa20efb0ccdf54a4c48e6c1932453a0a42 Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 18 Aug 2021 07:55:38 -0300 Subject: [PATCH 29/30] Update packages/babel-helper-create-class-features-plugin/src/fields.ts Co-authored-by: Justin Ridgewell --- .../src/fields.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 9d513f670ad2..cb03c9f10d77 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -527,16 +527,14 @@ function buildPrivateInstanceFieldInitSpec( } const helper = state.addHelper("classPrivateFieldInitSpec"); - const expr = t.callExpression(helper, [ - t.thisExpression(), - t.cloneNode(id), - template.expression.ast`{ + return template.statement.ast`${helper}( + ${t.thisExpression()}, + ${id}, + { writable: true, value: ${value} - }`, - ]); - - return t.expressionStatement(expr); + }, + )`; } function buildPrivateStaticFieldInitSpec( From ebf193c5a201a293a7c1536b52aa2feb0d64ca2a Mon Sep 17 00:00:00 2001 From: Felipe Armoni Date: Wed, 18 Aug 2021 08:09:28 -0300 Subject: [PATCH 30/30] Clone id nodes --- .../src/fields.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index cb03c9f10d77..d2ee44f0cced 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -529,7 +529,7 @@ function buildPrivateInstanceFieldInitSpec( const helper = state.addHelper("classPrivateFieldInitSpec"); return template.statement.ast`${helper}( ${t.thisExpression()}, - ${id}, + ${t.cloneNode(id)}, { writable: true, value: ${value} @@ -670,7 +670,7 @@ function buildPrivateAccessorInitialization( const helper = state.addHelper("classPrivateFieldInitSpec"); return template.statement.ast`${helper}( ${t.thisExpression()}, - ${id}, + ${t.cloneNode(id)}, { get: ${getId ? getId.name : prop.scope.buildUndefinedNode()}, set: ${setId ? setId.name : prop.scope.buildUndefinedNode()} @@ -694,7 +694,10 @@ function buildPrivateInstanceMethodInitalization( } const helper = state.addHelper("classPrivateMethodInitSpec"); - return template.statement.ast`${helper}(${t.thisExpression()}, ${id})`; + return template.statement.ast`${helper}( + ${t.thisExpression()}, + ${t.cloneNode(id)} + )`; } function buildPublicFieldInitLoose(