Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: early return when instance is not iterable #10396

Merged
merged 3 commits into from Sep 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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");