Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "return" outside of function issue #5

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 8 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
'use strict';

var $Map = typeof Map === 'function' && Map.prototype ? Map : null;
var $Set = typeof Set === 'function' && Set.prototype ? Set : null;
var $mapHas = typeof Map === 'function' && Map.prototype && Map.prototype.has;
var $setHas = typeof Set === 'function' && Set.prototype && Set.prototype.has;

if (!$Map) {
// eslint-disable-next-line no-unused-vars
module.exports = function isMap(x) {
// `Map` is not present in this environment.
return false;
};
return;
}

var $mapHas = $Map ? Map.prototype.has : null;
var $setHas = $Set ? Set.prototype.has : null;
if (!$mapHas) {
// eslint-disable-next-line no-unused-vars
module.exports = function isMap(x) {
// `Map` does not have a `has` method
return false;
};
return;
}

module.exports = function isMap(x) {
if (!x || typeof x !== 'object') {
module.exports = function isSet(x) {
if (!$mapHas || !x || typeof x !== 'object') {
// `Set` is either not present in this environment or does not have a `has` method, or the argument is of an incorrect type
return false;
}

try {
$mapHas.call(x);
if ($setHas) {
Expand All @@ -36,7 +18,8 @@ module.exports = function isMap(x) {
return true;
}
}
return x instanceof $Map; // core-js workaround, pre-v2.5.0
return x instanceof Map; // core-js workaround, pre-v2.5.0
} catch (e) {}

return false;
};