Ujjwal Sharma 2ac49ba7c4
add support for logical assignments with private properties (#11702)
* add support for logical assignments with private properties

Patches the logic for handling assignment operators and adds support for
handling the logical assignment operators appropriately.

Fixes: https://github.com/babel/babel/issues/11646

* replace hardcoded logical assignment operators with constant

Replace a hardcoded check for logical assignment operators with the
LOGICAL_OPERATORS constant in
plugin-proposal-logical-assignment-operators.

Refs: https://github.com/babel/babel/pull/11702#discussion_r438554423
2020-07-30 14:10:16 -04:00

43 lines
1.4 KiB
JavaScript

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 id = 0;
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }
var _nullish = _classPrivateFieldLooseKey("nullish");
var _and = _classPrivateFieldLooseKey("and");
var _or = _classPrivateFieldLooseKey("or");
class Foo {
constructor() {
Object.defineProperty(this, _nullish, {
writable: true,
value: 0
});
Object.defineProperty(this, _and, {
writable: true,
value: 0
});
Object.defineProperty(this, _or, {
writable: true,
value: 0
});
}
self() {
return this;
}
test() {
var _classPrivateFieldLoo, _classPrivateFieldLoo2, _classPrivateFieldLoo3, _classPrivateFieldLoo4;
(_classPrivateFieldLoo = _classPrivateFieldLooseBase(this, _nullish))[_nullish] ?? (_classPrivateFieldLoo[_nullish] = 42);
(_classPrivateFieldLoo2 = _classPrivateFieldLooseBase(this, _and))[_and] && (_classPrivateFieldLoo2[_and] = 0);
(_classPrivateFieldLoo3 = _classPrivateFieldLooseBase(this, _or))[_or] || (_classPrivateFieldLoo3[_or] = 0);
(_classPrivateFieldLoo4 = _classPrivateFieldLooseBase(this.self(), _nullish))[_nullish] ?? (_classPrivateFieldLoo4[_nullish] = 42);
}
}