Merge pull request #516 from jridgewell/mallot
Playground Proposal: Mallet operator
This commit is contained in:
17
test/fixtures/transformation/playground/mallet-operator/actual.js
vendored
Normal file
17
test/fixtures/transformation/playground/mallet-operator/actual.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
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);
|
||||
90
test/fixtures/transformation/playground/mallet-operator/exec.js
vendored
Normal file
90
test/fixtures/transformation/playground/mallet-operator/exec.js
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
var obj = {};
|
||||
obj.x ||= 2;
|
||||
assert.equal(obj.x, 2);
|
||||
|
||||
obj = {};
|
||||
assert.equal(obj.x ||= 2, 2);
|
||||
|
||||
obj = { x: 1 };
|
||||
obj.x ||= 2;
|
||||
assert.equal(obj.x, 1);
|
||||
|
||||
obj = { x: 1 };
|
||||
assert.equal(obj.x ||= 2, 1);
|
||||
|
||||
obj = { x: undefined }
|
||||
obj.x ||= 2;
|
||||
assert.equal(obj.x, 2);
|
||||
|
||||
obj = { x: undefined }
|
||||
assert.equal(obj.x ||= 2, 2);
|
||||
|
||||
obj = { x: null }
|
||||
obj.x ||= 2;
|
||||
assert.equal(obj.x, 2);
|
||||
|
||||
obj = { x: null }
|
||||
assert.equal(obj.x ||= 2, 2);
|
||||
|
||||
obj = { x: false }
|
||||
obj.x ||= 2;
|
||||
assert.equal(obj.x, 2);
|
||||
|
||||
obj = { x: false }
|
||||
assert.equal(obj.x ||= 2, 2);
|
||||
|
||||
obj = { x: '' }
|
||||
obj.x ||= 2;
|
||||
assert.equal(obj.x, 2);
|
||||
|
||||
obj = { x: '' }
|
||||
assert.equal(obj.x ||= 2, 2);
|
||||
|
||||
obj = { x: 0 }
|
||||
obj.x ||= 2;
|
||||
assert.equal(obj.x, 2);
|
||||
|
||||
obj = { x: 0 }
|
||||
assert.equal(obj.x ||= 2, 2);
|
||||
|
||||
obj = undefined;
|
||||
obj ||= 2;
|
||||
assert.equal(obj, 2);
|
||||
|
||||
obj = undefined;
|
||||
assert.equal(obj ||= 2 , 2);
|
||||
|
||||
obj = 1;
|
||||
obj ||= 2;
|
||||
assert.equal(obj, 1);
|
||||
|
||||
obj = 1;
|
||||
assert.equal(obj ||= 2 , 1);
|
||||
|
||||
obj = null;
|
||||
obj ||= 2;
|
||||
assert.equal(obj, 2);
|
||||
|
||||
obj = null;
|
||||
assert.equal(obj ||= 2 , 2);
|
||||
|
||||
obj = false;
|
||||
obj ||= 2;
|
||||
assert.equal(obj, 2);
|
||||
|
||||
obj = false;
|
||||
assert.equal(obj ||= 2 , 2);
|
||||
|
||||
obj = '';
|
||||
obj ||= 2;
|
||||
assert.equal(obj, 2);
|
||||
|
||||
obj = '';
|
||||
assert.equal(obj ||= 2 , 2);
|
||||
|
||||
obj = 0;
|
||||
obj ||= 2;
|
||||
assert.equal(obj, 2);
|
||||
|
||||
obj = 0;
|
||||
assert.equal(obj ||= 2 , 2);
|
||||
29
test/fixtures/transformation/playground/mallet-operator/expected.js
vendored
Normal file
29
test/fixtures/transformation/playground/mallet-operator/expected.js
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
"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]));
|
||||
Reference in New Issue
Block a user