From 3d874f2479ab34ec6ffa79f77152cbb49eae4602 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 13 Feb 2015 20:45:43 +1100 Subject: [PATCH] update sliceToArray helper, again... --- lib/6to5/transformation/templates/sliced-to-array.js | 8 ++++---- .../bin/6to5-node/filename/in-files/{foo.js => bar.js} | 0 test/fixtures/bin/6to5-node/filename/options.json | 2 +- .../transformation/es6-destructuring/array/expected.js | 2 +- .../es6-destructuring/assignment-expression/expected.js | 2 +- .../es6-destructuring/assignment-statement/expected.js | 2 +- .../transformation/es6-destructuring/empty/expected.js | 2 +- .../transformation/es6-destructuring/for-in/expected.js | 2 +- .../transformation/es6-destructuring/for-of/expected.js | 2 +- .../es6-destructuring/member-expression/expected.js | 2 +- .../transformation/es6-destructuring/mixed/expected.js | 2 +- .../es6-destructuring/parameters/expected.js | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) rename test/fixtures/bin/6to5-node/filename/in-files/{foo.js => bar.js} (100%) diff --git a/lib/6to5/transformation/templates/sliced-to-array.js b/lib/6to5/transformation/templates/sliced-to-array.js index 3ef086127c..af2f04e8e7 100644 --- a/lib/6to5/transformation/templates/sliced-to-array.js +++ b/lib/6to5/transformation/templates/sliced-to-array.js @@ -1,14 +1,14 @@ (function (arr, i) { - if (Array.isArray(arr)) { + if (!arr || !arr[Symbol.iterator]) { + throw new TypeError("Invalid attempt to destructure non-iterable instance"); + } else if (Array.isArray(arr)) { return arr; - } else if (Symbol.iterator in arr) { + } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; - } else { - throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }); diff --git a/test/fixtures/bin/6to5-node/filename/in-files/foo.js b/test/fixtures/bin/6to5-node/filename/in-files/bar.js similarity index 100% rename from test/fixtures/bin/6to5-node/filename/in-files/foo.js rename to test/fixtures/bin/6to5-node/filename/in-files/bar.js diff --git a/test/fixtures/bin/6to5-node/filename/options.json b/test/fixtures/bin/6to5-node/filename/options.json index 36b991ad38..d9bcfc2f57 100644 --- a/test/fixtures/bin/6to5-node/filename/options.json +++ b/test/fixtures/bin/6to5-node/filename/options.json @@ -1,3 +1,3 @@ { - "args": ["foo"] + "args": ["bar"] } diff --git a/test/fixtures/transformation/es6-destructuring/array/expected.js b/test/fixtures/transformation/es6-destructuring/array/expected.js index 790c36e041..80f0f225e7 100644 --- a/test/fixtures/transformation/es6-destructuring/array/expected.js +++ b/test/fixtures/transformation/es6-destructuring/array/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; var _ref = ["hello", [", ", "junk"], ["world"]]; diff --git a/test/fixtures/transformation/es6-destructuring/assignment-expression/expected.js b/test/fixtures/transformation/es6-destructuring/assignment-expression/expected.js index 007f89b03b..dc77a31667 100644 --- a/test/fixtures/transformation/es6-destructuring/assignment-expression/expected.js +++ b/test/fixtures/transformation/es6-destructuring/assignment-expression/expected.js @@ -1,6 +1,6 @@ "use strict"; var _temp, _temp2; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; console.log((_temp = [123], _temp2 = _slicedToArray(_temp, 1), x = _temp2[0], _temp)); diff --git a/test/fixtures/transformation/es6-destructuring/assignment-statement/expected.js b/test/fixtures/transformation/es6-destructuring/assignment-statement/expected.js index 5f81ff3920..858f09bbdc 100644 --- a/test/fixtures/transformation/es6-destructuring/assignment-statement/expected.js +++ b/test/fixtures/transformation/es6-destructuring/assignment-statement/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; var _ref = f(); diff --git a/test/fixtures/transformation/es6-destructuring/empty/expected.js b/test/fixtures/transformation/es6-destructuring/empty/expected.js index 42bfc53ba0..1d65a1a529 100644 --- a/test/fixtures/transformation/es6-destructuring/empty/expected.js +++ b/test/fixtures/transformation/es6-destructuring/empty/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; var _ref = ["foo", "hello", [", ", "junk"], ["world"]]; diff --git a/test/fixtures/transformation/es6-destructuring/for-in/expected.js b/test/fixtures/transformation/es6-destructuring/for-in/expected.js index f20f1ca756..f745b66aaf 100644 --- a/test/fixtures/transformation/es6-destructuring/for-in/expected.js +++ b/test/fixtures/transformation/es6-destructuring/for-in/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; for (var _ref in obj) { var _ref2 = _slicedToArray(_ref, 2); diff --git a/test/fixtures/transformation/es6-destructuring/for-of/expected.js b/test/fixtures/transformation/es6-destructuring/for-of/expected.js index 7d1d2c9375..0153f013e7 100644 --- a/test/fixtures/transformation/es6-destructuring/for-of/expected.js +++ b/test/fixtures/transformation/es6-destructuring/for-of/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; for (var _iterator = test.expectation.registers[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { var _step$value = _slicedToArray(_step.value, 3); diff --git a/test/fixtures/transformation/es6-destructuring/member-expression/expected.js b/test/fixtures/transformation/es6-destructuring/member-expression/expected.js index 8d7c06bb2a..bde82a9e06 100644 --- a/test/fixtures/transformation/es6-destructuring/member-expression/expected.js +++ b/test/fixtures/transformation/es6-destructuring/member-expression/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; var _ref = [1, 2]; diff --git a/test/fixtures/transformation/es6-destructuring/mixed/expected.js b/test/fixtures/transformation/es6-destructuring/mixed/expected.js index 23601213ee..b350be4d80 100644 --- a/test/fixtures/transformation/es6-destructuring/mixed/expected.js +++ b/test/fixtures/transformation/es6-destructuring/mixed/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; var _rect$topLeft = _slicedToArray(rect.topLeft, 2); diff --git a/test/fixtures/transformation/es6-destructuring/parameters/expected.js b/test/fixtures/transformation/es6-destructuring/parameters/expected.js index 3f991923c5..e1332ba704 100644 --- a/test/fixtures/transformation/es6-destructuring/parameters/expected.js +++ b/test/fixtures/transformation/es6-destructuring/parameters/expected.js @@ -1,6 +1,6 @@ "use strict"; -var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in arr) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; +var _slicedToArray = function (arr, i) { if (!arr || !arr[Symbol.iterator]) { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } else if (Array.isArray(arr)) { return arr; } else { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } }; function somethingAdvanced(_ref) { var _ref$topLeft = _ref.topLeft;