Skip to content

Commit

Permalink
[Refactor] use call-bound directly
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Dec 17, 2024
1 parent ebd5d82 commit 265971b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';

var GetIntrinsic = require('get-intrinsic');
var callBound = require('call-bind/callBound');
var callBound = require('call-bound');

var $WeakSet = GetIntrinsic('%WeakSet%', true);

/** @type {undefined | (<V>(thisArg: Set<V>, value: V) => boolean)} */
var $setHas = callBound('WeakSet.prototype.has', true);

if ($setHas) {
/** @type {undefined | (<K extends object, V>(thisArg: WeakMap<K, V>, key: K) => boolean)} */
var $mapHas = callBound('WeakMap.prototype.has', true);

/** @type {import('.')} */
Expand All @@ -16,9 +18,11 @@ if ($setHas) {
return false;
}
try {
// @ts-expect-error TS can't figure out that $setHas is always truthy here
$setHas(x, $setHas);
if ($mapHas) {
try {
// @ts-expect-error this indeed might not be a weak collection
$mapHas(x, $mapHas);
} catch (e) {
return true;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@
},
"homepage": "https://github.com/inspect-js/is-weakset#readme",
"dependencies": {
"call-bind": "^1.0.8",
"call-bound": "^1.0.3",
"get-intrinsic": "^1.2.6"
},
"devDependencies": {
"@arethetypeswrong/cli": "^0.17.1",
"@ljharb/eslint-config": "^21.1.1",
"@ljharb/tsconfig": "^0.2.2",
"@types/call-bind": "^1.0.5",
"@types/for-each": "^0.3.3",
"@types/get-intrinsic": "^1.2.3",
"@types/object-inspect": "^1.13.0",
Expand Down

0 comments on commit 265971b

Please sign in to comment.