clean up conditional assignment operator transformers
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
obj ||= {};
|
||||
|
||||
obj.x ||= 2;
|
||||
|
||||
console.log(obj.x ||= 2);
|
||||
|
||||
obj.x.x ||= 2;
|
||||
|
||||
console.log(obj.x.x ||= 2);
|
||||
|
||||
obj[x()] ||= 2;
|
||||
|
||||
console.log(obj[x()] ||= 2);
|
||||
|
||||
obj[y()][x()] ||= 2;
|
||||
|
||||
console.log(obj[y()][x()] ||= 2);
|
||||
@@ -88,3 +88,19 @@ assert.equal(obj, 2);
|
||||
|
||||
obj = 0;
|
||||
assert.equal(obj ||= 2 , 2);
|
||||
|
||||
var calls = 0;
|
||||
var q = { q: 3 };
|
||||
var o = {
|
||||
get p() {
|
||||
calls++;
|
||||
return q;
|
||||
}
|
||||
};
|
||||
|
||||
o.p.q ||= 2;
|
||||
assert.equal(1, calls);
|
||||
o.p.f ||= 2;
|
||||
assert.equal(2, calls);
|
||||
assert.equal(3, o.p.q);
|
||||
assert.equal(2, o.p.f);
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _obj$x2, _x2, _obj$y2, _x4;
|
||||
if (!obj) obj = {};
|
||||
if (!obj.x) obj.x = 2;
|
||||
|
||||
|
||||
console.log((!obj.x && (obj.x = 2), obj.x));
|
||||
|
||||
var _obj$x = obj.x;
|
||||
if (!_obj$x.x) _obj$x.x = 2;
|
||||
|
||||
|
||||
console.log((_obj$x2 = obj.x, !_obj$x2.x && (_obj$x2.x = 2), _obj$x2.x));
|
||||
|
||||
var _x = x();
|
||||
|
||||
if (!obj[_x]) obj[_x] = 2;
|
||||
|
||||
|
||||
console.log((_x2 = x(), !obj[_x2] && (obj[_x2] = 2), obj[_x2]));
|
||||
|
||||
var _obj$y = obj[y()];
|
||||
var _x3 = x();
|
||||
|
||||
if (!_obj$y[_x3]) _obj$y[_x3] = 2;
|
||||
|
||||
|
||||
console.log((_obj$y2 = obj[y()], _x4 = x(), !_obj$y2[_x4] && (_obj$y2[_x4] = 2), _obj$y2[_x4]));
|
||||
@@ -1,13 +0,0 @@
|
||||
var obj = {};
|
||||
|
||||
obj.x ?= 2;
|
||||
|
||||
console.log(obj.x ?= 2);
|
||||
|
||||
obj[x()] ?= 2;
|
||||
|
||||
console.log(obj[x()] ?= 2);
|
||||
|
||||
obj[y()][x()] ?= 2;
|
||||
|
||||
console.log(obj[y()][x()] ?= 2);
|
||||
@@ -18,3 +18,19 @@ assert.equal(obj.x, undefined);
|
||||
|
||||
obj = { x: undefined }
|
||||
assert.equal(obj.x ?= 2, undefined);
|
||||
|
||||
var calls = 0;
|
||||
var q = { q: 3 };
|
||||
var o = {
|
||||
get p() {
|
||||
calls++;
|
||||
return q;
|
||||
}
|
||||
};
|
||||
|
||||
o.p.q ?= 2;
|
||||
assert.equal(1, calls);
|
||||
o.p.f ?= 2;
|
||||
assert.equal(2, calls);
|
||||
assert.equal(3, o.p.q);
|
||||
assert.equal(2, o.p.f);
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
"use strict";
|
||||
|
||||
var _obj2, _obj4, _x2, _obj$y2, _x4;
|
||||
var _hasOwn = Object.prototype.hasOwnProperty;
|
||||
var obj = {};
|
||||
|
||||
var _obj = obj;
|
||||
if (!_hasOwn.call(_obj, "x")) _obj.x = 2;
|
||||
|
||||
|
||||
console.log((_obj2 = obj, !_hasOwn.call(_obj2, "x") && (_obj2.x = 2), _obj2.x));
|
||||
|
||||
var _obj3 = obj;
|
||||
var _x = x();
|
||||
|
||||
if (!_hasOwn.call(_obj3, _x)) _obj3[_x] = 2;
|
||||
|
||||
|
||||
console.log((_obj4 = obj, _x2 = x(), !_hasOwn.call(_obj4, _x2) && (_obj4[_x2] = 2), _obj4[_x2]));
|
||||
|
||||
var _obj$y = obj[y()];
|
||||
var _x3 = x();
|
||||
|
||||
if (!_hasOwn.call(_obj$y, _x3)) _obj$y[_x3] = 2;
|
||||
|
||||
|
||||
console.log((_obj$y2 = obj[y()], _x4 = x(), !_hasOwn.call(_obj$y2, _x4) && (_obj$y2[_x4] = 2), _obj$y2[_x4]));
|
||||
Reference in New Issue
Block a user