Skip to content

Commit

Permalink
fix: early return when instance is not iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Sep 5, 2019
1 parent 2e7bea4 commit 017b026
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/babel-helpers/src/helpers.js
Expand Up @@ -943,7 +943,7 @@ helpers.iterableToArrayLimit = helper("7.0.0-beta.0")`
// _e = _iteratorError
// _i = _iterator
// _s = _step
if (!Symbol.iterator in Object(arr)) return;
var _arr = [];
var _n = true;
var _d = false;
Expand All @@ -969,6 +969,7 @@ helpers.iterableToArrayLimit = helper("7.0.0-beta.0")`

helpers.iterableToArrayLimitLoose = helper("7.0.0-beta.0")`
export default function _iterableToArrayLimitLoose(arr, i) {
if (!Symbol.iterator in Object(arr)) return;
var _arr = [];
for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) {
_arr.push(_step.value);
Expand Down
@@ -0,0 +1,9 @@
expect(
() => {
var [foo, bar] = undefined;
}).toThrow("Invalid attempt to destructure non-iterable instance");

expect(
() => {
var foo = [ ...undefined ];
}).toThrow("Invalid attempt to spread non-iterable instance");

0 comments on commit 017b026

Please sign in to comment.