Allow rest/spread on polyfilled or builtin iterables without Symbol support (#11268)
* Allow rest/spread on polyfilled or builtin iterables when `Symbol` unsupported Currently, when `Symbol` is not supported, we allow using rest/spread with: - arrays - strings - arguments With this PR, it will be also possible to use it with - maps - sets - binary arrays While in old browsers es6 builtins would still need to be polyfilled, it's way easier to polyfill them because `Symbol` cannot be reliably polyfilled. I didn't use `instanceof` becase: - it doesn't work with polyfills not attatched to the global scope - when using Babel to load polyfills, it would force the inclusion of `Map` and `Set` polyfills even if they are not used Downside: the current approach of relying on `toString || construcor.name` doesn't work with subclasses. * Don't use Array.from for array-like objects
This commit is contained in:
@@ -5,7 +5,7 @@ var _isIterable = require("../core-js/is-iterable");
|
||||
var _Symbol = require("../core-js/symbol");
|
||||
|
||||
function _iterableToArray(iter) {
|
||||
if (typeof iter === 'string' || Object.prototype.toString.call(iter) === "[object Arguments]" || typeof _Symbol !== "undefined" && _isIterable(Object(iter))) return _Array$from(iter);
|
||||
if (typeof _Symbol !== "undefined" && _isIterable(Object(iter))) return _Array$from(iter);
|
||||
}
|
||||
|
||||
module.exports = _iterableToArray;
|
||||
Reference in New Issue
Block a user