From 1e1d081805e51d494d2d22568b656698a28849f0 Mon Sep 17 00:00:00 2001 From: magic-akari Date: Mon, 2 May 2022 12:34:46 +0800 Subject: [PATCH] fix(es/compat): Support updating a private field with bigint value (#4136) --- ...eNameFieldUnaryMutation_es2015.1.normal.js | 43 ++- ...ameFieldUnaryMutation_es2015.2.minified.js | 10 +- ...vateNameFieldUnaryMutation_es5.1.normal.js | 43 ++- ...teNameFieldUnaryMutation_es5.2.minified.js | 10 +- ...ateNameMethodAssignment_es2015.1.normal.js | 4 +- ...rivateNameMethodAssignment_es5.1.normal.js | 4 +- ...vateNameMethodAssignment_es5.2.minified.js | 4 +- ...ieldDestructuredBinding_es2015.1.normal.js | 16 +- ...ldDestructuredBinding_es2015.2.minified.js | 10 +- ...icFieldDestructuredBinding_es5.1.normal.js | 18 +- ...FieldDestructuredBinding_es5.2.minified.js | 10 +- ...taticFieldUnaryMutation_es2015.1.normal.js | 42 ++- ...ticFieldUnaryMutation_es2015.2.minified.js | 10 +- ...meStaticFieldUnaryMutation_es5.1.normal.js | 42 ++- ...StaticFieldUnaryMutation_es5.2.minified.js | 10 +- ...eStaticMethodAssignment_es2015.1.normal.js | 6 +- ...taticMethodAssignment_es2015.2.minified.js | 5 +- ...NameStaticMethodAssignment_es5.1.normal.js | 6 +- ...meStaticMethodAssignment_es5.2.minified.js | 2 +- ...StaticsAndStaticMethods_es2015.1.normal.js | 3 +- ...aticsAndStaticMethods_es2015.2.minified.js | 2 +- ...ameStaticsAndStaticMethods_es5.1.normal.js | 3 +- ...eStaticsAndStaticMethods_es5.2.minified.js | 2 +- .../privateNamesAndMethods_es2015.1.normal.js | 3 +- .../privateNamesAndMethods_es5.1.normal.js | 3 +- .../privateNamesAndMethods_es5.2.minified.js | 2 +- ...teNamesAndStaticMethods_es2015.1.normal.js | 3 +- ...NamesAndStaticMethods_es2015.2.minified.js | 2 +- ...ivateNamesAndStaticMethods_es5.1.normal.js | 3 +- ...ateNamesAndStaticMethods_es5.2.minified.js | 2 +- .../helpers/_class_apply_descriptor_update.js | 23 ++ .../helpers/_class_private_field_update.js | 4 + .../_class_static_private_field_update.js | 5 + .../src/helpers/mod.rs | 10 + .../src/es2022/class_properties/mod.rs | 4 +- .../es2022/class_properties/private_field.rs | 273 +++++++----------- .../tests/classes/issue-3700/exec.js | 38 +++ .../tests/classes/issue-3700/input.js | 38 +++ .../tests/classes/issue-3700/output.js | 62 ++++ .../tests/es2022_class_properties.rs | 136 ++++----- .../src/_class_apply_descriptor_update.js | 23 ++ .../src/_class_private_field_update.js | 7 + .../src/_class_static_private_field_update.js | 9 + 43 files changed, 540 insertions(+), 415 deletions(-) create mode 100644 crates/swc_ecma_transforms_base/src/helpers/_class_apply_descriptor_update.js create mode 100644 crates/swc_ecma_transforms_base/src/helpers/_class_private_field_update.js create mode 100644 crates/swc_ecma_transforms_base/src/helpers/_class_static_private_field_update.js create mode 100644 crates/swc_ecma_transforms_compat/tests/classes/issue-3700/exec.js create mode 100644 crates/swc_ecma_transforms_compat/tests/classes/issue-3700/input.js create mode 100644 crates/swc_ecma_transforms_compat/tests/classes/issue-3700/output.js create mode 100644 packages/swc-helpers/src/_class_apply_descriptor_update.js create mode 100644 packages/swc-helpers/src/_class_private_field_update.js create mode 100644 packages/swc-helpers/src/_class_static_private_field_update.js diff --git a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es2015.1.normal.js index 976d0e9cb22..66b6d78450a 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es2015.1.normal.js @@ -3,36 +3,35 @@ var _test = /*#__PURE__*/ new WeakMap(); // @target: es2015 class C { test() { - var _ref, _this_test, _ref1, _this_test1, _ref2, _ref3, _ref4, _this_test2, _ref5, _this_test3, _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _this_test4; - swcHelpers.classPrivateFieldSet(_ref = this.getInstance(), _test, (_this_test = +swcHelpers.classPrivateFieldGet(_ref, _test)) + 1), _this_test; - swcHelpers.classPrivateFieldSet(_ref1 = this.getInstance(), _test, (_this_test1 = +swcHelpers.classPrivateFieldGet(_ref1, _test)) - 1), _this_test1; - swcHelpers.classPrivateFieldSet(_ref2 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref2, _test) + 1); - swcHelpers.classPrivateFieldSet(_ref3 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref3, _test) - 1); - const a = (swcHelpers.classPrivateFieldSet(_ref4 = this.getInstance(), _test, (_this_test2 = +swcHelpers.classPrivateFieldGet(_ref4, _test)) + 1), _this_test2); - const b = (swcHelpers.classPrivateFieldSet(_ref5 = this.getInstance(), _test, (_this_test3 = +swcHelpers.classPrivateFieldGet(_ref5, _test)) - 1), _this_test3); - const c = swcHelpers.classPrivateFieldSet(_ref6 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref6, _test) + 1); - const d = swcHelpers.classPrivateFieldSet(_ref7 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref7, _test) - 1); - for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); swcHelpers.classPrivateFieldGet(_ref8 = this.getInstance(), _test) < 10; swcHelpers.classPrivateFieldSet(_ref9 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref9, _test) + 1)){} - for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); swcHelpers.classPrivateFieldGet(_ref10 = this.getInstance(), _test) < 10; swcHelpers.classPrivateFieldSet(_ref11 = this.getInstance(), _test, (_this_test4 = +swcHelpers.classPrivateFieldGet(_ref11, _test)) + 1), _this_test4){} + var _ref, _ref1; + swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++; + swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value--; + ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value; + --swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value; + const a = swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++; + const b = swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value--; + const c = ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value; + const d = --swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value; + for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); swcHelpers.classPrivateFieldGet(_ref = this.getInstance(), _test) < 10; ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value){} + for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); swcHelpers.classPrivateFieldGet(_ref1 = this.getInstance(), _test) < 10; swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++){} } getInstance() { return new C(); } constructor(){ - var _this_test, _this_test5, _this_test6, _this_test7, _this_test8; swcHelpers.classPrivateFieldInit(this, _test, { writable: true, value: 24 }); - swcHelpers.classPrivateFieldSet(this, _test, (_this_test = +swcHelpers.classPrivateFieldGet(this, _test)) + 1), _this_test; - swcHelpers.classPrivateFieldSet(this, _test, (_this_test5 = +swcHelpers.classPrivateFieldGet(this, _test)) - 1), _this_test5; - swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1); - swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1); - const a = (swcHelpers.classPrivateFieldSet(this, _test, (_this_test6 = +swcHelpers.classPrivateFieldGet(this, _test)) + 1), _this_test6); - const b = (swcHelpers.classPrivateFieldSet(this, _test, (_this_test7 = +swcHelpers.classPrivateFieldGet(this, _test)) - 1), _this_test7); - const c = swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1); - const d = swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1); - for(swcHelpers.classPrivateFieldSet(this, _test, 0); swcHelpers.classPrivateFieldGet(this, _test) < 10; swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1)){} - for(swcHelpers.classPrivateFieldSet(this, _test, 0); swcHelpers.classPrivateFieldGet(this, _test) < 10; swcHelpers.classPrivateFieldSet(this, _test, (_this_test8 = +swcHelpers.classPrivateFieldGet(this, _test)) + 1), _this_test8){} + swcHelpers.classPrivateFieldUpdate(this, _test).value++; + swcHelpers.classPrivateFieldUpdate(this, _test).value--; + ++swcHelpers.classPrivateFieldUpdate(this, _test).value; + --swcHelpers.classPrivateFieldUpdate(this, _test).value; + const a = swcHelpers.classPrivateFieldUpdate(this, _test).value++; + const b = swcHelpers.classPrivateFieldUpdate(this, _test).value--; + const c = ++swcHelpers.classPrivateFieldUpdate(this, _test).value; + const d = --swcHelpers.classPrivateFieldUpdate(this, _test).value; + for(swcHelpers.classPrivateFieldSet(this, _test, 0); swcHelpers.classPrivateFieldGet(this, _test) < 10; ++swcHelpers.classPrivateFieldUpdate(this, _test).value){} + for(swcHelpers.classPrivateFieldSet(this, _test, 0); swcHelpers.classPrivateFieldGet(this, _test) < 10; swcHelpers.classPrivateFieldUpdate(this, _test).value++){} } } diff --git a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es2015.2.minified.js index 7f2cdcf69a4..d7dd6710950 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es2015.2.minified.js @@ -2,19 +2,17 @@ import * as swcHelpers from "@swc/helpers"; var _test = new WeakMap(); class C { test() { - var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _this_test; - for(swcHelpers.classPrivateFieldSet(_ref = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref, _test) + 1), swcHelpers.classPrivateFieldSet(_ref1 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref1, _test) - 1), swcHelpers.classPrivateFieldSet(_ref2 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref2, _test) + 1), swcHelpers.classPrivateFieldSet(_ref3 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref3, _test) - 1), swcHelpers.classPrivateFieldSet(_ref4 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref4, _test) + 1), swcHelpers.classPrivateFieldSet(_ref5 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref5, _test) - 1), swcHelpers.classPrivateFieldSet(_ref6 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref6, _test) + 1), swcHelpers.classPrivateFieldSet(_ref7 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref7, _test) - 1), swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); 10 > swcHelpers.classPrivateFieldGet(this.getInstance(), _test); swcHelpers.classPrivateFieldSet(_ref8 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref8, _test) + 1)); - for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); 10 > swcHelpers.classPrivateFieldGet(this.getInstance(), _test); swcHelpers.classPrivateFieldSet(_ref9 = this.getInstance(), _test, (_this_test = +swcHelpers.classPrivateFieldGet(_ref9, _test)) + 1), _this_test); + for(swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++, swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value--, ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value, --swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value, swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++, swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value--, ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value, --swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value, swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); 10 > swcHelpers.classPrivateFieldGet(this.getInstance(), _test); ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value); + for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); 10 > swcHelpers.classPrivateFieldGet(this.getInstance(), _test); swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++); } getInstance() { return new C(); } constructor(){ - var _this_test; for(swcHelpers.classPrivateFieldInit(this, _test, { writable: !0, value: 24 - }), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1), swcHelpers.classPrivateFieldSet(this, _test, 0); 10 > swcHelpers.classPrivateFieldGet(this, _test); swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1)); - for(swcHelpers.classPrivateFieldSet(this, _test, 0); 10 > swcHelpers.classPrivateFieldGet(this, _test); swcHelpers.classPrivateFieldSet(this, _test, (_this_test = +swcHelpers.classPrivateFieldGet(this, _test)) + 1), _this_test); + }), swcHelpers.classPrivateFieldUpdate(this, _test).value++, swcHelpers.classPrivateFieldUpdate(this, _test).value--, ++swcHelpers.classPrivateFieldUpdate(this, _test).value, --swcHelpers.classPrivateFieldUpdate(this, _test).value, swcHelpers.classPrivateFieldUpdate(this, _test).value++, swcHelpers.classPrivateFieldUpdate(this, _test).value--, ++swcHelpers.classPrivateFieldUpdate(this, _test).value, --swcHelpers.classPrivateFieldUpdate(this, _test).value, swcHelpers.classPrivateFieldSet(this, _test, 0); 10 > swcHelpers.classPrivateFieldGet(this, _test); ++swcHelpers.classPrivateFieldUpdate(this, _test).value); + for(swcHelpers.classPrivateFieldSet(this, _test, 0); 10 > swcHelpers.classPrivateFieldGet(this, _test); swcHelpers.classPrivateFieldUpdate(this, _test).value++); } } diff --git a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es5.1.normal.js index 0e80ceeed75..a1f006af359 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es5.1.normal.js @@ -5,35 +5,34 @@ var C = /*#__PURE__*/ function() { "use strict"; function C() { swcHelpers.classCallCheck(this, C); - var _this_test, _this_test1, _this_test2, _this_test3, _this_test4; swcHelpers.classPrivateFieldInit(this, _test, { writable: true, value: 24 }); - swcHelpers.classPrivateFieldSet(this, _test, (_this_test = +swcHelpers.classPrivateFieldGet(this, _test)) + 1), _this_test; - swcHelpers.classPrivateFieldSet(this, _test, (_this_test1 = +swcHelpers.classPrivateFieldGet(this, _test)) - 1), _this_test1; - swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1); - swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1); - var a = (swcHelpers.classPrivateFieldSet(this, _test, (_this_test2 = +swcHelpers.classPrivateFieldGet(this, _test)) + 1), _this_test2); - var b = (swcHelpers.classPrivateFieldSet(this, _test, (_this_test3 = +swcHelpers.classPrivateFieldGet(this, _test)) - 1), _this_test3); - var c = swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1); - var d = swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1); - for(swcHelpers.classPrivateFieldSet(this, _test, 0); swcHelpers.classPrivateFieldGet(this, _test) < 10; swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1)){} - for(swcHelpers.classPrivateFieldSet(this, _test, 0); swcHelpers.classPrivateFieldGet(this, _test) < 10; swcHelpers.classPrivateFieldSet(this, _test, (_this_test4 = +swcHelpers.classPrivateFieldGet(this, _test)) + 1), _this_test4){} + swcHelpers.classPrivateFieldUpdate(this, _test).value++; + swcHelpers.classPrivateFieldUpdate(this, _test).value--; + ++swcHelpers.classPrivateFieldUpdate(this, _test).value; + --swcHelpers.classPrivateFieldUpdate(this, _test).value; + var a = swcHelpers.classPrivateFieldUpdate(this, _test).value++; + var b = swcHelpers.classPrivateFieldUpdate(this, _test).value--; + var c = ++swcHelpers.classPrivateFieldUpdate(this, _test).value; + var d = --swcHelpers.classPrivateFieldUpdate(this, _test).value; + for(swcHelpers.classPrivateFieldSet(this, _test, 0); swcHelpers.classPrivateFieldGet(this, _test) < 10; ++swcHelpers.classPrivateFieldUpdate(this, _test).value){} + for(swcHelpers.classPrivateFieldSet(this, _test, 0); swcHelpers.classPrivateFieldGet(this, _test) < 10; swcHelpers.classPrivateFieldUpdate(this, _test).value++){} } var _proto = C.prototype; _proto.test = function test() { - var _ref, _this_test, _ref1, _this_test5, _ref2, _ref3, _ref4, _this_test6, _ref5, _this_test7, _ref6, _ref7, _ref8, _ref9, _ref10, _ref11, _this_test8; - swcHelpers.classPrivateFieldSet(_ref = this.getInstance(), _test, (_this_test = +swcHelpers.classPrivateFieldGet(_ref, _test)) + 1), _this_test; - swcHelpers.classPrivateFieldSet(_ref1 = this.getInstance(), _test, (_this_test5 = +swcHelpers.classPrivateFieldGet(_ref1, _test)) - 1), _this_test5; - swcHelpers.classPrivateFieldSet(_ref2 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref2, _test) + 1); - swcHelpers.classPrivateFieldSet(_ref3 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref3, _test) - 1); - var a = (swcHelpers.classPrivateFieldSet(_ref4 = this.getInstance(), _test, (_this_test6 = +swcHelpers.classPrivateFieldGet(_ref4, _test)) + 1), _this_test6); - var b = (swcHelpers.classPrivateFieldSet(_ref5 = this.getInstance(), _test, (_this_test7 = +swcHelpers.classPrivateFieldGet(_ref5, _test)) - 1), _this_test7); - var c = swcHelpers.classPrivateFieldSet(_ref6 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref6, _test) + 1); - var d = swcHelpers.classPrivateFieldSet(_ref7 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref7, _test) - 1); - for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); swcHelpers.classPrivateFieldGet(_ref8 = this.getInstance(), _test) < 10; swcHelpers.classPrivateFieldSet(_ref9 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref9, _test) + 1)){} - for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); swcHelpers.classPrivateFieldGet(_ref10 = this.getInstance(), _test) < 10; swcHelpers.classPrivateFieldSet(_ref11 = this.getInstance(), _test, (_this_test8 = +swcHelpers.classPrivateFieldGet(_ref11, _test)) + 1), _this_test8){} + var _ref, _ref1; + swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++; + swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value--; + ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value; + --swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value; + var a = swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++; + var b = swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value--; + var c = ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value; + var d = --swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value; + for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); swcHelpers.classPrivateFieldGet(_ref = this.getInstance(), _test) < 10; ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value){} + for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); swcHelpers.classPrivateFieldGet(_ref1 = this.getInstance(), _test) < 10; swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++){} }; _proto.getInstance = function getInstance() { return new C(); diff --git a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es5.2.minified.js index e9d940a0205..997a73ee671 100644 --- a/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameFieldUnaryMutation_es5.2.minified.js @@ -2,18 +2,16 @@ import * as swcHelpers from "@swc/helpers"; var _test = new WeakMap(), C = function() { "use strict"; function C() { - var _this_test; for(swcHelpers.classCallCheck(this, C), swcHelpers.classPrivateFieldInit(this, _test, { writable: !0, value: 24 - }), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1), swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) - 1), swcHelpers.classPrivateFieldSet(this, _test, 0); 10 > swcHelpers.classPrivateFieldGet(this, _test); swcHelpers.classPrivateFieldSet(this, _test, +swcHelpers.classPrivateFieldGet(this, _test) + 1)); - for(swcHelpers.classPrivateFieldSet(this, _test, 0); 10 > swcHelpers.classPrivateFieldGet(this, _test); swcHelpers.classPrivateFieldSet(this, _test, (_this_test = +swcHelpers.classPrivateFieldGet(this, _test)) + 1), _this_test); + }), swcHelpers.classPrivateFieldUpdate(this, _test).value++, swcHelpers.classPrivateFieldUpdate(this, _test).value--, ++swcHelpers.classPrivateFieldUpdate(this, _test).value, --swcHelpers.classPrivateFieldUpdate(this, _test).value, swcHelpers.classPrivateFieldUpdate(this, _test).value++, swcHelpers.classPrivateFieldUpdate(this, _test).value--, ++swcHelpers.classPrivateFieldUpdate(this, _test).value, --swcHelpers.classPrivateFieldUpdate(this, _test).value, swcHelpers.classPrivateFieldSet(this, _test, 0); 10 > swcHelpers.classPrivateFieldGet(this, _test); ++swcHelpers.classPrivateFieldUpdate(this, _test).value); + for(swcHelpers.classPrivateFieldSet(this, _test, 0); 10 > swcHelpers.classPrivateFieldGet(this, _test); swcHelpers.classPrivateFieldUpdate(this, _test).value++); } var _proto = C.prototype; return _proto.test = function() { - var _ref, _ref1, _ref2, _ref3, _ref4, _ref5, _ref6, _ref7, _ref8, _ref9, _this_test; - for(swcHelpers.classPrivateFieldSet(_ref = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref, _test) + 1), swcHelpers.classPrivateFieldSet(_ref1 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref1, _test) - 1), swcHelpers.classPrivateFieldSet(_ref2 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref2, _test) + 1), swcHelpers.classPrivateFieldSet(_ref3 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref3, _test) - 1), swcHelpers.classPrivateFieldSet(_ref4 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref4, _test) + 1), swcHelpers.classPrivateFieldSet(_ref5 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref5, _test) - 1), swcHelpers.classPrivateFieldSet(_ref6 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref6, _test) + 1), swcHelpers.classPrivateFieldSet(_ref7 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref7, _test) - 1), swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); 10 > swcHelpers.classPrivateFieldGet(this.getInstance(), _test); swcHelpers.classPrivateFieldSet(_ref8 = this.getInstance(), _test, +swcHelpers.classPrivateFieldGet(_ref8, _test) + 1)); - for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); 10 > swcHelpers.classPrivateFieldGet(this.getInstance(), _test); swcHelpers.classPrivateFieldSet(_ref9 = this.getInstance(), _test, (_this_test = +swcHelpers.classPrivateFieldGet(_ref9, _test)) + 1), _this_test); + for(swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++, swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value--, ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value, --swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value, swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++, swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value--, ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value, --swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value, swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); 10 > swcHelpers.classPrivateFieldGet(this.getInstance(), _test); ++swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value); + for(swcHelpers.classPrivateFieldSet(this.getInstance(), _test, 0); 10 > swcHelpers.classPrivateFieldGet(this.getInstance(), _test); swcHelpers.classPrivateFieldUpdate(this.getInstance(), _test).value++); }, _proto.getInstance = function() { return new C(); }, C; diff --git a/crates/swc/tests/tsc-references/privateNameMethodAssignment_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameMethodAssignment_es2015.1.normal.js index 191a29c6207..206b3b8a633 100644 --- a/crates/swc/tests/tsc-references/privateNameMethodAssignment_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameMethodAssignment_es2015.1.normal.js @@ -3,7 +3,6 @@ var _method = /*#__PURE__*/ new WeakSet(); // @target: es2015 class A3 { constructor(a, b){ - var _b, _this_method; swcHelpers.classPrivateMethodInit(this, _method); swcHelpers.classPrivateFieldSet(this, _method, ()=>{} // Error, not writable ); @@ -14,7 +13,8 @@ class A3 { x: ()=>{} }); //Error, not writable let x = swcHelpers.classPrivateMethodGet(this, _method, method); - swcHelpers.classPrivateFieldSet(_b = b, _method, (_this_method = +swcHelpers.classPrivateMethodGet(_b, _method, method)) + 1), _this_method; //Error, not writable + swcHelpers.classPrivateFieldUpdate(b, _method).value++ //Error, not writable + ; } } function method() {} diff --git a/crates/swc/tests/tsc-references/privateNameMethodAssignment_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameMethodAssignment_es5.1.normal.js index ca16a47928d..fb53b2b202e 100644 --- a/crates/swc/tests/tsc-references/privateNameMethodAssignment_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameMethodAssignment_es5.1.normal.js @@ -4,7 +4,6 @@ var _method = /*#__PURE__*/ new WeakSet(); var A3 = function A3(a, b) { "use strict"; swcHelpers.classCallCheck(this, A3); - var _b, _this_method; swcHelpers.classPrivateMethodInit(this, _method); swcHelpers.classPrivateFieldSet(this, _method, function() {} // Error, not writable ); @@ -16,6 +15,7 @@ var A3 = function A3(a, b) { x: function() {} }, swcHelpers.classPrivateFieldDestructureSet(this, _method).value = ref.x, ref; //Error, not writable var x = swcHelpers.classPrivateMethodGet(this, _method, method); - swcHelpers.classPrivateFieldSet(_b = b, _method, (_this_method = +swcHelpers.classPrivateMethodGet(_b, _method, method)) + 1), _this_method; //Error, not writable + swcHelpers.classPrivateFieldUpdate(b, _method).value++ //Error, not writable + ; }; function method() {} diff --git a/crates/swc/tests/tsc-references/privateNameMethodAssignment_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameMethodAssignment_es5.2.minified.js index 689a996de4d..02375c32be7 100644 --- a/crates/swc/tests/tsc-references/privateNameMethodAssignment_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameMethodAssignment_es5.2.minified.js @@ -1,9 +1,9 @@ import * as swcHelpers from "@swc/helpers"; var _method = new WeakSet(), A3 = function(a, b) { "use strict"; - var _b, ref; + var ref; swcHelpers.classCallCheck(this, A3), swcHelpers.classPrivateMethodInit(this, _method), swcHelpers.classPrivateFieldSet(this, _method, function() {}), swcHelpers.classPrivateFieldSet(a, _method, function() {}), swcHelpers.classPrivateFieldSet(b, _method, function() {}), ref = { x: function() {} - }, swcHelpers.classPrivateFieldDestructureSet(this, _method).value = ref.x, swcHelpers.classPrivateMethodGet(this, _method, method), swcHelpers.classPrivateFieldSet(_b = b, _method, +swcHelpers.classPrivateMethodGet(_b, _method, method) + 1); + }, swcHelpers.classPrivateFieldDestructureSet(this, _method).value = ref.x, swcHelpers.classPrivateMethodGet(this, _method, method), swcHelpers.classPrivateFieldUpdate(b, _method).value++; }; function method() {} diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es2015.1.normal.js index ec93bb6c0b6..a87c55e77bc 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es2015.1.normal.js @@ -15,32 +15,32 @@ class A { ]; } static test(_a) { - [swcHelpers.classStaticPrivateFieldDestructureSet(_a, _field).value] = [ + [swcHelpers.classStaticPrivateFieldDestructureSet(_a, A, _field).value] = [ 2 ]; } constructor(){ this.otherClass = A; let y; - ({ x: swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value , y } = this.testObject()); - [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value, y] = this.testArray(); - ({ a: swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value , b: [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value] } = { + ({ x: swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value , y } = this.testObject()); + [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value, y] = this.testArray(); + ({ a: swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value , b: [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value] } = { a: 1, b: [ 2 ] }); - [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value, [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value]] = [ + [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value, [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value]] = [ 1, [ 2 ] ]; - ({ a: swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = 1 , b: [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = 1] } = { + ({ a: swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = 1 , b: [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = 1] } = { b: [] }); - [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = 2] = []; - [swcHelpers.classStaticPrivateFieldDestructureSet(this.otherClass, _field).value = 2] = []; + [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = 2] = []; + [swcHelpers.classStaticPrivateFieldDestructureSet(this.otherClass, A, _field).value = 2] = []; } } var _field = { diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es2015.2.minified.js index 1d7ebd62c1a..5d57925cad9 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es2015.2.minified.js @@ -13,26 +13,26 @@ class A { ]; } static test(_a) { - [swcHelpers.classStaticPrivateFieldDestructureSet(_a, _field).value] = [ + [swcHelpers.classStaticPrivateFieldDestructureSet(_a, A, _field).value] = [ 2 ]; } constructor(){ this.otherClass = A; let y; - ({ x: swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value , y } = this.testObject()), [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value, y] = this.testArray(), ({ a: swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value , b: [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value] } = { + ({ x: swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value , y } = this.testObject()), [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value, y] = this.testArray(), ({ a: swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value , b: [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value] } = { a: 1, b: [ 2 ] - }), [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value, [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value]] = [ + }), [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value, [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value]] = [ 1, [ 2 ] - ], ({ a: swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = 1 , b: [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = 1] } = { + ], ({ a: swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = 1 , b: [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = 1] } = { b: [] - }), [swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = 2] = [], [swcHelpers.classStaticPrivateFieldDestructureSet(this.otherClass, _field).value = 2] = []; + }), [swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = 2] = [], [swcHelpers.classStaticPrivateFieldDestructureSet(this.otherClass, A, _field).value = 2] = []; } } var _field = { diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es5.1.normal.js index d7c101124db..5b144a71f07 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es5.1.normal.js @@ -8,28 +8,28 @@ var A = /*#__PURE__*/ function() { this.otherClass = A; var y; var ref; - ref = this.testObject(), swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref.x, y = ref.y, ref; + ref = this.testObject(), swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref.x, y = ref.y, ref; var ref1; - ref1 = swcHelpers.slicedToArray(this.testArray(), 2), swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref1[0], y = ref1[1], ref1; + ref1 = swcHelpers.slicedToArray(this.testArray(), 2), swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref1[0], y = ref1[1], ref1; var ref2, ref3; ref2 = { a: 1, b: [ 2 ] - }, swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref2.a, ref3 = swcHelpers.slicedToArray(ref2.b, 1), swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref3[0], ref3, ref2; + }, swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref2.a, ref3 = swcHelpers.slicedToArray(ref2.b, 1), swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref3[0], ref3, ref2; var ref4; - swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = 1, ref4 = [ + swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = 1, ref4 = [ 2 - ], swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref4[0], ref4; + ], swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref4[0], ref4; var ref5, ref6, ref7, ref8; ref5 = { b: [] - }, ref6 = ref5.a, swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref6 === void 0 ? 1 : ref6, ref7 = swcHelpers.slicedToArray(ref5.b, 1), ref8 = ref7[0], swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref8 === void 0 ? 1 : ref8, ref7, ref5; + }, ref6 = ref5.a, swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref6 === void 0 ? 1 : ref6, ref7 = swcHelpers.slicedToArray(ref5.b, 1), ref8 = ref7[0], swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref8 === void 0 ? 1 : ref8, ref7, ref5; var ref9, ref10; - ref9 = [], ref10 = ref9[0], swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref10 === void 0 ? 2 : ref10, ref9; + ref9 = [], ref10 = ref9[0], swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref10 === void 0 ? 2 : ref10, ref9; var ref11, ref12; - ref11 = [], ref12 = ref11[0], swcHelpers.classStaticPrivateFieldDestructureSet(this.otherClass, _field).value = ref12 === void 0 ? 2 : ref12, ref11; + ref11 = [], ref12 = ref11[0], swcHelpers.classStaticPrivateFieldDestructureSet(this.otherClass, A, _field).value = ref12 === void 0 ? 2 : ref12, ref11; } var _proto = A.prototype; _proto.testObject = function testObject() { @@ -45,7 +45,7 @@ var A = /*#__PURE__*/ function() { ]; }; A.test = function test(_a) { - swcHelpers.classStaticPrivateFieldDestructureSet(_a, _field).value = 2; + swcHelpers.classStaticPrivateFieldDestructureSet(_a, A, _field).value = 2; }; return A; }(); diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es5.2.minified.js index eb8e0e16659..2259bc86542 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldDestructuredBinding_es5.2.minified.js @@ -3,16 +3,16 @@ var A = function() { "use strict"; function A() { var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9; - swcHelpers.classCallCheck(this, A), this.otherClass = A, ref = this.testObject(), swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref.x, ref.y, ref1 = swcHelpers.slicedToArray(this.testArray(), 2), swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref1[0], ref1[1], ref2 = { + swcHelpers.classCallCheck(this, A), this.otherClass = A, ref = this.testObject(), swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref.x, ref.y, ref1 = swcHelpers.slicedToArray(this.testArray(), 2), swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref1[0], ref1[1], ref2 = { a: 1, b: [ 2 ] - }, swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref2.a, ref3 = swcHelpers.slicedToArray(ref2.b, 1), swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref3[0], swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = 1, ref4 = [ + }, swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref2.a, ref3 = swcHelpers.slicedToArray(ref2.b, 1), swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref3[0], swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = 1, ref4 = [ 2 - ], swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = ref4[0], ref6 = (ref5 = { + ], swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = ref4[0], ref6 = (ref5 = { b: [] - }).a, swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = void 0 === ref6 ? 1 : ref6, ref7 = swcHelpers.slicedToArray(ref5.b, 1)[0], swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = void 0 === ref7 ? 1 : ref7, ref8 = void 0, swcHelpers.classStaticPrivateFieldDestructureSet(A, _field).value = void 0 === ref8 ? 2 : ref8, ref9 = void 0, swcHelpers.classStaticPrivateFieldDestructureSet(this.otherClass, _field).value = void 0 === ref9 ? 2 : ref9; + }).a, swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = void 0 === ref6 ? 1 : ref6, ref7 = swcHelpers.slicedToArray(ref5.b, 1)[0], swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = void 0 === ref7 ? 1 : ref7, ref8 = void 0, swcHelpers.classStaticPrivateFieldDestructureSet(A, A, _field).value = void 0 === ref8 ? 2 : ref8, ref9 = void 0, swcHelpers.classStaticPrivateFieldDestructureSet(this.otherClass, A, _field).value = void 0 === ref9 ? 2 : ref9; } var _proto = A.prototype; return _proto.testObject = function() { @@ -26,7 +26,7 @@ var A = function() { 11 ]; }, A.test = function(_a) { - swcHelpers.classStaticPrivateFieldDestructureSet(_a, _field).value = 2; + swcHelpers.classStaticPrivateFieldDestructureSet(_a, A, _field).value = 2; }, A; }(), _field = { writable: !0, diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es2015.1.normal.js index 05ef5c690eb..f756ae74787 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es2015.1.normal.js @@ -2,33 +2,31 @@ import * as swcHelpers from "@swc/helpers"; // @target: es2015 class C { test() { - var _this_test, _this_test1, _this_test2, _this_test3, _this_test4; - swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) + 1), _this_test; - swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test1 = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) - 1), _this_test1; - swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1); - swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1); - const a = (swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test2 = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) + 1), _this_test2); - const b = (swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test3 = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) - 1), _this_test3); - const c = swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1); - const d = swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1); - for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) < 10; swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1)){} - for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) < 10; swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test4 = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) + 1), _this_test4){} + swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++; + swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value--; + ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value; + --swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value; + const a = swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++; + const b = swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value--; + const c = ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value; + const d = --swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value; + for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) < 10; ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value){} + for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) < 10; swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++){} } getClass() { return C; } constructor(){ - var _this_test, _this_test5, _this_test6, _this_test7, _this_test8; - swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) + 1), _this_test; - swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test5 = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) - 1), _this_test5; - swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1); - swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1); - const a = (swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test6 = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) + 1), _this_test6); - const b = (swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test7 = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) - 1), _this_test7); - const c = swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1); - const d = swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1); - for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) < 10; swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1)){} - for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) < 10; swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test8 = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) + 1), _this_test8){} + swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++; + swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value--; + ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value; + --swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value; + const a = swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++; + const b = swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value--; + const c = ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value; + const d = --swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value; + for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) < 10; ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value){} + for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) < 10; swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++){} } } var _test = { diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es2015.2.minified.js index e1304cf100e..de1f14fa5f2 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es2015.2.minified.js @@ -1,17 +1,15 @@ import * as swcHelpers from "@swc/helpers"; class C { test() { - var _this_test; - for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test); swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1)); - for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test); swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) + 1), _this_test); + for(swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++, swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value--, ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value, --swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value, swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++, swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value--, ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value, --swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value, swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test); ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value); + for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test); swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++); } getClass() { return C; } constructor(){ - var _this_test; - for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test); swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1)); - for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test); swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) + 1), _this_test); + for(swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++, swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value--, ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value, --swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value, swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++, swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value--, ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value, --swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value, swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test); ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value); + for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test); swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++); } } var _test = { diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es5.1.normal.js index 4cf15dcc19c..b078d74ede9 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es5.1.normal.js @@ -4,31 +4,29 @@ var C = /*#__PURE__*/ function() { "use strict"; function C() { swcHelpers.classCallCheck(this, C); - var _this_test, _this_test1, _this_test2, _this_test3, _this_test4; - swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) + 1), _this_test; - swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test1 = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) - 1), _this_test1; - swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1); - swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1); - var a = (swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test2 = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) + 1), _this_test2); - var b = (swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test3 = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) - 1), _this_test3); - var c = swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1); - var d = swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1); - for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) < 10; swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1)){} - for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) < 10; swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test4 = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) + 1), _this_test4){} + swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++; + swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value--; + ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value; + --swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value; + var a = swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++; + var b = swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value--; + var c = ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value; + var d = --swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value; + for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) < 10; ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value){} + for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) < 10; swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++){} } var _proto = C.prototype; _proto.test = function test() { - var _this_test, _this_test5, _this_test6, _this_test7, _this_test8; - swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) + 1), _this_test; - swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test5 = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) - 1), _this_test5; - swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1); - swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1); - var a = (swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test6 = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) + 1), _this_test6); - var b = (swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test7 = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) - 1), _this_test7); - var c = swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1); - var d = swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1); - for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) < 10; swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1)){} - for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) < 10; swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test8 = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) + 1), _this_test8){} + swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++; + swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value--; + ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value; + --swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value; + var a = swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++; + var b = swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value--; + var c = ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value; + var d = --swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value; + for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) < 10; ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value){} + for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) < 10; swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++){} }; _proto.getClass = function getClass() { return C; diff --git a/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es5.2.minified.js index 83085f88e9e..1ae933e5e72 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticFieldUnaryMutation_es5.2.minified.js @@ -2,15 +2,13 @@ import * as swcHelpers from "@swc/helpers"; var C = function() { "use strict"; function C() { - var _this_test; - for(swcHelpers.classCallCheck(this, C), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test); swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test) + 1)); - for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test); swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, (_this_test = +swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test)) + 1), _this_test); + for(swcHelpers.classCallCheck(this, C), swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++, swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value--, ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value, --swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value, swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++, swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value--, ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value, --swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value, swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test); ++swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value); + for(swcHelpers.classStaticPrivateFieldSpecSet(C, C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(C, C, _test); swcHelpers.classStaticPrivateFieldUpdate(C, C, _test).value++); } var _proto = C.prototype; return _proto.test = function() { - var _this_test; - for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) - 1), swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test); swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test) + 1)); - for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test); swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, (_this_test = +swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test)) + 1), _this_test); + for(swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++, swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value--, ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value, --swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value, swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++, swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value--, ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value, --swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value, swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test); ++swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value); + for(swcHelpers.classStaticPrivateFieldSpecSet(this.getClass(), C, _test, 0); 10 > swcHelpers.classStaticPrivateFieldSpecGet(this.getClass(), C, _test); swcHelpers.classStaticPrivateFieldUpdate(this.getClass(), C, _test).value++); }, _proto.getClass = function() { return C; }, C; diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es2015.1.normal.js index db0900ad1f3..8ad5d8f8dc1 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es2015.1.normal.js @@ -2,17 +2,17 @@ import * as swcHelpers from "@swc/helpers"; // @target: es2015 class A3 { constructor(a, b){ - var _this_method; swcHelpers.classStaticPrivateFieldSpecSet(A3, A3, _method, ()=>{} // Error, not writable ); swcHelpers.classStaticPrivateFieldSpecSet(a, A3, _method, ()=>{}); // Error, not writable swcHelpers.classStaticPrivateFieldSpecSet(b, A3, _method, ()=>{} //Error, not writable ); - ({ x: swcHelpers.classStaticPrivateFieldDestructureSet(A3, _method).value } = { + ({ x: swcHelpers.classStaticPrivateFieldDestructureSet(A3, A3, _method).value } = { x: ()=>{} }); //Error, not writable let x = swcHelpers.classStaticPrivateMethodGet(A3, A3, method); - swcHelpers.classStaticPrivateFieldSpecSet(b, A3, _method, (_this_method = +swcHelpers.classStaticPrivateMethodGet(b, A3, method)) + 1), _this_method; //Error, not writable + swcHelpers.classStaticPrivateFieldUpdate(b, A3, _method).value++ //Error, not writable + ; } } function method() {} diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es2015.2.minified.js index f3e48e3c759..fea7003c40d 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es2015.2.minified.js @@ -1,9 +1,8 @@ import * as swcHelpers from "@swc/helpers"; class A3 { constructor(a, b){ - swcHelpers.classStaticPrivateFieldSpecSet(A3, A3, _method, ()=>{}), swcHelpers.classStaticPrivateFieldSpecSet(a, A3, _method, ()=>{}), swcHelpers.classStaticPrivateFieldSpecSet(b, A3, _method, ()=>{}), ({ x: swcHelpers.classStaticPrivateFieldDestructureSet(A3, _method).value } = { + swcHelpers.classStaticPrivateFieldSpecSet(A3, A3, _method, ()=>{}), swcHelpers.classStaticPrivateFieldSpecSet(a, A3, _method, ()=>{}), swcHelpers.classStaticPrivateFieldSpecSet(b, A3, _method, ()=>{}), ({ x: swcHelpers.classStaticPrivateFieldDestructureSet(A3, A3, _method).value } = { x () {} - }), swcHelpers.classStaticPrivateMethodGet(A3, A3, method), swcHelpers.classStaticPrivateFieldSpecSet(b, A3, _method, +swcHelpers.classStaticPrivateMethodGet(b, A3, method) + 1); + }), swcHelpers.classStaticPrivateMethodGet(A3, A3, function() {}), swcHelpers.classStaticPrivateFieldUpdate(b, A3, _method).value++; } } -function method() {} diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es5.1.normal.js index cdc3ec2cba8..3834eed146f 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es5.1.normal.js @@ -3,7 +3,6 @@ import * as swcHelpers from "@swc/helpers"; var A3 = function A3(a, b) { "use strict"; swcHelpers.classCallCheck(this, A3); - var _this_method; swcHelpers.classStaticPrivateFieldSpecSet(A3, A3, _method, function() {} // Error, not writable ); swcHelpers.classStaticPrivateFieldSpecSet(a, A3, _method, function() {}); // Error, not writable @@ -12,8 +11,9 @@ var A3 = function A3(a, b) { var ref; ref = { x: function() {} - }, swcHelpers.classStaticPrivateFieldDestructureSet(A3, _method).value = ref.x, ref; //Error, not writable + }, swcHelpers.classStaticPrivateFieldDestructureSet(A3, A3, _method).value = ref.x, ref; //Error, not writable var x = swcHelpers.classStaticPrivateMethodGet(A3, A3, method); - swcHelpers.classStaticPrivateFieldSpecSet(b, A3, _method, (_this_method = +swcHelpers.classStaticPrivateMethodGet(b, A3, method)) + 1), _this_method; //Error, not writable + swcHelpers.classStaticPrivateFieldUpdate(b, A3, _method).value++ //Error, not writable + ; }; function method() {} diff --git a/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es5.2.minified.js index cf1303bee9c..cb6df43cad2 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticMethodAssignment_es5.2.minified.js @@ -4,6 +4,6 @@ var A3 = function(a, b) { var ref; swcHelpers.classCallCheck(this, A3), swcHelpers.classStaticPrivateFieldSpecSet(A3, A3, _method, function() {}), swcHelpers.classStaticPrivateFieldSpecSet(a, A3, _method, function() {}), swcHelpers.classStaticPrivateFieldSpecSet(b, A3, _method, function() {}), ref = { x: function() {} - }, swcHelpers.classStaticPrivateFieldDestructureSet(A3, _method).value = ref.x, swcHelpers.classStaticPrivateMethodGet(A3, A3, method), swcHelpers.classStaticPrivateFieldSpecSet(b, A3, _method, +swcHelpers.classStaticPrivateMethodGet(b, A3, method) + 1); + }, swcHelpers.classStaticPrivateFieldDestructureSet(A3, A3, _method).value = ref.x, swcHelpers.classStaticPrivateMethodGet(A3, A3, method), swcHelpers.classStaticPrivateFieldUpdate(b, A3, _method).value++; }; function method() {} diff --git a/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es2015.1.normal.js index 9058215e5b6..dec455d9bd6 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es2015.1.normal.js @@ -5,12 +5,11 @@ import * as swcHelpers from "@swc/helpers"; // @useDefineForClassFields: false class A { constructor(){ - var _this_quux; swcHelpers.classStaticPrivateMethodGet(A, A, foo).call(A, 30); swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30); swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30); swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1); - swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, (_this_quux = +swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux)) + 1), _this_quux; + swcHelpers.classStaticPrivateFieldUpdate(A, A, _quux).value++; } } var _quux = { diff --git a/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es2015.2.minified.js index 40b9a9dd10c..1aa273424e6 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es2015.2.minified.js @@ -1,7 +1,7 @@ import * as swcHelpers from "@swc/helpers"; class A { constructor(){ - swcHelpers.classStaticPrivateMethodGet(A, A, function(a) {}).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, +swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1); + swcHelpers.classStaticPrivateMethodGet(A, A, function(a) {}).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1), swcHelpers.classStaticPrivateFieldUpdate(A, A, _quux).value++; } } var _quux = { diff --git a/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es5.1.normal.js index 760c33f4ed4..450380b4814 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es5.1.normal.js @@ -7,12 +7,11 @@ import regeneratorRuntime from "regenerator-runtime"; var A = function A() { "use strict"; swcHelpers.classCallCheck(this, A); - var _this_quux; swcHelpers.classStaticPrivateMethodGet(A, A, foo).call(A, 30); swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30); swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30); swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1); - swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, (_this_quux = +swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux)) + 1), _this_quux; + swcHelpers.classStaticPrivateFieldUpdate(A, A, _quux).value++; }; var _quux = { get: get_quux, diff --git a/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es5.2.minified.js index caac2cc4437..ac43fe1ece0 100644 --- a/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNameStaticsAndStaticMethods_es5.2.minified.js @@ -2,7 +2,7 @@ import * as swcHelpers from "@swc/helpers"; import regeneratorRuntime from "regenerator-runtime"; var A = function() { "use strict"; - swcHelpers.classCallCheck(this, A), swcHelpers.classStaticPrivateMethodGet(A, A, foo).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, +swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1); + swcHelpers.classCallCheck(this, A), swcHelpers.classStaticPrivateMethodGet(A, A, foo).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1), swcHelpers.classStaticPrivateFieldUpdate(A, A, _quux).value++; }, _quux = { get: function() { return swcHelpers.classStaticPrivateFieldSpecGet(this, A, __quux); diff --git a/crates/swc/tests/tsc-references/privateNamesAndMethods_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNamesAndMethods_es2015.1.normal.js index 2aa0e28be36..075d7260e92 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndMethods_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesAndMethods_es2015.1.normal.js @@ -5,7 +5,6 @@ var _foo = /*#__PURE__*/ new WeakSet(), _bar = /*#__PURE__*/ new WeakSet(), _baz // @useDefineForClassFields: false class A { constructor(){ - var _this_quux; swcHelpers.classPrivateMethodInit(this, _foo); swcHelpers.classPrivateMethodInit(this, _bar); swcHelpers.classPrivateMethodInit(this, _baz); @@ -21,7 +20,7 @@ class A { swcHelpers.classPrivateMethodGet(this, _bar, bar).call(this, 30); swcHelpers.classPrivateMethodGet(this, _baz, baz).call(this, 30); swcHelpers.classPrivateFieldSet(this, _quux, swcHelpers.classPrivateFieldGet(this, _quux) + 1); - swcHelpers.classPrivateFieldSet(this, _quux, (_this_quux = +swcHelpers.classPrivateFieldGet(this, _quux)) + 1), _this_quux; + swcHelpers.classPrivateFieldUpdate(this, _quux).value++; } } function foo(a) {} diff --git a/crates/swc/tests/tsc-references/privateNamesAndMethods_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNamesAndMethods_es5.1.normal.js index 927080e3aa5..e58c30efb9f 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndMethods_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesAndMethods_es5.1.normal.js @@ -7,7 +7,6 @@ var _foo = /*#__PURE__*/ new WeakSet(), _bar = /*#__PURE__*/ new WeakSet(), _baz var A = function A() { "use strict"; swcHelpers.classCallCheck(this, A); - var _this_quux; swcHelpers.classPrivateMethodInit(this, _foo); swcHelpers.classPrivateMethodInit(this, _bar); swcHelpers.classPrivateMethodInit(this, _baz); @@ -23,7 +22,7 @@ var A = function A() { swcHelpers.classPrivateMethodGet(this, _bar, bar).call(this, 30); swcHelpers.classPrivateMethodGet(this, _baz, baz).call(this, 30); swcHelpers.classPrivateFieldSet(this, _quux, swcHelpers.classPrivateFieldGet(this, _quux) + 1); - swcHelpers.classPrivateFieldSet(this, _quux, (_this_quux = +swcHelpers.classPrivateFieldGet(this, _quux)) + 1), _this_quux; + swcHelpers.classPrivateFieldUpdate(this, _quux).value++; }; function foo(a) {} function bar(a) { diff --git a/crates/swc/tests/tsc-references/privateNamesAndMethods_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNamesAndMethods_es5.2.minified.js index a77635d1cd1..c8c7907917f 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndMethods_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNamesAndMethods_es5.2.minified.js @@ -8,7 +8,7 @@ var _foo = new WeakSet(), _bar = new WeakSet(), _baz = new WeakSet(), __quux = n }), swcHelpers.classPrivateFieldInit(this, __quux, { writable: !0, value: void 0 - }), swcHelpers.classPrivateMethodGet(this, _foo, foo).call(this, 30), swcHelpers.classPrivateMethodGet(this, _bar, bar).call(this, 30), swcHelpers.classPrivateMethodGet(this, _baz, baz).call(this, 30), swcHelpers.classPrivateFieldSet(this, _quux, swcHelpers.classPrivateFieldGet(this, _quux) + 1), swcHelpers.classPrivateFieldSet(this, _quux, +swcHelpers.classPrivateFieldGet(this, _quux) + 1); + }), swcHelpers.classPrivateMethodGet(this, _foo, foo).call(this, 30), swcHelpers.classPrivateMethodGet(this, _bar, bar).call(this, 30), swcHelpers.classPrivateMethodGet(this, _baz, baz).call(this, 30), swcHelpers.classPrivateFieldSet(this, _quux, swcHelpers.classPrivateFieldGet(this, _quux) + 1), swcHelpers.classPrivateFieldUpdate(this, _quux).value++; }; function foo(a) {} function bar(a) { diff --git a/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es2015.1.normal.js b/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es2015.1.normal.js index 9058215e5b6..dec455d9bd6 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es2015.1.normal.js @@ -5,12 +5,11 @@ import * as swcHelpers from "@swc/helpers"; // @useDefineForClassFields: false class A { constructor(){ - var _this_quux; swcHelpers.classStaticPrivateMethodGet(A, A, foo).call(A, 30); swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30); swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30); swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1); - swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, (_this_quux = +swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux)) + 1), _this_quux; + swcHelpers.classStaticPrivateFieldUpdate(A, A, _quux).value++; } } var _quux = { diff --git a/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es2015.2.minified.js b/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es2015.2.minified.js index 40b9a9dd10c..1aa273424e6 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es2015.2.minified.js @@ -1,7 +1,7 @@ import * as swcHelpers from "@swc/helpers"; class A { constructor(){ - swcHelpers.classStaticPrivateMethodGet(A, A, function(a) {}).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, +swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1); + swcHelpers.classStaticPrivateMethodGet(A, A, function(a) {}).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1), swcHelpers.classStaticPrivateFieldUpdate(A, A, _quux).value++; } } var _quux = { diff --git a/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es5.1.normal.js b/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es5.1.normal.js index 760c33f4ed4..450380b4814 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es5.1.normal.js @@ -7,12 +7,11 @@ import regeneratorRuntime from "regenerator-runtime"; var A = function A() { "use strict"; swcHelpers.classCallCheck(this, A); - var _this_quux; swcHelpers.classStaticPrivateMethodGet(A, A, foo).call(A, 30); swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30); swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30); swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1); - swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, (_this_quux = +swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux)) + 1), _this_quux; + swcHelpers.classStaticPrivateFieldUpdate(A, A, _quux).value++; }; var _quux = { get: get_quux, diff --git a/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es5.2.minified.js b/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es5.2.minified.js index caac2cc4437..ac43fe1ece0 100644 --- a/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/privateNamesAndStaticMethods_es5.2.minified.js @@ -2,7 +2,7 @@ import * as swcHelpers from "@swc/helpers"; import regeneratorRuntime from "regenerator-runtime"; var A = function() { "use strict"; - swcHelpers.classCallCheck(this, A), swcHelpers.classStaticPrivateMethodGet(A, A, foo).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, +swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1); + swcHelpers.classCallCheck(this, A), swcHelpers.classStaticPrivateMethodGet(A, A, foo).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateMethodGet(A, A, bar).call(A, 30), swcHelpers.classStaticPrivateFieldSpecSet(A, A, _quux, swcHelpers.classStaticPrivateFieldSpecGet(A, A, _quux) + 1), swcHelpers.classStaticPrivateFieldUpdate(A, A, _quux).value++; }, _quux = { get: function() { return swcHelpers.classStaticPrivateFieldSpecGet(this, A, __quux); diff --git a/crates/swc_ecma_transforms_base/src/helpers/_class_apply_descriptor_update.js b/crates/swc_ecma_transforms_base/src/helpers/_class_apply_descriptor_update.js new file mode 100644 index 00000000000..db089b33ee2 --- /dev/null +++ b/crates/swc_ecma_transforms_base/src/helpers/_class_apply_descriptor_update.js @@ -0,0 +1,23 @@ +function _classApplyDescriptorUpdate(receiver, descriptor) { + if (descriptor.set) { + if (!("__destrWrapper" in descriptor)) { + descriptor.__destrWrapper = { + set value(v) { + descriptor.set.call(receiver, v); + }, + get value() { + return descriptor.get.call(receiver); + }, + }; + } + return descriptor.__destrWrapper; + } else { + if (!descriptor.writable) { + // This should only throw in strict mode, but class bodies are + // always strict and private fields can only be used inside + // class bodies. + throw new TypeError("attempted to set read only private field"); + } + return descriptor; + } +} diff --git a/crates/swc_ecma_transforms_base/src/helpers/_class_private_field_update.js b/crates/swc_ecma_transforms_base/src/helpers/_class_private_field_update.js new file mode 100644 index 00000000000..2ea969d7b27 --- /dev/null +++ b/crates/swc_ecma_transforms_base/src/helpers/_class_private_field_update.js @@ -0,0 +1,4 @@ +function _classPrivateFieldUpdate(receiver, privateMap) { + var descriptor = _classExtractFieldDescriptor( receiver, privateMap, "update"); + return _classApplyDescriptorUpdate(receiver, descriptor); +} diff --git a/crates/swc_ecma_transforms_base/src/helpers/_class_static_private_field_update.js b/crates/swc_ecma_transforms_base/src/helpers/_class_static_private_field_update.js new file mode 100644 index 00000000000..8f5fbb69e72 --- /dev/null +++ b/crates/swc_ecma_transforms_base/src/helpers/_class_static_private_field_update.js @@ -0,0 +1,5 @@ +function _classStaticPrivateFieldUpdate(receiver, classConstructor, descriptor) { + _classCheckPrivateStaticAccess(receiver, classConstructor); + _classCheckPrivateStaticFieldDescriptor(descriptor, "update"); + return _classApplyDescriptorUpdate(receiver, descriptor); +} diff --git a/crates/swc_ecma_transforms_base/src/helpers/mod.rs b/crates/swc_ecma_transforms_base/src/helpers/mod.rs index 2a00a07eba7..0205e297826 100644 --- a/crates/swc_ecma_transforms_base/src/helpers/mod.rs +++ b/crates/swc_ecma_transforms_base/src/helpers/mod.rs @@ -186,6 +186,7 @@ define_helpers!(Helpers { class_apply_descriptor_destructure: (), class_apply_descriptor_get: (), class_apply_descriptor_set: (), + class_apply_descriptor_update: (), class_call_check: (), class_check_private_static_field_descriptor: (), class_extract_field_descriptor: (), @@ -195,6 +196,10 @@ define_helpers!(Helpers { class_private_field_loose_base: (), class_private_field_loose_key: (), class_private_field_set: (class_extract_field_descriptor, class_apply_descriptor_set), + class_private_field_update: ( + class_extract_field_descriptor, + class_apply_descriptor_update + ), class_private_method_get: (), class_private_method_init: (check_private_redeclaration), class_private_method_set: (), @@ -208,6 +213,11 @@ define_helpers!(Helpers { class_check_private_static_field_descriptor, class_apply_descriptor_set ), + class_static_private_field_update: ( + class_check_private_static_access, + class_check_private_static_field_descriptor, + class_apply_descriptor_update + ), construct: (set_prototype_of), create_class: (), decorate: (to_array, to_property_key), diff --git a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs index d2b64b9730b..05866a069e3 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/mod.rs @@ -880,7 +880,7 @@ impl ClassProperties { private_method_fn_decls.visit_mut_with(&mut PrivateAccessVisitor { private: &self.private, vars: vec![], - in_assign_pat: false, + private_access_type: Default::default(), c: self.c, }); @@ -891,7 +891,7 @@ impl ClassProperties { members.visit_mut_with(&mut PrivateAccessVisitor { private: &self.private, vars: vec![], - in_assign_pat: false, + private_access_type: Default::default(), c: self.c, }); diff --git a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/private_field.rs b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/private_field.rs index 1220af3b2d6..5ac7bb4db09 100644 --- a/crates/swc_ecma_transforms_compat/src/es2022/class_properties/private_field.rs +++ b/crates/swc_ecma_transforms_compat/src/es2022/class_properties/private_field.rs @@ -143,10 +143,23 @@ impl VisitMut for BrandCheckHandler<'_> { } } +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub(super) enum PrivateAccessType { + Get, + DestructureSet, + Update, +} + +impl Default for PrivateAccessType { + fn default() -> Self { + Self::Get + } +} + pub(super) struct PrivateAccessVisitor<'a> { pub vars: Vec, pub private: &'a PrivateRecord, - pub in_assign_pat: bool, + pub private_access_type: PrivateAccessType, pub c: Config, } @@ -214,138 +227,12 @@ impl<'a> VisitMut for PrivateAccessVisitor<'a> { } match e { - Expr::Update(UpdateExpr { - span, - prefix, - op, - arg, - }) if arg.is_member() => { - let mut arg = arg.take().member().unwrap(); + Expr::Update(UpdateExpr { arg, .. }) if arg.is_member() => { + let old_access_type = self.private_access_type; + + self.private_access_type = PrivateAccessType::Update; arg.visit_mut_with(self); - - let n = match &arg.prop { - MemberProp::PrivateName(n) => n, - _ => { - *e = Expr::Update(UpdateExpr { - span: *span, - prefix: *prefix, - op: *op, - arg: Box::new(Expr::Member(arg)), - }); - e.visit_mut_children_with(self); - return; - } - }; - - let obj = arg.obj.clone(); - - let (mark, kind, class_name) = self.private.get(&n.id); - if mark == Mark::root() { - return; - } - - let ident = Ident::new(format!("_{}", n.id.sym).into(), n.id.span.apply_mark(mark)); - - let var = alias_ident_for(&obj, "_ref"); - - let this = if matches!(*obj, Expr::This(..)) { - ThisExpr { span: DUMMY_SP }.as_arg() - } else if kind.is_static { - obj.as_arg() - } else { - self.vars.push(VarDeclarator { - span: DUMMY_SP, - name: var.clone().into(), - init: None, - definite: false, - }); - AssignExpr { - span: obj.span(), - left: PatOrExpr::Pat(var.clone().into()), - op: op!("="), - right: obj, - } - .as_arg() - }; - // Used iff !prefix - let old_var = Ident { - // be more like babel - sym: (String::from("_this") + &ident.sym).into(), - span: ident.span.apply_mark(Mark::fresh(Mark::root())), - optional: false, - }; - if !*prefix { - self.vars.push(VarDeclarator { - span: DUMMY_SP, - name: old_var.clone().into(), - init: None, - definite: false, - }); - } - - let value = { - let arg = Box::new(self.visit_mut_private_get(&mut arg, Some(var)).0); - let left = Box::new(Expr::Unary(UnaryExpr { - span: DUMMY_SP, - op: op!(unary, "+"), - arg, - })); - let left = if *prefix { - left - } else { - Box::new(Expr::Assign(AssignExpr { - span: DUMMY_SP, - left: PatOrExpr::Pat(old_var.clone().into()), - op: op!("="), - right: left, - })) - }; - - BinExpr { - span: DUMMY_SP, - left, - op: match op { - op!("++") => op!(bin, "+"), - op!("--") => op!(bin, "-"), - }, - right: Box::new(Expr::Lit(Lit::Num(Number { - span: DUMMY_SP, - value: 1.0, - raw: None, - }))), - } - .as_arg() - }; - - let expr = if kind.is_static { - Expr::Call(CallExpr { - span: DUMMY_SP, - callee: helper!( - class_static_private_field_spec_set, - "classStaticPrivateFieldSpecSet" - ), - args: vec![this, class_name.clone().as_arg(), ident.as_arg(), value], - - type_args: Default::default(), - }) - } else { - Expr::Call(CallExpr { - span: DUMMY_SP, - callee: helper!(class_private_field_set, "classPrivateFieldSet"), - args: vec![this, ident.as_arg(), value], - - type_args: Default::default(), - }) - }; - - if *prefix { - *e = expr; - } else { - *e = Expr::Seq(SeqExpr { - span: DUMMY_SP, - exprs: vec![Box::new(expr), Box::new(Expr::Ident(old_var))], - }); - } + self.private_access_type = old_access_type; } Expr::Assign(AssignExpr { @@ -449,9 +336,11 @@ impl<'a> VisitMut for PrivateAccessVisitor<'a> { .. }) => { right.visit_mut_with(self); - self.in_assign_pat = true; + let old_access_type = self.private_access_type; + + self.private_access_type = PrivateAccessType::DestructureSet; left.visit_mut_with(self); - self.in_assign_pat = false; + self.private_access_type = old_access_type; } // Actually this is a call and we should bind `this`. @@ -596,16 +485,17 @@ impl<'a> VisitMut for PrivateAccessVisitor<'a> { if let Pat::Expr(expr) = &p { if let Expr::Member(me) = &**expr { if let MemberProp::PrivateName(..) = &me.prop { - self.in_assign_pat = true; + let old_access_type = self.private_access_type; + self.private_access_type = PrivateAccessType::DestructureSet; p.visit_mut_children_with(self); - self.in_assign_pat = false; + self.private_access_type = old_access_type; return; } } } - self.in_assign_pat = false; + self.private_access_type = Default::default(); p.visit_mut_children_with(self); } } @@ -618,7 +508,7 @@ pub(super) fn visit_private_in_expr( let mut priv_visitor = PrivateAccessVisitor { private, vars: vec![], - in_assign_pat: false, + private_access_type: Default::default(), c: config, }; @@ -659,23 +549,52 @@ impl<'a> PrivateAccessVisitor<'a> { let ident = Ident::new(format!("_{}", n.id.sym).into(), n.id.span.apply_mark(mark)); if kind.is_static { - if self.in_assign_pat { - let set = helper!( - class_static_private_field_destructure, - "classStaticPrivateFieldDestructureSet" - ); + match self.private_access_type { + PrivateAccessType::DestructureSet => { + let set = helper!( + class_static_private_field_destructure, + "classStaticPrivateFieldDestructureSet" + ); - return ( - CallExpr { - span: DUMMY_SP, - callee: set, - args: vec![obj.clone().as_arg(), ident.as_arg()], + return ( + CallExpr { + span: DUMMY_SP, + callee: set, + args: vec![ + obj.clone().as_arg(), + class_name.clone().as_arg(), + ident.as_arg(), + ], - type_args: Default::default(), - } - .make_member(quote_ident!("value")), - Some(*obj), - ); + type_args: Default::default(), + } + .make_member(quote_ident!("value")), + Some(*obj), + ); + } + PrivateAccessType::Update => { + let set = helper!( + class_static_private_field_update, + "classStaticPrivateFieldUpdate" + ); + + return ( + CallExpr { + span: DUMMY_SP, + callee: set, + args: vec![ + obj.clone().as_arg(), + class_name.clone().as_arg(), + ident.as_arg(), + ], + + type_args: Default::default(), + } + .make_member(quote_ident!("value")), + Some(*obj), + ); + } + _ => {} } if kind.is_method() { @@ -714,23 +633,41 @@ impl<'a> PrivateAccessVisitor<'a> { Some(Expr::Ident(class_name.clone())), ) } else { - if self.in_assign_pat { - let set = helper!( - class_private_field_destructure, - "classPrivateFieldDestructureSet" - ); + match self.private_access_type { + PrivateAccessType::DestructureSet => { + let set = helper!( + class_private_field_destructure, + "classPrivateFieldDestructureSet" + ); - return ( - CallExpr { - span: DUMMY_SP, - callee: set, - args: vec![obj.clone().as_arg(), ident.as_arg()], + return ( + CallExpr { + span: DUMMY_SP, + callee: set, + args: vec![obj.clone().as_arg(), ident.as_arg()], - type_args: Default::default(), - } - .make_member(quote_ident!("value")), - Some(*obj), - ); + type_args: Default::default(), + } + .make_member(quote_ident!("value")), + Some(*obj), + ); + } + PrivateAccessType::Update => { + let set = helper!(class_private_field_update, "classPrivateFieldUpdate"); + + return ( + CallExpr { + span: DUMMY_SP, + callee: set, + args: vec![obj.clone().as_arg(), ident.as_arg()], + + type_args: Default::default(), + } + .make_member(quote_ident!("value")), + Some(*obj), + ); + } + _ => {} } let get = if self.c.private_as_properties { diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/exec.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/exec.js new file mode 100644 index 00000000000..962724a5e53 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/exec.js @@ -0,0 +1,38 @@ +class A { + #a = 1n; + static #b = 2n; + + get #c() { + return this.#a; + } + set #c(v) { + this.#a = v; + } + + static get #d() { + return this.#b; + } + static set #d(v) { + this.#b = v; + } + + foo() { + let a = this.#a++; + a = ++this.#a; + let b = this.#c++; + b = ++this.#c; + console.log(a, b); + } + + static bar() { + let d = this.#d++; + d = ++this.#d; + let e = A.#d++; + e = ++A.#d; + console.log(d, e); + } +} + +const a = new A(); +a.foo(); +A.bar(); diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/input.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/input.js new file mode 100644 index 00000000000..962724a5e53 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/input.js @@ -0,0 +1,38 @@ +class A { + #a = 1n; + static #b = 2n; + + get #c() { + return this.#a; + } + set #c(v) { + this.#a = v; + } + + static get #d() { + return this.#b; + } + static set #d(v) { + this.#b = v; + } + + foo() { + let a = this.#a++; + a = ++this.#a; + let b = this.#c++; + b = ++this.#c; + console.log(a, b); + } + + static bar() { + let d = this.#d++; + d = ++this.#d; + let e = A.#d++; + e = ++A.#d; + console.log(d, e); + } +} + +const a = new A(); +a.foo(); +A.bar(); diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/output.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/output.js new file mode 100644 index 00000000000..7c9c5b9a1e1 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-3700/output.js @@ -0,0 +1,62 @@ +var _a = /*#__PURE__*/ new WeakMap(), _c = /*#__PURE__*/ new WeakMap(); +let A = /*#__PURE__*/ function() { + "use strict"; + function A() { + _classCallCheck(this, A); + _classPrivateFieldInit(this, _c, { + get: get_c, + set: set_c + }); + _classPrivateFieldInit(this, _a, { + writable: true, + value: 1n + }); + } + _createClass(A, [ + { + key: "foo", + value: function foo() { + let a = _classPrivateFieldUpdate(this, _a).value++; + a = ++_classPrivateFieldUpdate(this, _a).value; + let b = _classPrivateFieldUpdate(this, _c).value++; + b = ++_classPrivateFieldUpdate(this, _c).value; + console.log(a, b); + } + } + ], [ + { + key: "bar", + value: function bar() { + let d = _classStaticPrivateFieldUpdate(this, A, _d).value++; + d = ++_classStaticPrivateFieldUpdate(this, A, _d).value; + let e = _classStaticPrivateFieldUpdate(A, A, _d).value++; + e = ++_classStaticPrivateFieldUpdate(A, A, _d).value; + console.log(d, e); + } + } + ]); + return A; +}(); +var _d = { + get: get_d, + set: set_d +}; +var _b = { + writable: true, + value: 2n +}; +function get_c() { + return _classPrivateFieldGet(this, _a); +} +function set_c(v) { + _classPrivateFieldSet(this, _a, v); +} +function get_d() { + return _classStaticPrivateFieldSpecGet(this, A, _b); +} +function set_d(v) { + _classStaticPrivateFieldSpecSet(this, A, _b, v); +} +const a = new A(); +a.foo(); +A.bar(); diff --git a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs index 2cce90f1ba9..c598a81deea 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2022_class_properties.rs @@ -1485,32 +1485,27 @@ class Foo { "#, r#" var _foo = new WeakMap(); -var Foo = -/*#__PURE__*/ -function () { - "use strict"; - - function Foo() { - _classCallCheck(this, Foo); - - _classPrivateFieldInit(this, _foo, { - writable: true, - value: 0 - }); - } - - _createClass(Foo, [{ - key: "test", - value: function test(other) { - var _this_foo, _obj, _this_foo1, _obj1; - - _classPrivateFieldSet(this, _foo, (_this_foo = +_classPrivateFieldGet(this, _foo)) + 1), _this_foo; - _classPrivateFieldSet(this, _foo, +_classPrivateFieldGet(this, _foo) + 1); - _classPrivateFieldSet(_obj = other.obj, _foo, (_this_foo1 = +_classPrivateFieldGet(_obj, _foo)) + 1), _this_foo1; - _classPrivateFieldSet(_obj1 = other.obj, _foo, +_classPrivateFieldGet(_obj1, _foo) + 1); +var Foo = function() { + "use strict"; + function Foo() { + _classCallCheck(this, Foo); + _classPrivateFieldInit(this, _foo, { + writable: true, + value: 0 + }); } - }]); - return Foo; + _createClass(Foo, [ + { + key: "test", + value: function test(other) { + _classPrivateFieldUpdate(this, _foo).value++; + ++_classPrivateFieldUpdate(this, _foo).value; + _classPrivateFieldUpdate(other.obj, _foo).value++; + ++_classPrivateFieldUpdate(other.obj, _foo).value; + } + } + ]); + return Foo; }(); "# ); @@ -2725,33 +2720,32 @@ class Foo { } } ", - " + r#" var _x = new WeakMap(); var Foo = function () { - \"use strict\"; - function Foo() { - _classCallCheck(this, Foo); + "use strict"; + function Foo() { + _classCallCheck(this, Foo); - _classPrivateFieldInit(this, _x, { - writable: true, - value: 0 - }); - } - - _createClass(Foo, [{ - key: \"test\", - value: function test() { - var _this_x; - - _classPrivateFieldSet(this, _x, (_this_x = +_classPrivateFieldGet(this, _x)) + 1), _this_x; - - _classPrivateFieldSet(this, _x, +_classPrivateFieldGet(this, _x) + 1); + _classPrivateFieldInit(this, _x, { + writable: true, + value: 0 + }); } - }]); - return Foo; + _createClass(Foo, [ + { + key: "test", + value: function test() { + _classPrivateFieldUpdate(this, _x).value++; + ++_classPrivateFieldUpdate(this, _x).value; + } + } + ]); + + return Foo; }(); -" +"# ); test!( @@ -2768,33 +2762,30 @@ class Foo { } } ", - " + r#" var Foo = function () { - \"use strict\"; + "use strict"; function Foo() { - _classCallCheck(this, Foo); + _classCallCheck(this, Foo); } - _createClass(Foo, [{ - key: \"test\", - value: function test() { - var _this_x; - - _classStaticPrivateFieldSpecSet(Foo, Foo, _x, (_this_x = \ - +_classStaticPrivateFieldSpecGet(Foo, Foo, _x)) + 1), _this_x; - - _classStaticPrivateFieldSpecSet(Foo, Foo, _x, +_classStaticPrivateFieldSpecGet(Foo, Foo, _x) \ - + 1); - } - }]); + _createClass(Foo, [ + { + key: "test", + value: function test() { + _classStaticPrivateFieldUpdate(Foo, Foo, _x).value++; + ++_classStaticPrivateFieldUpdate(Foo, Foo, _x).value; + } + } + ]); return Foo; }(); - var _x = { writable: true, value: 0 -};" +}; +"# ); test!( @@ -3518,17 +3509,17 @@ class Foo { r#" var _client = new WeakMap(); var Foo = function Foo(props) { - "use strict"; + "use strict"; - _classCallCheck(this, Foo); + _classCallCheck(this, Foo); - _classPrivateFieldInit(this, _client, { - writable: true, - value: void 0 - }); + _classPrivateFieldInit(this, _client, { + writable: true, + value: void 0 + }); - _classPrivateFieldSet(this, _client, 1); - [this.x = _classPrivateFieldGet(this, _client), _classPrivateFieldDestructureSet(this, _client).value, this.y = _classPrivateFieldGet(this, _client)] = props; + _classPrivateFieldSet(this, _client, 1); + [this.x = _classPrivateFieldGet(this, _client), _classPrivateFieldDestructureSet(this, _client).value, this.y = _classPrivateFieldGet(this, _client)] = props; }; "# ); @@ -5819,9 +5810,8 @@ class A { var _D = new WeakMap(); class A { B() { - var _C, _this_D; 1; - _classPrivateFieldSet(_C = C, _D, (_this_D = +_classPrivateFieldGet(_C, _D)) + 1), _this_D; + _classPrivateFieldUpdate(C, _D).value++; E(function() {}); } constructor(){ diff --git a/packages/swc-helpers/src/_class_apply_descriptor_update.js b/packages/swc-helpers/src/_class_apply_descriptor_update.js new file mode 100644 index 00000000000..67385d05afc --- /dev/null +++ b/packages/swc-helpers/src/_class_apply_descriptor_update.js @@ -0,0 +1,23 @@ +export default function _classApplyDescriptorUpdate(receiver, descriptor) { + if (descriptor.set) { + if (!("__destrWrapper" in descriptor)) { + descriptor.__destrWrapper = { + set value(v) { + descriptor.set.call(receiver, v); + }, + get value() { + return descriptor.get.call(receiver); + }, + }; + } + return descriptor.__destrWrapper; + } else { + if (!descriptor.writable) { + // This should only throw in strict mode, but class bodies are + // always strict and private fields can only be used inside + // class bodies. + throw new TypeError("attempted to set read only private field"); + } + return descriptor; + } +} diff --git a/packages/swc-helpers/src/_class_private_field_update.js b/packages/swc-helpers/src/_class_private_field_update.js new file mode 100644 index 00000000000..46beb0fd887 --- /dev/null +++ b/packages/swc-helpers/src/_class_private_field_update.js @@ -0,0 +1,7 @@ +import classExtractFieldDescriptor from "./_class_extract_field_descriptor"; +import classApplyDescriptorUpdate from "./_class_apply_descriptor_update"; + +export default function _classPrivateFieldUpdate(receiver, privateMap) { + var descriptor = classExtractFieldDescriptor(receiver, privateMap, "update"); + return classApplyDescriptorUpdate(receiver, descriptor); +} diff --git a/packages/swc-helpers/src/_class_static_private_field_update.js b/packages/swc-helpers/src/_class_static_private_field_update.js new file mode 100644 index 00000000000..3a6f4be3269 --- /dev/null +++ b/packages/swc-helpers/src/_class_static_private_field_update.js @@ -0,0 +1,9 @@ +import classCheckPrivateStaticAccess from './_class_check_private_static_access'; +import classCheckPrivateStaticFieldDescriptor from './_class_check_private_static_access'; +import classApplyDescriptorUpdate from './_class_apply_descriptor_update'; + +export default function _classStaticPrivateFieldUpdate(receiver, classConstructor, descriptor) { + classCheckPrivateStaticAccess(receiver, classConstructor); + classCheckPrivateStaticFieldDescriptor(descriptor, "update"); + return classApplyDescriptorUpdate(receiver, descriptor); +}