Skip to content

Commit

Permalink
fixup! add support for logical assignments with private properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzokuken committed Jul 22, 2020
1 parent c6606ad commit 86cfb91
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
@@ -1,6 +1,6 @@
{
"plugins": [
"proposal-logical-assignment-operators",
"proposal-class-properties"
["proposal-logical-assignment-operators", { "loose": true }],
["proposal-class-properties", { "loose": true }]
]
}
@@ -1,26 +1,26 @@
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = privateMap.get(receiver); if (!descriptor) { throw new TypeError("attempted to set private field on non-instance"); } if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } return value; }
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 _classPrivateFieldGet(receiver, privateMap) { var descriptor = privateMap.get(receiver); if (!descriptor) { throw new TypeError("attempted to get private field on non-instance"); } if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
var id = 0;

var _nullish = new WeakMap();
function _classPrivateFieldLooseKey(name) { return "__private_" + id++ + "_" + name; }

var _and = new WeakMap();
var _nullish = _classPrivateFieldLooseKey("nullish");

var _or = new WeakMap();
var _and = _classPrivateFieldLooseKey("and");

var _or = _classPrivateFieldLooseKey("or");

class Foo {
constructor() {
_nullish.set(this, {
Object.defineProperty(this, _nullish, {
writable: true,
value: 0
});

_and.set(this, {
Object.defineProperty(this, _and, {
writable: true,
value: 0
});

_or.set(this, {
Object.defineProperty(this, _or, {
writable: true,
value: 0
});
Expand All @@ -31,12 +31,12 @@ class Foo {
}

test() {
var _this$self;
var _classPrivateFieldLoo, _classPrivateFieldLoo2, _classPrivateFieldLoo3, _classPrivateFieldLoo4;

_classPrivateFieldGet(this, _nullish) ?? _classPrivateFieldSet(this, _nullish, 42);
_classPrivateFieldGet(this, _and) && _classPrivateFieldSet(this, _and, 0);
_classPrivateFieldGet(this, _or) || _classPrivateFieldSet(this, _or, 0);
_classPrivateFieldGet(_this$self, _nullish) ?? _classPrivateFieldSet(_this$self = this.self(), _nullish, 42);
(_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);
}

}
Expand Up @@ -36,7 +36,7 @@ class Foo {
_classPrivateFieldGet(this, _nullish) ?? _classPrivateFieldSet(this, _nullish, 42);
_classPrivateFieldGet(this, _and) && _classPrivateFieldSet(this, _and, 0);
_classPrivateFieldGet(this, _or) || _classPrivateFieldSet(this, _or, 0);
_classPrivateFieldGet(_this$self, _nullish) ?? _classPrivateFieldSet(_this$self = this.self(), _nullish, 42);
_classPrivateFieldGet(_this$self = this.self(), _nullish) ?? _classPrivateFieldSet(_this$self, _nullish, 42);
}

}

0 comments on commit 86cfb91

Please sign in to comment.