mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2026-01-13 12:06:14 +03:00
Merge 45658acb06 into 62cb6ddc25
This commit is contained in:
commit
67bceff89f
5
.changeset/puny-phones-like.md
Normal file
5
.changeset/puny-phones-like.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@redux-devtools/utils': patch
|
||||
---
|
||||
|
||||
Fix function parameters detection
|
||||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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<Action<string>> },
|
||||
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'),
|
||||
|
|
|
|||
|
|
@ -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'}
|
||||
|
|
@ -12930,8 +12918,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': {}
|
||||
|
|
@ -15896,8 +15882,6 @@ snapshots:
|
|||
|
||||
get-package-type@0.1.0: {}
|
||||
|
||||
get-params@0.1.2: {}
|
||||
|
||||
get-port@7.1.0: {}
|
||||
|
||||
get-proto@1.0.1:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user