Skip to content

Commit

Permalink
Fixes babel#7597
Browse files Browse the repository at this point in the history
Update babel helpers to not require Symbol to exist. We ran into an issue with ie11 where Symbol is not supported. This PR gaurds the usage of Symbol by ensuring that it exists first. There are also changes that allow objects with a length property and array-like objects to work with `iterableToArray`.
  • Loading branch information
sharmilajesupaul committed Nov 5, 2018
1 parent c6d2f45 commit fa86391
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
17 changes: 13 additions & 4 deletions packages/babel-helpers/src/helpers.js
Expand Up @@ -861,8 +861,13 @@ helpers.arrayWithHoles = helper("7.0.0-beta.0")`
helpers.iterableToArray = helper("7.0.0-beta.0")`
export default function _iterableToArray(iter) {
if (
Symbol.iterator in Object(iter) ||
Object.prototype.toString.call(iter) === "[object Arguments]"
Array.isArray(iter)
|| typeof iter === 'string'
|| (typeof Symbol === 'function' && Symbol.iterator in Object(iter))
|| (iter && 'length' in iter)
|| (typeof Map !== 'undefined' && iter instanceof Map)
|| (typeof Set !== 'undefined' && iter instanceof Set)
|| Object.prototype.toString.call(iter) === "[object Arguments]"
) return Array.from(iter);
}
`;
Expand Down Expand Up @@ -1562,7 +1567,9 @@ helpers.decorate = helper("7.1.5")`
value: "Descriptor",
configurable: true,
};
Object.defineProperty(obj, Symbol.toStringTag, desc);
if (typeof Symbol === 'function' && Symbol.toStringTag)
Object.defineProperty(obj, Symbol.toStringTag, desc);
if (element.kind === "field") obj.initializer = element.initializer;
Expand Down Expand Up @@ -1675,7 +1682,9 @@ helpers.decorate = helper("7.1.5")`
};
var desc = { value: "Descriptor", configurable: true };
Object.defineProperty(obj, Symbol.toStringTag, desc);
if (typeof Symbol === 'function' && Symbol.toStringTag)
Object.defineProperty(obj, Symbol.toStringTag, desc);
return obj;
}
Expand Down
@@ -1,5 +1,9 @@
import _Array$from from "../../core-js/array/from";
import _Set from "../../core-js/set";
import _Map from "../../core-js/map";
import _isIterable from "../../core-js/is-iterable";
import _Symbol from "../../core-js/symbol";
import _Array$isArray from "../../core-js/array/is-array";
export default function _iterableToArray(iter) {
if (_isIterable(Object(iter)) || Object.prototype.toString.call(iter) === "[object Arguments]") return _Array$from(iter);
if (_Array$isArray(iter) || typeof iter === 'string' || typeof _Symbol === 'function' && _isIterable(Object(iter)) || iter && 'length' in iter || typeof _Map !== 'undefined' && iter instanceof _Map || typeof _Set !== 'undefined' && iter instanceof _Set || Object.prototype.toString.call(iter) === "[object Arguments]") return _Array$from(iter);
}
10 changes: 9 additions & 1 deletion packages/babel-runtime-corejs2/helpers/iterableToArray.js
@@ -1,9 +1,17 @@
var _Array$from = require("../core-js/array/from");

var _Set = require("../core-js/set");

var _Map = require("../core-js/map");

var _isIterable = require("../core-js/is-iterable");

var _Symbol = require("../core-js/symbol");

var _Array$isArray = require("../core-js/array/is-array");

function _iterableToArray(iter) {
if (_isIterable(Object(iter)) || Object.prototype.toString.call(iter) === "[object Arguments]") return _Array$from(iter);
if (_Array$isArray(iter) || typeof iter === 'string' || typeof _Symbol === 'function' && _isIterable(Object(iter)) || iter && 'length' in iter || typeof _Map !== 'undefined' && iter instanceof _Map || typeof _Set !== 'undefined' && iter instanceof _Set || Object.prototype.toString.call(iter) === "[object Arguments]") return _Array$from(iter);
}

module.exports = _iterableToArray;
2 changes: 1 addition & 1 deletion packages/babel-runtime/helpers/esm/iterableToArray.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/babel-runtime/helpers/iterableToArray.js
@@ -1,5 +1,5 @@
function _iterableToArray(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
if (Array.isArray(iter) || typeof iter === 'string' || typeof Symbol === 'function' && Symbol.iterator in Object(iter) || iter && 'length' in iter || typeof Map !== 'undefined' && iter instanceof Map || typeof Set !== 'undefined' && iter instanceof Set || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}

module.exports = _iterableToArray;

0 comments on commit fa86391

Please sign in to comment.