Skip to content

Commit

Permalink
Fixes babel#7597
Browse files Browse the repository at this point in the history
Ensure that `Symbol` exists and is a function before using it. We ran into an issue with the usage of `Symbol` breaking on ie11 because it is not supported.
  • Loading branch information
sharmilajesupaul committed Oct 31, 2018
1 parent de80aef commit 0ba8392
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/babel-helpers/src/helpers.js
Expand Up @@ -1539,7 +1539,8 @@ helpers.decorate = helper("7.0.2")`
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 @@ -1653,7 +1654,8 @@ helpers.decorate = helper("7.0.2")`
};
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
12 changes: 10 additions & 2 deletions packages/babel-runtime/helpers/esm/iterableToArray.js
@@ -1,3 +1,11 @@
export default 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);
}
10 changes: 9 additions & 1 deletion packages/babel-runtime/helpers/iterableToArray.js
@@ -1,5 +1,13 @@
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 0ba8392

Please sign in to comment.