babel/src/babel/transformation/templates/helper-sliced-to-array.js
2015-03-23 17:26:54 +11:00

39 lines
1.1 KiB
JavaScript

(function (arr, i) {
if (arr && arr.constructor === Array) {
return arr;
} else if (Symbol.iterator in Object(arr)) {
// this is an expanded form of `for...of` that properly supports abrupt completions of
// iterators etc. variable names have been minimised to reduce the size of this massive
// helper. sometimes spec compliancy is annoying :()
//
// _n = _iteratorNormalCompletion
// _d = _didIteratorError
// _e = _iteratorError
// _i = _iterator
// _s = _step
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"]) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
} else {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
});