From 9c7ce6c5ef918cea38181c49914f37ec5a0b90d9 Mon Sep 17 00:00:00 2001 From: Christian Zosel Date: Sat, 3 Feb 2024 15:07:39 +0100 Subject: [PATCH] chore: replace memoize dependency with own implementation --- .github/workflows/nodejs.yml | 2 +- package.json | 1 - src/pragma.mjs | 2 +- src/util.mjs | 11 +++++++++++ yarn.lock | 12 ------------ 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 38b6f5e2e..185170062 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -30,7 +30,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - node-version: [18.x, 20.x, 21.x] + node-version: [16.x, 18.x, 20.x] env: ENABLE_COVERAGE: true diff --git a/package.json b/package.json index 3cf61afff..11cb28176 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ ], "dependencies": { "linguist-languages": "^7.27.0", - "memoize": "^10.0.0", "php-parser": "^3.1.5" }, "devDependencies": { diff --git a/src/pragma.mjs b/src/pragma.mjs index dc6b7da01..976baa7d9 100644 --- a/src/pragma.mjs +++ b/src/pragma.mjs @@ -1,4 +1,4 @@ -import memoize from "memoize"; +import { memoize } from "./util.mjs"; import parse from "./parser.mjs"; const reHasPragma = /@prettier|@format/; diff --git a/src/util.mjs b/src/util.mjs index 6890e7d9e..1bda959a2 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -685,6 +685,16 @@ function isSimpleCallArgument(node, depth = 2) { return false; } +function memoize(fn) { + const cache = new Map(); + return (key) => { + if (!cache.has(key)) { + cache.set(key, fn(key)); + } + return cache.get(key); + }; +} + export { printNumber, getPrecedence, @@ -715,4 +725,5 @@ export { getAncestorNode, normalizeMagicMethodName, isSimpleCallArgument, + memoize, }; diff --git a/yarn.lock b/yarn.lock index fcbb17217..b754bee8f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4704,13 +4704,6 @@ makeerror@1.0.12: dependencies: tmpl "1.0.5" -memoize@^10.0.0: - version "10.0.0" - resolved "https://registry.yarnpkg.com/memoize/-/memoize-10.0.0.tgz#43fa66b2022363c7c50cf5dfab732a808a3d7147" - integrity sha512-H6cBLgsi6vMWOcCpvVCdFFnl3kerEXbrYh9q+lY6VXvQSmM6CkmV08VOwT+WE2tzIEqRPFfAq3fm4v/UIW6mSA== - dependencies: - mimic-function "^5.0.0" - merge-stream@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60" @@ -4751,11 +4744,6 @@ mimic-fn@^4.0.0: resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-4.0.0.tgz#60a90550d5cb0b239cca65d893b1a53b29871ecc" integrity sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw== -mimic-function@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/mimic-function/-/mimic-function-5.0.0.tgz#6cb5a922d17923ee58cf2f7d904f3eb350e0c87a" - integrity sha512-RBfQ+9X9DpXdEoK7Bu+KeEU6vFhumEIiXKWECPzRBmDserEq4uR2b/VCm0LwpMSosoq2k+Zuxj/GzOr0Fn6h/g== - minimatch@^3.0.4, minimatch@^3.0.5, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b"