add loose mode to spread and destructuring

This commit is contained in:
Sebastian McKenzie
2015-01-18 12:12:12 +11:00
parent 41949fd58b
commit 95d9f59668
92 changed files with 519 additions and 15 deletions

View File

@@ -0,0 +1 @@
var [a, [b], [c], d] = ["hello", [", ", "junk"], ["world"]];

View File

@@ -0,0 +1,10 @@
"use strict";
var _ref = ["hello", [", ", "junk"], ["world"]];
var a = _ref[0];
var _ref$1 = _ref[1];
var b = _ref$1[0];
var _ref$2 = _ref[2];
var c = _ref$2[0];
var d = _ref[3];

View File

@@ -0,0 +1 @@
console.log([x] = [123]);

View File

@@ -0,0 +1,4 @@
"use strict";
var _temp, _temp2;
console.log((_temp = [123], _temp2 = _temp, x = _temp2[0], _temp));

View File

@@ -0,0 +1 @@
[a, b] = f();

View File

@@ -0,0 +1,7 @@
"use strict";
var _ref = f();
var _ref2 = _ref;
a = _ref2[0];
b = _ref2[1];

View File

@@ -0,0 +1 @@
var [, a, [b], [c], d] = ["foo", "hello", [", ", "junk"], ["world"]];

View File

@@ -0,0 +1,10 @@
"use strict";
var _ref = ["foo", "hello", [", ", "junk"], ["world"]];
var a = _ref[1];
var _ref$2 = _ref[2];
var b = _ref$2[0];
var _ref$3 = _ref[3];
var c = _ref$3[0];
var d = _ref[4];

View File

@@ -0,0 +1,3 @@
var { ...x } = z;
var { x, ...y } = z;
(function({ x, ...y }) { })

View File

@@ -0,0 +1,23 @@
"use strict";
var _objectWithoutProperties = function (obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) continue;
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
target[i] = obj[i];
}
return target;
};
var x = _objectWithoutProperties(z, []);
var x = z.x;
var y = _objectWithoutProperties(z, ["x"]);
(function (_ref) {
var x = _ref.x;
var y = _objectWithoutProperties(_ref, ["x"]);
});

View File

@@ -0,0 +1,3 @@
{
"experimental": true
}

View File

@@ -0,0 +1,3 @@
for (var [name, value] in obj) {
print("Name: " + name + ", Value: " + value);
}

View File

@@ -0,0 +1,8 @@
"use strict";
for (var _ref in obj) {
var _ref2 = _ref;
var name = _ref2[0];
var value = _ref2[1];
print("Name: " + name + ", Value: " + value);
}

View File

@@ -0,0 +1,3 @@
for (var [ name, before, after ] of this.test.expectation.registers) {
}

View File

@@ -0,0 +1,9 @@
"use strict";
for (var _iterator = this.test.expectation.registers[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var _ref = _step.value;
var _ref2 = _ref;
var name = _ref2[0];
var before = _ref2[1];
var after = _ref2[2];
}

View File

@@ -0,0 +1 @@
[this.foo, this.bar] = [1, 2];

View File

@@ -0,0 +1,7 @@
"use strict";
var _ref = [1, 2];
var _ref2 = _ref;
this.foo = _ref2[0];
this.bar = _ref2[1];

View File

@@ -0,0 +1 @@
var {topLeft: [x1, y1], bottomRight: [x2, y2] } = rect;

View File

@@ -0,0 +1,8 @@
"use strict";
var _rect$topLeft = rect.topLeft;
var x1 = _rect$topLeft[0];
var y1 = _rect$topLeft[1];
var _rect$bottomRight = rect.bottomRight;
var x2 = _rect$bottomRight[0];
var y2 = _rect$bottomRight[1];

View File

@@ -0,0 +1,2 @@
var { x, y } = coords,
foo = "bar";

View File

@@ -0,0 +1,5 @@
"use strict";
var x = coords.x;
var y = coords.y;
var foo = "bar";

View File

@@ -0,0 +1 @@
var {topLeft: {x: x1, y: y1}, bottomRight: {x: x2, y: y2}} = rect;

View File

@@ -0,0 +1,6 @@
"use strict";
var x1 = rect.topLeft.x;
var y1 = rect.topLeft.y;
var x2 = rect.bottomRight.x;
var y2 = rect.bottomRight.y;

View File

@@ -0,0 +1 @@
var { x, y } = coords;

View File

@@ -0,0 +1,4 @@
"use strict";
var x = coords.x;
var y = coords.y;

View File

@@ -0,0 +1,3 @@
{
"loose": ["destructuring"]
}

View File

@@ -0,0 +1,15 @@
function somethingAdvanced({topLeft: {x: x1, y: y1}, bottomRight: {x: x2, y: y2}}){
}
function unpackObject({title: title, author: author}) {
return title + ' ' + author;
}
console.log(unpackObject({title: 'title', author: 'author'}));
var unpackArray = function ([a, b, c], [x, y, z]) {
return a+b+c;
};
console.log(unpackArray(['hello', ', ', 'world'], [1, 2, 3]));

View File

@@ -0,0 +1,30 @@
"use strict";
function somethingAdvanced(_ref) {
var x1 = _ref.topLeft.x;
var y1 = _ref.topLeft.y;
var x2 = _ref.bottomRight.x;
var y2 = _ref.bottomRight.y;
}
function unpackObject(_ref2) {
var title = _ref2.title;
var author = _ref2.author;
return title + " " + author;
}
console.log(unpackObject({ title: "title", author: "author" }));
var unpackArray = function (_ref3, _ref4) {
var _ref32 = _ref3;
var a = _ref32[0];
var b = _ref32[1];
var c = _ref32[2];
var _ref42 = _ref4;
var x = _ref42[0];
var y = _ref42[1];
var z = _ref42[2];
return a + b + c;
};
console.log(unpackArray(["hello", ", ", "world"], [1, 2, 3]));

View File

@@ -0,0 +1,5 @@
var isSorted = ([x, y, ...wow]) => {
if (!zs.length) return true
if (y > x) return isSorted(zs)
return false
};

View File

@@ -0,0 +1,12 @@
"use strict";
var isSorted = function (_ref) {
var _ref2 = _ref;
var x = _ref2[0];
var y = _ref2[1];
var wow = _ref2.slice(2);
if (!zs.length) return true;
if (y > x) return isSorted(zs);
return false;
};

View File

@@ -32,16 +32,16 @@ function unpackObject(_ref2) {
console.log(unpackObject({ title: "title", author: "author" }));
var unpackArray = function (_ref3, _ref4) {
var _ref3 = _slicedToArray(_ref3, 3);
var _ref32 = _slicedToArray(_ref3, 3);
var a = _ref3[0];
var b = _ref3[1];
var c = _ref3[2];
var _ref4 = _slicedToArray(_ref4, 3);
var a = _ref32[0];
var b = _ref32[1];
var c = _ref32[2];
var _ref42 = _slicedToArray(_ref4, 3);
var x = _ref4[0];
var y = _ref4[1];
var z = _ref4[2];
var x = _ref42[0];
var y = _ref42[1];
var z = _ref42[2];
return a + b + c;
};

View File

@@ -0,0 +1,12 @@
assert.equal(() => {
let sum = 0;
let a = 0;
{
let a = 10;
for (let i = 0; i < a; i++) {
let a = 1;
sum += (() => a)();
}
}
return sum;
}(), 10);

View File

@@ -0,0 +1,9 @@
function foo() {
return bar([...arguments]);
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@@ -0,0 +1,11 @@
"use strict";
function foo() {
return bar([].concat(arguments));
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@@ -0,0 +1,9 @@
function foo() {
return bar("test", ...arguments);
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@@ -0,0 +1,11 @@
"use strict";
function foo() {
return bar.apply(undefined, ["test"].concat(arguments));
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@@ -0,0 +1,9 @@
function foo() {
return bar(...arguments);
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@@ -0,0 +1,11 @@
"use strict";
function foo() {
return bar.apply(undefined, arguments);
}
function bar(one, two, three) {
return [one, two, three];
}
foo("foo", "bar");

View File

@@ -0,0 +1 @@
var lyrics = [...parts, "head", "and", "toes"];

View File

@@ -0,0 +1,3 @@
"use strict";
var lyrics = [].concat(parts, ["head", "and", "toes"]);

View File

@@ -0,0 +1 @@
var a = [b, ...c, d];

View File

@@ -0,0 +1,3 @@
"use strict";
var a = [b].concat(c, [d]);

View File

@@ -0,0 +1 @@
var a = [b, ...c, d, e, ...f];

View File

@@ -0,0 +1,3 @@
"use strict";
var a = [b].concat(c, [d, e], f);

View File

@@ -0,0 +1 @@
var lyrics = ["head", "and", "toes", ...parts];

View File

@@ -0,0 +1,3 @@
"use strict";
var lyrics = ["head", "and", "toes"].concat(parts);

View File

@@ -0,0 +1 @@
obj[method](foo, bar, ...args);

View File

@@ -0,0 +1,4 @@
"use strict";
var _obj;
(_obj = obj)[method].apply(_obj, [foo, bar].concat(args));

View File

@@ -0,0 +1 @@
obj[method](...args);

View File

@@ -0,0 +1,4 @@
"use strict";
var _obj;
(_obj = obj)[method].apply(_obj, args);

View File

@@ -0,0 +1,2 @@
foob.add(foo, bar, ...numbers);
foob.test.add(foo, bar, ...numbers);

View File

@@ -0,0 +1,5 @@
"use strict";
var _foob, _foob$test;
(_foob = foob).add.apply(_foob, [foo, bar].concat(numbers));
(_foob$test = foob.test).add.apply(_foob$test, [foo, bar].concat(numbers));

View File

@@ -0,0 +1,2 @@
foob.add(...numbers);
foob.test.add(...numbers);

View File

@@ -0,0 +1,5 @@
"use strict";
var _foob, _foob$test;
(_foob = foob).add.apply(_foob, numbers);
(_foob$test = foob.test).add.apply(_foob$test, numbers);

View File

@@ -0,0 +1 @@
f(...[1, 2, 3]);

View File

@@ -0,0 +1,3 @@
"use strict";
f.apply(undefined, [1, 2, 3]);

View File

@@ -0,0 +1 @@
add(...numbers, foo, bar);

View File

@@ -0,0 +1,3 @@
"use strict";
add.apply(undefined, numbers.concat([foo, bar]));

View File

@@ -0,0 +1 @@
add(foo, ...numbers, bar);

View File

@@ -0,0 +1,3 @@
"use strict";
add.apply(undefined, [foo].concat(numbers, [bar]));

View File

@@ -0,0 +1 @@
add(foo, bar, ...numbers);

View File

@@ -0,0 +1,3 @@
"use strict";
add.apply(undefined, [foo, bar].concat(numbers));

View File

@@ -0,0 +1 @@
add(foo, ...numbers, bar, what, ...test);

View File

@@ -0,0 +1,3 @@
"use strict";
add.apply(undefined, [foo].concat(numbers, [bar, what], test));

View File

@@ -0,0 +1 @@
add(...numbers);

View File

@@ -0,0 +1,3 @@
"use strict";
add.apply(undefined, numbers);

View File

@@ -0,0 +1,2 @@
new Numbers(...nums);
new Numbers(1, ...nums);

View File

@@ -0,0 +1,12 @@
"use strict";
var _applyConstructor = function (Constructor, args) {
var instance = Object.create(Constructor.prototype);
var result = Constructor.apply(instance, args);
return result != null && (typeof result == "object" || typeof result == "function") ? result : instance;
};
_applyConstructor(Numbers, nums);
_applyConstructor(Numbers, [1].concat(nums));

View File

@@ -0,0 +1,3 @@
{
"loose": "spread"
}

View File

@@ -0,0 +1 @@
[...foo];

View File

@@ -0,0 +1,3 @@
"use strict";
[].concat(foo);

View File

@@ -0,0 +1,5 @@
function add() {
return [for (i of [1, 2, 3]) i * arguments[0]];
}
add(5);

View File

@@ -0,0 +1,17 @@
"use strict";
function add() {
var _arguments = arguments;
return (function () {
var _ref = [];
for (var _iterator = [1, 2, 3][Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var i = _step.value;
_ref.push(i * _arguments[0]);
}
return _ref;
})();
}
add(5);

View File

@@ -0,0 +1 @@
var arr = [for (i of [1, 2, 3]) if (i > 1) i * i];

View File

@@ -0,0 +1,14 @@
"use strict";
var arr = (function () {
var _arr = [];
for (var _iterator = [1, 2, 3][Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var i = _step.value;
if (i > 1) {
_arr.push(i * i);
}
}
return _arr;
})();

View File

@@ -0,0 +1 @@
var arr = [for (i of [1, 2, 3]) i * i];

View File

@@ -0,0 +1,12 @@
"use strict";
var arr = (function () {
var _arr = [];
for (var _iterator = [1, 2, 3][Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var i = _step.value;
_arr.push(i * i);
}
return _arr;
})();

View File

@@ -0,0 +1 @@
var seattlers = [for (customers of countries) for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }];

View File

@@ -0,0 +1,17 @@
"use strict";
var seattlers = (function () {
var _seattlers = [];
for (var _iterator = countries[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var customers = _step.value;
for (var _iterator2 = customers[Symbol.iterator](), _step2; !(_step2 = _iterator2.next()).done;) {
var c = _step2.value;
if (c.city == "Seattle") {
_seattlers.push({ name: c.name, age: c.age });
}
}
}
return _seattlers;
})();

View File

@@ -0,0 +1 @@
var arr = [for (x of "abcdefgh".split("")) for (y of "12345678".split("")) x + y];

View File

@@ -0,0 +1,15 @@
"use strict";
var arr = (function () {
var _arr = [];
for (var _iterator = "abcdefgh".split("")[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var x = _step.value;
for (var _iterator2 = "12345678".split("")[Symbol.iterator](), _step2; !(_step2 = _iterator2.next()).done;) {
var y = _step2.value;
_arr.push(x + y);
}
}
return _arr;
})();

View File

@@ -0,0 +1,4 @@
{
"experimental": true,
"loose": "arrayComprehension"
}

View File

@@ -0,0 +1 @@
var arr = [for (i of nums) if (i > 1) i * i];

View File

@@ -0,0 +1,14 @@
"use strict";
var arr = (function () {
var _arr = [];
for (var _iterator = nums[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var i = _step.value;
if (i > 1) {
_arr.push(i * i);
}
}
return _arr;
})();

View File

@@ -0,0 +1 @@
var arr = [for (i of nums) i * i];

View File

@@ -0,0 +1,12 @@
"use strict";
var arr = (function () {
var _arr = [];
for (var _iterator = nums[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var i = _step.value;
_arr.push(i * i);
}
return _arr;
})();

View File

@@ -0,0 +1,5 @@
function add() {
return [for (i of [1, 2, 3]) i * this.multiplier];
}
add.call({ multiplier: 5 });

View File

@@ -0,0 +1,17 @@
"use strict";
function add() {
var _this = this;
return (function () {
var _ref = [];
for (var _iterator = [1, 2, 3][Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
var i = _step.value;
_ref.push(i * _this.multiplier);
}
return _ref;
})();
}
add.call({ multiplier: 5 });

View File

@@ -0,0 +1,4 @@
{
"experimental": true,
"loose": "generatorComprehension"
}

View File

@@ -0,0 +1,6 @@
var nums = [1, 2, 3, 4, 5, 6];
var multiples = (for (i of nums) if (i % 2) i * i);
assert.equal(multiples.next().value, 1);
assert.equal(multiples.next().value, 9);
assert.equal(multiples.next().value, 25);
assert.ok(multiples.next().done);