Revert "add loose mode to spread and destructuring"

This reverts commit 95d9f59668.
This commit is contained in:
Sebastian McKenzie
2015-01-18 12:52:16 +11:00
parent 0bb52d6e3d
commit 93d99077e5
92 changed files with 15 additions and 519 deletions

View File

@@ -7,7 +7,7 @@ var buildVariableAssign = function (opts, id, init) {
if (t.isMemberExpression(id)) op = "=";
if (op) {
return t.expressionStatement(t.assignmentExpression(op, id, init));
return t.expressionStatement(t.assignmentExpression("=", id, init));
} else {
return t.variableDeclaration(opts.kind, [
t.variableDeclarator(id, init)
@@ -95,12 +95,7 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
}
}
var isLoose = opts.file.isLoose("destructuring");
var toArray = parentId;
if (!isLoose) {
toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
}
var toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length);
var _parentId = opts.scope.generateUidBasedOnNode(parentId, opts.file);
nodes.push(t.variableDeclaration("var", [
@@ -112,14 +107,12 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) {
var elem = pattern.elements[i];
if (!elem) continue;
i = +i;
var newPatternId;
if (t.isSpreadElement(elem)) {
newPatternId = parentId;
if (!isLoose) {
newPatternId = opts.file.toArray(parentId);
}
newPatternId = opts.file.toArray(parentId);
if (i > 0) {
newPatternId = t.callExpression(t.memberExpression(newPatternId, t.identifier("slice")), [t.literal(i)]);

View File

@@ -2,11 +2,7 @@ var t = require("../../types");
var _ = require("lodash");
var getSpreadLiteral = function (spread, file) {
if (file.isLoose("spread")) {
return spread.argument;
} else {
return file.toArray(spread.argument);
}
return file.toArray(spread.argument);
};
var hasSpread = function (nodes) {
@@ -68,7 +64,7 @@ exports.CallExpression = function (node, parent, scope, context, file) {
node.arguments = [];
var nodes;
if (args.length === 1 && args[0].argument.name === "arguments") {
if (args.length === 1 && args[0].argument.name === 'arguments') {
nodes = [args[0].argument];
} else {
nodes = build(args, file);

View File

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

View File

@@ -1,10 +0,0 @@
"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

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

View File

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

View File

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

View File

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

View File

@@ -1,10 +0,0 @@
"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

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

View File

@@ -1,23 +0,0 @@
"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

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

View File

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

View File

@@ -1,8 +0,0 @@
"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

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

View File

@@ -1,9 +0,0 @@
"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

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

View File

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

View File

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

View File

@@ -1,8 +0,0 @@
"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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,15 +0,0 @@
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

@@ -1,30 +0,0 @@
"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

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

View File

@@ -1,12 +0,0 @@
"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 _ref32 = _slicedToArray(_ref3, 3);
var _ref3 = _slicedToArray(_ref3, 3);
var a = _ref32[0];
var b = _ref32[1];
var c = _ref32[2];
var _ref42 = _slicedToArray(_ref4, 3);
var a = _ref3[0];
var b = _ref3[1];
var c = _ref3[2];
var _ref4 = _slicedToArray(_ref4, 3);
var x = _ref42[0];
var y = _ref42[1];
var z = _ref42[2];
var x = _ref4[0];
var y = _ref4[1];
var z = _ref4[2];
return a + b + c;
};

View File

@@ -1,12 +0,0 @@
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

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

View File

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

View File

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

View File

@@ -1,11 +0,0 @@
"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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,5 +0,0 @@
"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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,12 +0,0 @@
"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

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

View File

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

View File

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

View File

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

View File

@@ -1,17 +0,0 @@
"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

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

View File

@@ -1,14 +0,0 @@
"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

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

View File

@@ -1,12 +0,0 @@
"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

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

View File

@@ -1,17 +0,0 @@
"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

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

View File

@@ -1,15 +0,0 @@
"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

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

View File

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

View File

@@ -1,14 +0,0 @@
"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

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

View File

@@ -1,12 +0,0 @@
"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

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

View File

@@ -1,17 +0,0 @@
"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

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

View File

@@ -1,6 +0,0 @@
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);