From 09e6a49bea6d6fe5af802905676253fc131b8e5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20S=C3=A1nchez?= Date: Sat, 27 Dec 2025 18:22:11 +0000 Subject: [PATCH] Inline fixed get-params + handle falsy values in flatTree --- .changeset/puny-phones-like.md | 5 ++ packages/redux-devtools-utils/package.json | 2 - packages/redux-devtools-utils/src/index.ts | 72 +++++++++++++++++++++- pnpm-lock.yaml | 16 ----- 4 files changed, 76 insertions(+), 19 deletions(-) create mode 100644 .changeset/puny-phones-like.md diff --git a/.changeset/puny-phones-like.md b/.changeset/puny-phones-like.md new file mode 100644 index 00000000..5b1ab068 --- /dev/null +++ b/.changeset/puny-phones-like.md @@ -0,0 +1,5 @@ +--- +'@redux-devtools/utils': patch +--- + +Fix function parameters detection diff --git a/packages/redux-devtools-utils/package.json b/packages/redux-devtools-utils/package.json index 264e4b28..7afab6c5 100644 --- a/packages/redux-devtools-utils/package.json +++ b/packages/redux-devtools-utils/package.json @@ -35,8 +35,6 @@ "@babel/runtime": "^7.28.4", "@redux-devtools/core": "workspace:^", "@redux-devtools/serialize": "workspace:^", - "@types/get-params": "^0.1.2", - "get-params": "^0.1.2", "immutable": "^5.1.4", "jsan": "^3.1.14", "nanoid": "^5.1.6", diff --git a/packages/redux-devtools-utils/src/index.ts b/packages/redux-devtools-utils/src/index.ts index 75120714..63d2b1dc 100644 --- a/packages/redux-devtools-utils/src/index.ts +++ b/packages/redux-devtools-utils/src/index.ts @@ -1,4 +1,3 @@ -import getParams from 'get-params'; import jsan from 'jsan'; import { nanoid } from 'nanoid/non-secure'; import { immutableSerialize } from '@redux-devtools/serialize'; @@ -15,13 +14,84 @@ export interface ActionCreatorObject { readonly args: readonly string[]; } +function getParams(func: Function) { + if (typeof func !== 'function') return []; + + const src = func + .toString() + // remove comments + .replace(/\/\*[\s\S]*?\*\//g, '') + .replace(/\/\/.*$/gm, '') + .trim(); + + let paramsSrc = ''; + + // function foo(a, b) + const fnMatch = src.match(/^[^(]*\(\s*([^)]*)\)/); + + // (a, b) => or a => + const arrowMatch = src.match(/^(?:\(\s*([^)]*)\)|([^\s=]+))\s*=>/); + + if (fnMatch) { + paramsSrc = fnMatch[1] ?? ''; + } else if (arrowMatch) { + paramsSrc = arrowMatch[1] ?? arrowMatch[2] ?? ''; + } else { + return []; + } + + if (!paramsSrc) return []; + + const params = []; + let current = ''; + let depth = 0; + + for (let i = 0; i < paramsSrc.length; i++) { + const ch = paramsSrc[i]; + + if (ch === ',' && depth === 0) { + params.push(current.trim()); + current = ''; + continue; + } + + if (ch === '{' || ch === '[' || ch === '(') depth++; + if (ch === '}' || ch === ']' || ch === ')') depth--; + + current += ch; + } + + if (current.trim()) { + params.push(current.trim()); + } + + // remove default values: a = 1 → a + return params.map((p, i) => { + const cleaned = p.replace(/=.*/, '').trim(); + + // destructured parameter + if ( + cleaned.startsWith('{') || + cleaned.startsWith('[') || + cleaned.startsWith('...{') || + cleaned.startsWith('...[') + ) { + return `arg_${i}`; + } + + return cleaned; + }); +} + function flatTree( obj: { [key: string]: ActionCreator> }, namespace = '', ) { + if (!obj) return []; let functions: ActionCreatorObject[] = []; Object.keys(obj).forEach((key) => { const prop = obj[key]; + if (!prop) return; if (typeof prop === 'function') { functions.push({ name: namespace + (key || prop.name || 'anonymous'), diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 27ce9b94..c289ac6e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2499,12 +2499,6 @@ importers: '@redux-devtools/serialize': specifier: workspace:^ version: link:../redux-devtools-serialize - '@types/get-params': - specifier: ^0.1.2 - version: 0.1.2 - get-params: - specifier: ^0.1.2 - version: 0.1.2 immutable: specifier: ^5.1.4 version: 5.1.4 @@ -4811,9 +4805,6 @@ packages: '@types/geojson@7946.0.16': resolution: {integrity: sha512-6C8nqWur3j98U6+lXDfTUWIfgvZU+EumvpHKcYjujKH7woYyLj2sUmff0tRhrqM7BohUw7Pz3ZB1jj2gW9Fvmg==} - '@types/get-params@0.1.2': - resolution: {integrity: sha512-ujqPyr1UDsOTDngJPV+WFbR0iHT5AfZKlNPMX6XOCnQcMhEqR+r64dVC/nwYCitqjR3DcpWofnOEAInUQmI/eA==} - '@types/har-format@1.2.16': resolution: {integrity: sha512-fluxdy7ryD3MV6h8pTfTYpy/xQzCFC7m89nOH9y94cNqJ1mDIDPut7MnRHI3F6qRmh/cT2fUjG1MLdCNb4hE9A==} @@ -7129,9 +7120,6 @@ packages: resolution: {integrity: sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==} engines: {node: '>=8.0.0'} - get-params@0.1.2: - resolution: {integrity: sha512-41eOxtlGgHQRbFyA8KTH+w+32Em3cRdfBud7j67ulzmIfmaHX9doq47s0fa4P5o9H64BZX9nrYI6sJvk46Op+Q==} - get-port@7.1.0: resolution: {integrity: sha512-QB9NKEeDg3xxVwCCwJQ9+xycaz6pBB6iQ76wiWMl1927n0Kir6alPiP+yuiICLLU4jpMe08dXfpebuQppFA2zw==} engines: {node: '>=16'} @@ -12929,8 +12917,6 @@ snapshots: '@types/geojson@7946.0.16': {} - '@types/get-params@0.1.2': {} - '@types/har-format@1.2.16': {} '@types/hex-rgba@1.0.3': {} @@ -15895,8 +15881,6 @@ snapshots: get-package-type@0.1.0: {} - get-params@0.1.2: {} - get-port@7.1.0: {} get-proto@1.0.1: