diff --git a/lib/6to5/transformation/transformers/es6-destructuring.js b/lib/6to5/transformation/transformers/es6-destructuring.js index 8b1f5ae882..33929faadd 100644 --- a/lib/6to5/transformation/transformers/es6-destructuring.js +++ b/lib/6to5/transformation/transformers/es6-destructuring.js @@ -7,7 +7,7 @@ var buildVariableAssign = function (opts, id, init) { if (t.isMemberExpression(id)) op = "="; if (op) { - return t.expressionStatement(t.assignmentExpression("=", id, init)); + return t.expressionStatement(t.assignmentExpression(op, id, init)); } else { return t.variableDeclaration(opts.kind, [ t.variableDeclarator(id, init) @@ -95,7 +95,12 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) { } } - var toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length); + var isLoose = opts.file.isLoose("destructuring"); + var toArray = parentId; + + if (!isLoose) { + toArray = opts.file.toArray(parentId, !hasSpreadElement && pattern.elements.length); + } var _parentId = opts.scope.generateUidBasedOnNode(parentId, opts.file); nodes.push(t.variableDeclaration("var", [ @@ -107,12 +112,14 @@ var pushArrayPattern = function (opts, nodes, pattern, parentId) { var elem = pattern.elements[i]; if (!elem) continue; - i = +i; - var newPatternId; if (t.isSpreadElement(elem)) { - newPatternId = opts.file.toArray(parentId); + newPatternId = parentId; + + if (!isLoose) { + newPatternId = opts.file.toArray(parentId); + } if (i > 0) { newPatternId = t.callExpression(t.memberExpression(newPatternId, t.identifier("slice")), [t.literal(i)]); diff --git a/lib/6to5/transformation/transformers/es6-spread.js b/lib/6to5/transformation/transformers/es6-spread.js index 4fa64b5e2b..2b9865fce5 100644 --- a/lib/6to5/transformation/transformers/es6-spread.js +++ b/lib/6to5/transformation/transformers/es6-spread.js @@ -2,7 +2,11 @@ var t = require("../../types"); var _ = require("lodash"); var getSpreadLiteral = function (spread, file) { - return file.toArray(spread.argument); + if (file.isLoose("spread")) { + return spread.argument; + } else { + return file.toArray(spread.argument); + } }; var hasSpread = function (nodes) { @@ -64,7 +68,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); diff --git a/test/fixtures/transformation/es6-destructuring-loose/array/actual.js b/test/fixtures/transformation/es6-destructuring-loose/array/actual.js new file mode 100644 index 0000000000..10aa8799ed --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/array/actual.js @@ -0,0 +1 @@ +var [a, [b], [c], d] = ["hello", [", ", "junk"], ["world"]]; diff --git a/test/fixtures/transformation/es6-destructuring-loose/array/expected.js b/test/fixtures/transformation/es6-destructuring-loose/array/expected.js new file mode 100644 index 0000000000..2b7403faed --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/array/expected.js @@ -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]; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring-loose/assignment-expression/actual.js b/test/fixtures/transformation/es6-destructuring-loose/assignment-expression/actual.js new file mode 100644 index 0000000000..2ebf93ff16 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/assignment-expression/actual.js @@ -0,0 +1 @@ +console.log([x] = [123]); diff --git a/test/fixtures/transformation/es6-destructuring-loose/assignment-expression/expected.js b/test/fixtures/transformation/es6-destructuring-loose/assignment-expression/expected.js new file mode 100644 index 0000000000..b7721a94bf --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/assignment-expression/expected.js @@ -0,0 +1,4 @@ +"use strict"; + +var _temp, _temp2; +console.log((_temp = [123], _temp2 = _temp, x = _temp2[0], _temp)); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring-loose/assignment-statement/actual.js b/test/fixtures/transformation/es6-destructuring-loose/assignment-statement/actual.js new file mode 100644 index 0000000000..d14ce7e47d --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/assignment-statement/actual.js @@ -0,0 +1 @@ +[a, b] = f(); diff --git a/test/fixtures/transformation/es6-destructuring-loose/assignment-statement/expected.js b/test/fixtures/transformation/es6-destructuring-loose/assignment-statement/expected.js new file mode 100644 index 0000000000..e1feb2d7fe --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/assignment-statement/expected.js @@ -0,0 +1,7 @@ +"use strict"; + +var _ref = f(); + +var _ref2 = _ref; +a = _ref2[0]; +b = _ref2[1]; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring-loose/empty/actual.js b/test/fixtures/transformation/es6-destructuring-loose/empty/actual.js new file mode 100644 index 0000000000..a70e49fdd6 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/empty/actual.js @@ -0,0 +1 @@ +var [, a, [b], [c], d] = ["foo", "hello", [", ", "junk"], ["world"]]; diff --git a/test/fixtures/transformation/es6-destructuring-loose/empty/expected.js b/test/fixtures/transformation/es6-destructuring-loose/empty/expected.js new file mode 100644 index 0000000000..1bdbe4fc65 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/empty/expected.js @@ -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]; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/actual.js b/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/actual.js new file mode 100644 index 0000000000..b4877d6e45 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/actual.js @@ -0,0 +1,3 @@ +var { ...x } = z; +var { x, ...y } = z; +(function({ x, ...y }) { }) diff --git a/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/expected.js b/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/expected.js new file mode 100644 index 0000000000..dbb29cb23d --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/expected.js @@ -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"]); +}); diff --git a/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/options.json b/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/options.json new file mode 100644 index 0000000000..252f473a73 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/es7-object-rest/options.json @@ -0,0 +1,3 @@ +{ + "experimental": true +} diff --git a/test/fixtures/transformation/es6-destructuring-loose/for-in/actual.js b/test/fixtures/transformation/es6-destructuring-loose/for-in/actual.js new file mode 100644 index 0000000000..87fe7e7dde --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/for-in/actual.js @@ -0,0 +1,3 @@ +for (var [name, value] in obj) { + print("Name: " + name + ", Value: " + value); +} diff --git a/test/fixtures/transformation/es6-destructuring-loose/for-in/expected.js b/test/fixtures/transformation/es6-destructuring-loose/for-in/expected.js new file mode 100644 index 0000000000..787fa1df42 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/for-in/expected.js @@ -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); +} \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring-loose/for-of/actual.js b/test/fixtures/transformation/es6-destructuring-loose/for-of/actual.js new file mode 100644 index 0000000000..5873553d65 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/for-of/actual.js @@ -0,0 +1,3 @@ +for (var [ name, before, after ] of this.test.expectation.registers) { + +} diff --git a/test/fixtures/transformation/es6-destructuring-loose/for-of/expected.js b/test/fixtures/transformation/es6-destructuring-loose/for-of/expected.js new file mode 100644 index 0000000000..314c03654c --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/for-of/expected.js @@ -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]; +} \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring-loose/member-expression/actual.js b/test/fixtures/transformation/es6-destructuring-loose/member-expression/actual.js new file mode 100644 index 0000000000..bd5e42d7d1 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/member-expression/actual.js @@ -0,0 +1 @@ +[this.foo, this.bar] = [1, 2]; diff --git a/test/fixtures/transformation/es6-destructuring-loose/member-expression/expected.js b/test/fixtures/transformation/es6-destructuring-loose/member-expression/expected.js new file mode 100644 index 0000000000..7e7353b88f --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/member-expression/expected.js @@ -0,0 +1,7 @@ +"use strict"; + +var _ref = [1, 2]; + +var _ref2 = _ref; +this.foo = _ref2[0]; +this.bar = _ref2[1]; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring-loose/mixed/actual.js b/test/fixtures/transformation/es6-destructuring-loose/mixed/actual.js new file mode 100644 index 0000000000..79ac2cb22f --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/mixed/actual.js @@ -0,0 +1 @@ +var {topLeft: [x1, y1], bottomRight: [x2, y2] } = rect; diff --git a/test/fixtures/transformation/es6-destructuring-loose/mixed/expected.js b/test/fixtures/transformation/es6-destructuring-loose/mixed/expected.js new file mode 100644 index 0000000000..7f44ca9a37 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/mixed/expected.js @@ -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]; \ No newline at end of file diff --git a/test/fixtures/transformation/es6-destructuring-loose/multiple/actual.js b/test/fixtures/transformation/es6-destructuring-loose/multiple/actual.js new file mode 100644 index 0000000000..09249c483c --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/multiple/actual.js @@ -0,0 +1,2 @@ +var { x, y } = coords, + foo = "bar"; diff --git a/test/fixtures/transformation/es6-destructuring-loose/multiple/expected.js b/test/fixtures/transformation/es6-destructuring-loose/multiple/expected.js new file mode 100644 index 0000000000..c782335937 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/multiple/expected.js @@ -0,0 +1,5 @@ +"use strict"; + +var x = coords.x; +var y = coords.y; +var foo = "bar"; diff --git a/test/fixtures/transformation/es6-destructuring-loose/object-advanced/actual.js b/test/fixtures/transformation/es6-destructuring-loose/object-advanced/actual.js new file mode 100644 index 0000000000..c4b85492cf --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/object-advanced/actual.js @@ -0,0 +1 @@ +var {topLeft: {x: x1, y: y1}, bottomRight: {x: x2, y: y2}} = rect; diff --git a/test/fixtures/transformation/es6-destructuring-loose/object-advanced/expected.js b/test/fixtures/transformation/es6-destructuring-loose/object-advanced/expected.js new file mode 100644 index 0000000000..d3ee04ea05 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/object-advanced/expected.js @@ -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; diff --git a/test/fixtures/transformation/es6-destructuring-loose/object-basic/actual.js b/test/fixtures/transformation/es6-destructuring-loose/object-basic/actual.js new file mode 100644 index 0000000000..dae014575e --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/object-basic/actual.js @@ -0,0 +1 @@ +var { x, y } = coords; diff --git a/test/fixtures/transformation/es6-destructuring-loose/object-basic/expected.js b/test/fixtures/transformation/es6-destructuring-loose/object-basic/expected.js new file mode 100644 index 0000000000..97601e8b4e --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/object-basic/expected.js @@ -0,0 +1,4 @@ +"use strict"; + +var x = coords.x; +var y = coords.y; diff --git a/test/fixtures/transformation/es6-destructuring-loose/options.json b/test/fixtures/transformation/es6-destructuring-loose/options.json new file mode 100644 index 0000000000..77a73984e1 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/options.json @@ -0,0 +1,3 @@ +{ + "loose": ["destructuring"] +} diff --git a/test/fixtures/transformation/es6-destructuring-loose/parameters/actual.js b/test/fixtures/transformation/es6-destructuring-loose/parameters/actual.js new file mode 100644 index 0000000000..896a7ce416 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/parameters/actual.js @@ -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])); diff --git a/test/fixtures/transformation/es6-destructuring-loose/parameters/expected.js b/test/fixtures/transformation/es6-destructuring-loose/parameters/expected.js new file mode 100644 index 0000000000..3fd491d5b0 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/parameters/expected.js @@ -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])); diff --git a/test/fixtures/transformation/es6-destructuring-loose/spread/actual.js b/test/fixtures/transformation/es6-destructuring-loose/spread/actual.js new file mode 100644 index 0000000000..0ef8f028ed --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/spread/actual.js @@ -0,0 +1,5 @@ +var isSorted = ([x, y, ...wow]) => { + if (!zs.length) return true + if (y > x) return isSorted(zs) + return false +}; diff --git a/test/fixtures/transformation/es6-destructuring-loose/spread/expected.js b/test/fixtures/transformation/es6-destructuring-loose/spread/expected.js new file mode 100644 index 0000000000..03400c9581 --- /dev/null +++ b/test/fixtures/transformation/es6-destructuring-loose/spread/expected.js @@ -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; +}; diff --git a/test/fixtures/transformation/es6-destructuring/parameters/expected.js b/test/fixtures/transformation/es6-destructuring/parameters/expected.js index a6a1d3dfe6..830eb15edc 100644 --- a/test/fixtures/transformation/es6-destructuring/parameters/expected.js +++ b/test/fixtures/transformation/es6-destructuring/parameters/expected.js @@ -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; }; diff --git a/test/fixtures/transformation/es6-let-scoping/exec-block-scoped-2/exec.js b/test/fixtures/transformation/es6-let-scoping/exec-block-scoped-2/exec.js new file mode 100644 index 0000000000..e98bf47f5e --- /dev/null +++ b/test/fixtures/transformation/es6-let-scoping/exec-block-scoped-2/exec.js @@ -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); diff --git a/test/fixtures/transformation/es6-spread-loose/arguments-array/actual.js b/test/fixtures/transformation/es6-spread-loose/arguments-array/actual.js new file mode 100644 index 0000000000..e18c362b1b --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/arguments-array/actual.js @@ -0,0 +1,9 @@ +function foo() { + return bar([...arguments]); +} + +function bar(one, two, three) { + return [one, two, three]; +} + +foo("foo", "bar"); diff --git a/test/fixtures/transformation/es6-spread-loose/arguments-array/expected.js b/test/fixtures/transformation/es6-spread-loose/arguments-array/expected.js new file mode 100644 index 0000000000..92e9e6ff46 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/arguments-array/expected.js @@ -0,0 +1,11 @@ +"use strict"; + +function foo() { + return bar([].concat(arguments)); +} + +function bar(one, two, three) { + return [one, two, three]; +} + +foo("foo", "bar"); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-spread-loose/arguments-concat/actual.js b/test/fixtures/transformation/es6-spread-loose/arguments-concat/actual.js new file mode 100644 index 0000000000..a6fdb21bef --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/arguments-concat/actual.js @@ -0,0 +1,9 @@ +function foo() { + return bar("test", ...arguments); +} + +function bar(one, two, three) { + return [one, two, three]; +} + +foo("foo", "bar"); diff --git a/test/fixtures/transformation/es6-spread-loose/arguments-concat/expected.js b/test/fixtures/transformation/es6-spread-loose/arguments-concat/expected.js new file mode 100644 index 0000000000..b0bbaef08f --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/arguments-concat/expected.js @@ -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"); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-spread-loose/arguments/actual.js b/test/fixtures/transformation/es6-spread-loose/arguments/actual.js new file mode 100644 index 0000000000..476da431e8 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/arguments/actual.js @@ -0,0 +1,9 @@ +function foo() { + return bar(...arguments); +} + +function bar(one, two, three) { + return [one, two, three]; +} + +foo("foo", "bar"); diff --git a/test/fixtures/transformation/es6-spread-loose/arguments/expected.js b/test/fixtures/transformation/es6-spread-loose/arguments/expected.js new file mode 100644 index 0000000000..52a18f07e7 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/arguments/expected.js @@ -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"); diff --git a/test/fixtures/transformation/es6-spread-loose/array-literal-first/actual.js b/test/fixtures/transformation/es6-spread-loose/array-literal-first/actual.js new file mode 100644 index 0000000000..3857ab97d4 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/array-literal-first/actual.js @@ -0,0 +1 @@ +var lyrics = [...parts, "head", "and", "toes"]; diff --git a/test/fixtures/transformation/es6-spread-loose/array-literal-first/expected.js b/test/fixtures/transformation/es6-spread-loose/array-literal-first/expected.js new file mode 100644 index 0000000000..3d1401d537 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/array-literal-first/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +var lyrics = [].concat(parts, ["head", "and", "toes"]); diff --git a/test/fixtures/transformation/es6-spread-loose/array-literal-middle/actual.js b/test/fixtures/transformation/es6-spread-loose/array-literal-middle/actual.js new file mode 100644 index 0000000000..9b354ad7cf --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/array-literal-middle/actual.js @@ -0,0 +1 @@ +var a = [b, ...c, d]; diff --git a/test/fixtures/transformation/es6-spread-loose/array-literal-middle/expected.js b/test/fixtures/transformation/es6-spread-loose/array-literal-middle/expected.js new file mode 100644 index 0000000000..cc40455aeb --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/array-literal-middle/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +var a = [b].concat(c, [d]); diff --git a/test/fixtures/transformation/es6-spread-loose/array-literal-multiple/actual.js b/test/fixtures/transformation/es6-spread-loose/array-literal-multiple/actual.js new file mode 100644 index 0000000000..e65edc597a --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/array-literal-multiple/actual.js @@ -0,0 +1 @@ +var a = [b, ...c, d, e, ...f]; diff --git a/test/fixtures/transformation/es6-spread-loose/array-literal-multiple/expected.js b/test/fixtures/transformation/es6-spread-loose/array-literal-multiple/expected.js new file mode 100644 index 0000000000..5b55e67414 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/array-literal-multiple/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +var a = [b].concat(c, [d, e], f); diff --git a/test/fixtures/transformation/es6-spread-loose/array-literals/actual.js b/test/fixtures/transformation/es6-spread-loose/array-literals/actual.js new file mode 100644 index 0000000000..5ebb80da66 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/array-literals/actual.js @@ -0,0 +1 @@ +var lyrics = ["head", "and", "toes", ...parts]; diff --git a/test/fixtures/transformation/es6-spread-loose/array-literals/expected.js b/test/fixtures/transformation/es6-spread-loose/array-literals/expected.js new file mode 100644 index 0000000000..4b402a9818 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/array-literals/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +var lyrics = ["head", "and", "toes"].concat(parts); diff --git a/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-multiple-args/actual.js b/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-multiple-args/actual.js new file mode 100644 index 0000000000..305586e2a6 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-multiple-args/actual.js @@ -0,0 +1 @@ +obj[method](foo, bar, ...args); diff --git a/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-multiple-args/expected.js b/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-multiple-args/expected.js new file mode 100644 index 0000000000..6303149d3c --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-multiple-args/expected.js @@ -0,0 +1,4 @@ +"use strict"; + +var _obj; +(_obj = obj)[method].apply(_obj, [foo, bar].concat(args)); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-single-arg/actual.js b/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-single-arg/actual.js new file mode 100644 index 0000000000..65a21cba1e --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-single-arg/actual.js @@ -0,0 +1 @@ +obj[method](...args); diff --git a/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-single-arg/expected.js b/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-single-arg/expected.js new file mode 100644 index 0000000000..786a1efbd7 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/contexted-computed-method-call-single-arg/expected.js @@ -0,0 +1,4 @@ +"use strict"; + +var _obj; +(_obj = obj)[method].apply(_obj, args); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-spread-loose/contexted-method-call-multiple-args/actual.js b/test/fixtures/transformation/es6-spread-loose/contexted-method-call-multiple-args/actual.js new file mode 100644 index 0000000000..7dc7d142a1 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/contexted-method-call-multiple-args/actual.js @@ -0,0 +1,2 @@ +foob.add(foo, bar, ...numbers); +foob.test.add(foo, bar, ...numbers); diff --git a/test/fixtures/transformation/es6-spread-loose/contexted-method-call-multiple-args/expected.js b/test/fixtures/transformation/es6-spread-loose/contexted-method-call-multiple-args/expected.js new file mode 100644 index 0000000000..5c9d6466ef --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/contexted-method-call-multiple-args/expected.js @@ -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)); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-spread-loose/contexted-method-call-single-arg/actual.js b/test/fixtures/transformation/es6-spread-loose/contexted-method-call-single-arg/actual.js new file mode 100644 index 0000000000..ef061e17a8 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/contexted-method-call-single-arg/actual.js @@ -0,0 +1,2 @@ +foob.add(...numbers); +foob.test.add(...numbers); diff --git a/test/fixtures/transformation/es6-spread-loose/contexted-method-call-single-arg/expected.js b/test/fixtures/transformation/es6-spread-loose/contexted-method-call-single-arg/expected.js new file mode 100644 index 0000000000..f03c36ac76 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/contexted-method-call-single-arg/expected.js @@ -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); \ No newline at end of file diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-array-literal/actual.js b/test/fixtures/transformation/es6-spread-loose/method-call-array-literal/actual.js new file mode 100644 index 0000000000..2d1a0bb716 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-array-literal/actual.js @@ -0,0 +1 @@ +f(...[1, 2, 3]); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-array-literal/expected.js b/test/fixtures/transformation/es6-spread-loose/method-call-array-literal/expected.js new file mode 100644 index 0000000000..a370047756 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-array-literal/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +f.apply(undefined, [1, 2, 3]); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-first/actual.js b/test/fixtures/transformation/es6-spread-loose/method-call-first/actual.js new file mode 100644 index 0000000000..0d63c0ea63 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-first/actual.js @@ -0,0 +1 @@ +add(...numbers, foo, bar); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-first/expected.js b/test/fixtures/transformation/es6-spread-loose/method-call-first/expected.js new file mode 100644 index 0000000000..4700d54131 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-first/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +add.apply(undefined, numbers.concat([foo, bar])); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-middle/actual.js b/test/fixtures/transformation/es6-spread-loose/method-call-middle/actual.js new file mode 100644 index 0000000000..b04a3f0223 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-middle/actual.js @@ -0,0 +1 @@ +add(foo, ...numbers, bar); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-middle/expected.js b/test/fixtures/transformation/es6-spread-loose/method-call-middle/expected.js new file mode 100644 index 0000000000..74f6a108ac --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-middle/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +add.apply(undefined, [foo].concat(numbers, [bar])); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-multiple-args/actual.js b/test/fixtures/transformation/es6-spread-loose/method-call-multiple-args/actual.js new file mode 100644 index 0000000000..0a2421b7b4 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-multiple-args/actual.js @@ -0,0 +1 @@ +add(foo, bar, ...numbers); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-multiple-args/expected.js b/test/fixtures/transformation/es6-spread-loose/method-call-multiple-args/expected.js new file mode 100644 index 0000000000..e543eca3db --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-multiple-args/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +add.apply(undefined, [foo, bar].concat(numbers)); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-multiple/actual.js b/test/fixtures/transformation/es6-spread-loose/method-call-multiple/actual.js new file mode 100644 index 0000000000..c06ed01cfb --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-multiple/actual.js @@ -0,0 +1 @@ +add(foo, ...numbers, bar, what, ...test); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-multiple/expected.js b/test/fixtures/transformation/es6-spread-loose/method-call-multiple/expected.js new file mode 100644 index 0000000000..046ac08426 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-multiple/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +add.apply(undefined, [foo].concat(numbers, [bar, what], test)); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-single-arg/actual.js b/test/fixtures/transformation/es6-spread-loose/method-call-single-arg/actual.js new file mode 100644 index 0000000000..a24aa1b09c --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-single-arg/actual.js @@ -0,0 +1 @@ +add(...numbers); diff --git a/test/fixtures/transformation/es6-spread-loose/method-call-single-arg/expected.js b/test/fixtures/transformation/es6-spread-loose/method-call-single-arg/expected.js new file mode 100644 index 0000000000..ef2f902647 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/method-call-single-arg/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +add.apply(undefined, numbers); diff --git a/test/fixtures/transformation/es6-spread-loose/new-expression/actual.js b/test/fixtures/transformation/es6-spread-loose/new-expression/actual.js new file mode 100644 index 0000000000..72800dd42b --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/new-expression/actual.js @@ -0,0 +1,2 @@ +new Numbers(...nums); +new Numbers(1, ...nums); diff --git a/test/fixtures/transformation/es6-spread-loose/new-expression/expected.js b/test/fixtures/transformation/es6-spread-loose/new-expression/expected.js new file mode 100644 index 0000000000..5677c95bec --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/new-expression/expected.js @@ -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)); diff --git a/test/fixtures/transformation/es6-spread-loose/options.json b/test/fixtures/transformation/es6-spread-loose/options.json new file mode 100644 index 0000000000..536a7d71d2 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/options.json @@ -0,0 +1,3 @@ +{ + "loose": "spread" +} diff --git a/test/fixtures/transformation/es6-spread-loose/single/actual.js b/test/fixtures/transformation/es6-spread-loose/single/actual.js new file mode 100644 index 0000000000..6541257708 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/single/actual.js @@ -0,0 +1 @@ +[...foo]; diff --git a/test/fixtures/transformation/es6-spread-loose/single/expected.js b/test/fixtures/transformation/es6-spread-loose/single/expected.js new file mode 100644 index 0000000000..0d7e55ac18 --- /dev/null +++ b/test/fixtures/transformation/es6-spread-loose/single/expected.js @@ -0,0 +1,3 @@ +"use strict"; + +[].concat(foo); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/arguments/actual.js b/test/fixtures/transformation/es7-array-comprehension-loose/arguments/actual.js new file mode 100644 index 0000000000..95f9a4df57 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/arguments/actual.js @@ -0,0 +1,5 @@ +function add() { + return [for (i of [1, 2, 3]) i * arguments[0]]; +} + +add(5); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/arguments/expected.js b/test/fixtures/transformation/es7-array-comprehension-loose/arguments/expected.js new file mode 100644 index 0000000000..39115d87d3 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/arguments/expected.js @@ -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); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single-if/actual.js b/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single-if/actual.js new file mode 100644 index 0000000000..4882336b9f --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single-if/actual.js @@ -0,0 +1 @@ +var arr = [for (i of [1, 2, 3]) if (i > 1) i * i]; diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single-if/expected.js b/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single-if/expected.js new file mode 100644 index 0000000000..0f3f625138 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single-if/expected.js @@ -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; +})(); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single/actual.js b/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single/actual.js new file mode 100644 index 0000000000..2087ae351b --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single/actual.js @@ -0,0 +1 @@ +var arr = [for (i of [1, 2, 3]) i * i]; diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single/expected.js b/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single/expected.js new file mode 100644 index 0000000000..c3ae8d9432 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/array-expression-single/expected.js @@ -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; +})(); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/multiple-if/actual.js b/test/fixtures/transformation/es7-array-comprehension-loose/multiple-if/actual.js new file mode 100644 index 0000000000..754bb7e894 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/multiple-if/actual.js @@ -0,0 +1 @@ +var seattlers = [for (customers of countries) for (c of customers) if (c.city == "Seattle") { name: c.name, age: c.age }]; diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/multiple-if/expected.js b/test/fixtures/transformation/es7-array-comprehension-loose/multiple-if/expected.js new file mode 100644 index 0000000000..6b486b45f5 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/multiple-if/expected.js @@ -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; +})(); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/multiple/actual.js b/test/fixtures/transformation/es7-array-comprehension-loose/multiple/actual.js new file mode 100644 index 0000000000..f0aaa63c27 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/multiple/actual.js @@ -0,0 +1 @@ +var arr = [for (x of "abcdefgh".split("")) for (y of "12345678".split("")) x + y]; diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/multiple/expected.js b/test/fixtures/transformation/es7-array-comprehension-loose/multiple/expected.js new file mode 100644 index 0000000000..05f2c6e76d --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/multiple/expected.js @@ -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; +})(); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/options.json b/test/fixtures/transformation/es7-array-comprehension-loose/options.json new file mode 100644 index 0000000000..6e5e1c6b65 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/options.json @@ -0,0 +1,4 @@ +{ + "experimental": true, + "loose": "arrayComprehension" +} diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/single-if/actual.js b/test/fixtures/transformation/es7-array-comprehension-loose/single-if/actual.js new file mode 100644 index 0000000000..e2cf129386 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/single-if/actual.js @@ -0,0 +1 @@ +var arr = [for (i of nums) if (i > 1) i * i]; diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/single-if/expected.js b/test/fixtures/transformation/es7-array-comprehension-loose/single-if/expected.js new file mode 100644 index 0000000000..6e95f9cadc --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/single-if/expected.js @@ -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; +})(); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/single/actual.js b/test/fixtures/transformation/es7-array-comprehension-loose/single/actual.js new file mode 100644 index 0000000000..9dda19048b --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/single/actual.js @@ -0,0 +1 @@ +var arr = [for (i of nums) i * i]; diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/single/expected.js b/test/fixtures/transformation/es7-array-comprehension-loose/single/expected.js new file mode 100644 index 0000000000..88e01e350a --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/single/expected.js @@ -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; +})(); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/this/actual.js b/test/fixtures/transformation/es7-array-comprehension-loose/this/actual.js new file mode 100644 index 0000000000..355ed48188 --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/this/actual.js @@ -0,0 +1,5 @@ +function add() { + return [for (i of [1, 2, 3]) i * this.multiplier]; +} + +add.call({ multiplier: 5 }); diff --git a/test/fixtures/transformation/es7-array-comprehension-loose/this/expected.js b/test/fixtures/transformation/es7-array-comprehension-loose/this/expected.js new file mode 100644 index 0000000000..5645b53dcc --- /dev/null +++ b/test/fixtures/transformation/es7-array-comprehension-loose/this/expected.js @@ -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 }); diff --git a/test/fixtures/transformation/es7-generator-comprehension-loose/options.json b/test/fixtures/transformation/es7-generator-comprehension-loose/options.json new file mode 100644 index 0000000000..4fdef2f3ff --- /dev/null +++ b/test/fixtures/transformation/es7-generator-comprehension-loose/options.json @@ -0,0 +1,4 @@ +{ + "experimental": true, + "loose": "generatorComprehension" +} diff --git a/test/fixtures/transformation/es7-generator-comprehension-loose/simple/exec.js b/test/fixtures/transformation/es7-generator-comprehension-loose/simple/exec.js new file mode 100644 index 0000000000..dd7ef4da0a --- /dev/null +++ b/test/fixtures/transformation/es7-generator-comprehension-loose/simple/exec.js @@ -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);