From 130f0a6adbc04d385c7456a601d38344dce3d6a9 Mon Sep 17 00:00:00 2001 From: Tofandel Date: Mon, 14 Mar 2022 11:52:09 +0100 Subject: [PATCH 1/3] [meta] add `.editorconfig`; add `eclint` --- .editorconfig | 9 +++++++++ .eslintrc | 1 + index.js | 17 +++++------------ package.json | 2 ++ 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..72e0eba --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = tab +indent_size = 2 +trim_trailing_whitespace = true diff --git a/.eslintrc b/.eslintrc index e862764..93978e7 100644 --- a/.eslintrc +++ b/.eslintrc @@ -5,6 +5,7 @@ "rules": { "max-lines-per-function": 0, + "multiline-comment-style": 1, "new-cap": [2, { "capIsNewExceptions": ["GetIntrinsic"] }], }, } diff --git a/index.js b/index.js index f1c4826..a8bf3c7 100644 --- a/index.js +++ b/index.js @@ -16,13 +16,10 @@ var $mapSet = callBound('Map.prototype.set', true); var $mapHas = callBound('Map.prototype.has', true); /* - * This function traverses the list returning the node corresponding to the - * given key. - * - * That node is also moved to the head of the list, so that if it's accessed - * again we don't need to traverse the whole list. By doing so, all the recently - * used nodes can be accessed relatively quickly. - */ +* This function traverses the list returning the node corresponding to the given key. +* +* That node is also moved to the head of the list, so that if it's accessed again we don't need to traverse the whole list. By doing so, all the recently used nodes can be accessed relatively quickly. +*/ var listGetNode = function (list, key) { // eslint-disable-line consistent-return for (var prev = list, curr; (curr = prev.next) !== null; prev = curr) { if (curr.key === key) { @@ -109,11 +106,7 @@ module.exports = function getSideChannel() { $mapSet($m, key, value); } else { if (!$o) { - /* - * Initialize the linked list as an empty node, so that we don't have - * to special-case handling of the first node: we can always refer to - * it as (previous node).next, instead of something like (list).head - */ + // Initialize the linked list as an empty node, so that we don't have to special-case handling of the first node: we can always refer to it as (previous node).next, instead of something like (list).head $o = { key: {}, next: null }; } listSet($o, key, value); diff --git a/package.json b/package.json index ac81e74..30fe05c 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "scripts": { "prepublishOnly": "safe-publish-latest", "prepublish": "not-in-publish || npm run prepublishOnly", + "prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "tests-only": "nyc tape 'test/**/*.js'", @@ -47,6 +48,7 @@ "@ljharb/eslint-config": "^20.2.3", "aud": "^2.0.0", "auto-changelog": "^2.4.0", + "eclint": "^2.8.1", "eslint": "=8.8.0", "nyc": "^10.3.2", "safe-publish-latest": "^2.0.0", From 5130877a7b27c862e64e6d1c12a178b28808859d Mon Sep 17 00:00:00 2001 From: Tofandel Date: Mon, 14 Mar 2022 11:52:09 +0100 Subject: [PATCH 2/3] [Tests] increase coverage --- test/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/index.js b/test/index.js index 3b92ef7..b663b03 100644 --- a/test/index.js +++ b/test/index.js @@ -39,6 +39,11 @@ test('has', function (t) { channel.set(o, 'foo'); t.equal(channel.has(o), true, 'existent value yields true'); + t.equal(channel.has('abc'), false, 'non object value non existent yields false'); + + channel.set('abc', 'foo'); + t.equal(channel.has('abc'), true, 'non object value that exists yields true'); + t.end(); }); From 0f1b586d5d486e2b08d73e2f9d85732c6480f3d8 Mon Sep 17 00:00:00 2001 From: Tofandel Date: Mon, 14 Mar 2022 11:52:09 +0100 Subject: [PATCH 3/3] [Refactor] Reduce size by removing call-bind/get-intrinsic --- index.js | 27 ++++++++++++++++----------- package.json | 3 +-- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index a8bf3c7..0e77d99 100644 --- a/index.js +++ b/index.js @@ -1,19 +1,24 @@ 'use strict'; -var GetIntrinsic = require('get-intrinsic'); -var callBound = require('call-bind/callBound'); var inspect = require('object-inspect'); +var bind = require('function-bind'); -var $TypeError = GetIntrinsic('%TypeError%'); -var $WeakMap = GetIntrinsic('%WeakMap%', true); -var $Map = GetIntrinsic('%Map%', true); +var $call = Function.prototype.call; -var $weakMapGet = callBound('WeakMap.prototype.get', true); -var $weakMapSet = callBound('WeakMap.prototype.set', true); -var $weakMapHas = callBound('WeakMap.prototype.has', true); -var $mapGet = callBound('Map.prototype.get', true); -var $mapSet = callBound('Map.prototype.set', true); -var $mapHas = callBound('Map.prototype.has', true); +var callBound = function (original) { + return $call.call(bind, $call, original); +}; + +var $TypeError = TypeError; +var $WeakMap = typeof WeakMap === 'function' ? WeakMap : undefined; +var $Map = typeof Map === 'function' ? Map : undefined; + +var $weakMapGet = $WeakMap ? callBound($WeakMap.prototype.get) : undefined; +var $weakMapSet = $WeakMap ? callBound($WeakMap.prototype.set) : undefined; +var $weakMapHas = $WeakMap ? callBound($WeakMap.prototype.has) : undefined; +var $mapGet = $Map ? callBound($Map.prototype.get) : undefined; +var $mapSet = $Map ? callBound($Map.prototype.set) : undefined; +var $mapHas = $Map ? callBound($Map.prototype.has) : undefined; /* * This function traverses the list returning the node corresponding to the given key. diff --git a/package.json b/package.json index 30fe05c..b2b8e70 100644 --- a/package.json +++ b/package.json @@ -55,8 +55,7 @@ "tape": "^5.5.2" }, "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1", + "function-bind": "^1.1.1", "object-inspect": "^1.12.0" }, "auto-changelog": {