diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-in-function-param-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-in-function-param-with-transform/options.json new file mode 100644 index 000000000000..124133b5af2b --- /dev/null +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-in-function-param-with-transform/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + ["proposal-optional-chaining", { "loose": true }], + ["proposal-class-properties", { "loose": true }] + ] +} diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-in-function-param-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-in-function-param-with-transform/output.js index fe7ddec253e6..fb3516c4b811 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-in-function-param-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private-loose/optional-chain-in-function-param-with-transform/output.js @@ -1,78 +1,82 @@ -var _x = babelHelpers.classPrivateFieldLooseKey("x"); +function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } -var _m = babelHelpers.classPrivateFieldLooseKey("m"); +var id = 0; -var _self = babelHelpers.classPrivateFieldLooseKey("self"); +function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } -var Foo = /*#__PURE__*/function () { - "use strict"; +var _x = _classPrivateFieldLooseKey("x"); - function Foo() { - babelHelpers.classCallCheck(this, Foo); +var _m = _classPrivateFieldLooseKey("m"); + +var _self = _classPrivateFieldLooseKey("self"); + +class Foo { + static getSelf() { + return this; } - babelHelpers.createClass(Foo, null, [{ - key: "getSelf", - value: function getSelf() { - return this; - } - }, { - key: "test", - value: function test() { - var o = { - Foo: Foo - }; - var deep = { - very: { - o - } - }; - - function fn() { - return o; + static test() { + const o = { + Foo: Foo + }; + const deep = { + very: { + o } + }; - function fnDeep() { - return deep; - } + function fn() { + return o; + } - function f(o, r = (() => o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(o.Foo, _m)[_m]())()) { - return r; - } + function fnDeep() { + return deep; + } - function g(o, r = (() => o === null || o === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(babelHelpers.classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m])()?.()) { - return r; - } + function f(o, r = (() => o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]())()) { + return r; + } - function h(fnDeep, r = (() => { - var _fnDeep$very$o$Foo; + function g(o, r = (() => { + var _ref; - return (_fnDeep$very$o$Foo = fnDeep?.().very.o?.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_fnDeep$very$o$Foo, _m)[_m](); - })()) { - return r; - } + return (_ref = (() => o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m])()) == null ? void 0 : _ref(); + })()) { + return r; + } - function i(fn, r = (() => { - var _getSelf; + function h(fnDeep, r = (() => { + var _fnDeep$very$o$Foo, _fnDeep$very$o; - return (_getSelf = (() => fn === null || fn === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(fn().Foo, _self)[_self])()?.getSelf()) === null || _getSelf === void 0 ? void 0 : babelHelpers.classPrivateFieldLooseBase(_getSelf.self, _m)[_m](); - })()) { - return r; - } + return (_fnDeep$very$o$Foo = fnDeep == null ? void 0 : (_fnDeep$very$o = fnDeep().very.o) == null ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo, _m)[_m](); + })()) { + return r; + } - function j(fn, r = (() => babelHelpers.classPrivateFieldLooseBase(babelHelpers.classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf().self, _m)[_m]?.())()) { - return r; - } + function i(fn, r = (() => { + var _getSelf, _ref2; + + return (_getSelf = (_ref2 = (() => fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])()) == null ? void 0 : _ref2.getSelf()) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.self, _m)[_m](); + })()) { + return r; + } + + function j(fn, r = (() => { + var _classPrivateFieldLoo, _classPrivateFieldLoo2; - f(o); - g(o); - h(fnDeep); - i(fn); - j(fn); + return (_classPrivateFieldLoo = (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf().self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo.call(_classPrivateFieldLoo2); + })()) { + return r; } - }]); - return Foo; -}(); + + f(o); + g(o); + h(fnDeep); + i(fn); + j(fn); + } + +} Object.defineProperty(Foo, _x, { writable: true, @@ -81,7 +85,7 @@ Object.defineProperty(Foo, _x, { Object.defineProperty(Foo, _m, { writable: true, value: function () { - return babelHelpers.classPrivateFieldLooseBase(this, _x)[_x]; + return _classPrivateFieldLooseBase(this, _x)[_x]; } }); Object.defineProperty(Foo, _self, { diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param-with-transform/options.json b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param-with-transform/options.json index 124133b5af2b..63b4c77cc8e8 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param-with-transform/options.json +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param-with-transform/options.json @@ -1,6 +1,3 @@ { - "plugins": [ - ["proposal-optional-chaining", { "loose": true }], - ["proposal-class-properties", { "loose": true }] - ] + "plugins": ["proposal-optional-chaining", "proposal-class-properties"] } diff --git a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param-with-transform/output.js b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param-with-transform/output.js index fb3516c4b811..1c52675c3085 100644 --- a/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param-with-transform/output.js +++ b/packages/babel-plugin-proposal-class-properties/test/fixtures/private/optional-chain-in-function-param-with-transform/output.js @@ -1,14 +1,6 @@ -function _classPrivateFieldLooseBase(receiver, privateKey) { if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) { throw new TypeError("attempted to use private field on non-instance"); } return receiver; } +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } -var id = 0; - -function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; } - -var _x = _classPrivateFieldLooseKey("x"); - -var _m = _classPrivateFieldLooseKey("m"); - -var _self = _classPrivateFieldLooseKey("self"); +function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) { if (receiver !== classConstructor) { throw new TypeError("Private static access of wrong provenance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; } class Foo { static getSelf() { @@ -33,14 +25,18 @@ class Foo { return deep; } - function f(o, r = (() => o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(o.Foo, _m)[_m]())()) { + function f(o, r = (() => { + var _o$Foo; + + return o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_o$Foo = o.Foo, Foo, _m).call(_o$Foo); + })()) { return r; } function g(o, r = (() => { var _ref; - return (_ref = (() => o === null || o === void 0 ? void 0 : _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(o.Foo, _self)[_self].getSelf(), _m)[_m])()) == null ? void 0 : _ref(); + return (_ref = (() => o === null || o === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_classStaticPrivateFieldSpecGet(o.Foo, Foo, _self).getSelf(), Foo, _m))()) === null || _ref === void 0 ? void 0 : _ref(); })()) { return r; } @@ -48,23 +44,23 @@ class Foo { function h(fnDeep, r = (() => { var _fnDeep$very$o$Foo, _fnDeep$very$o; - return (_fnDeep$very$o$Foo = fnDeep == null ? void 0 : (_fnDeep$very$o = fnDeep().very.o) == null ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classPrivateFieldLooseBase(_fnDeep$very$o$Foo, _m)[_m](); + return (_fnDeep$very$o$Foo = fnDeep === null || fnDeep === void 0 ? void 0 : (_fnDeep$very$o = fnDeep().very.o) === null || _fnDeep$very$o === void 0 ? void 0 : _fnDeep$very$o.Foo) === null || _fnDeep$very$o$Foo === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_fnDeep$very$o$Foo, Foo, _m).call(_fnDeep$very$o$Foo); })()) { return r; } function i(fn, r = (() => { - var _getSelf, _ref2; + var _getSelf, _getSelf$self, _ref2; - return (_getSelf = (_ref2 = (() => fn === null || fn === void 0 ? void 0 : _classPrivateFieldLooseBase(fn().Foo, _self)[_self])()) == null ? void 0 : _ref2.getSelf()) === null || _getSelf === void 0 ? void 0 : _classPrivateFieldLooseBase(_getSelf.self, _m)[_m](); + return (_getSelf = (_ref2 = (() => fn === null || fn === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self))()) === null || _ref2 === void 0 ? void 0 : _ref2.getSelf()) === null || _getSelf === void 0 ? void 0 : _classStaticPrivateFieldSpecGet(_getSelf$self = _getSelf.self, Foo, _m).call(_getSelf$self); })()) { return r; } function j(fn, r = (() => { - var _classPrivateFieldLoo, _classPrivateFieldLoo2; + var _classStaticPrivateFi, _classStaticPrivateFi2; - return (_classPrivateFieldLoo = (_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(_classPrivateFieldLooseBase(fn().Foo, _self)[_self].getSelf().self, _m))[_m]) == null ? void 0 : _classPrivateFieldLoo.call(_classPrivateFieldLoo2); + return (_classStaticPrivateFi2 = _classStaticPrivateFieldSpecGet(_classStaticPrivateFi = _classStaticPrivateFieldSpecGet(fn().Foo, Foo, _self).getSelf().self, Foo, _m)) === null || _classStaticPrivateFi2 === void 0 ? void 0 : _classStaticPrivateFi2.call(_classStaticPrivateFi); })()) { return r; } @@ -78,19 +74,21 @@ class Foo { } -Object.defineProperty(Foo, _x, { +var _x = { writable: true, value: 1 -}); -Object.defineProperty(Foo, _m, { +}; +var _m = { writable: true, value: function () { - return _classPrivateFieldLooseBase(this, _x)[_x]; + return _classStaticPrivateFieldSpecGet(this, Foo, _x); } -}); -Object.defineProperty(Foo, _self, { +}; +var _self = { writable: true, value: Foo -}); -Foo.self = Foo; +}; + +_defineProperty(Foo, "self", Foo); + Foo.test();