From 830f8392d1492cff3fba4b75ab35d1670165ac25 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 17 Dec 2019 13:59:24 -0800 Subject: [PATCH] [Refactor] avoid top-level return, because babel and webpack are broken Closes https://github.com/inspect-js/node-deep-equal/issues/79. Closes https://github.com/inspect-js/node-deep-equal/issues/78. Closes https://github.com/es-shims/Promise.allSettled/issues/7. Closes https://github.com/airbnb/js-shims/issues/12. Relates to: - https://github.com/inspect-js/is-map/pull/5 - https://github.com/inspect-js/is-map/pull/4 - https://github.com/inspect-js/is-map/pull/3 - https://github.com/inspect-js/is-set/pull/5 - https://github.com/inspect-js/is-set/pull/4 - https://github.com/storybookjs/storybook/issues/9154. --- index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index b68555c..f7359a2 100644 --- a/index.js +++ b/index.js @@ -3,27 +3,27 @@ var $WeakMap = typeof WeakMap === 'function' && WeakMap.prototype ? WeakMap : null; var $WeakSet = typeof WeakSet === 'function' && WeakSet.prototype ? WeakSet : null; +var exported; + if (!$WeakMap) { // eslint-disable-next-line no-unused-vars - module.exports = function isWeakMap(x) { + exported = function isWeakMap(x) { // `WeakMap` is not present in this environment. return false; }; - return; } var $mapHas = $WeakMap ? $WeakMap.prototype.has : null; var $setHas = $WeakSet ? $WeakSet.prototype.has : null; -if (!$mapHas) { +if (!exported && !$mapHas) { // eslint-disable-next-line no-unused-vars - module.exports = function isWeakMap(x) { + exported = function isWeakMap(x) { // `WeakMap` does not have a `has` method return false; }; - return; } -module.exports = function isWeakMap(x) { +module.exports = exported || function isWeakMap(x) { if (!x || typeof x !== 'object') { return false; }