Skip to content

Commit eabe5de

Browse files
committed
fix: separate JSONPath path and script caches
1 parent e98dfd9 commit eabe5de

11 files changed

Lines changed: 58 additions & 30 deletions

badges/tests-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

dist/index-browser-esm.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,9 @@ JSONPath.prototype = JSONPathClass.prototype;
24192419
/** @type {Record<string, unknown>} */
24202420
JSONPath.cache = {};
24212421

2422+
/** @type {Record<string, string[]>} */
2423+
JSONPath.pathCache = {};
2424+
24222425
/**
24232426
* @param {string[]} pathArr Array to convert
24242427
* @returns {string} The path string
@@ -2457,10 +2460,10 @@ JSONPath.toPointer = function (pointer) {
24572460
*/
24582461
JSONPath.toPathArray = function (expr) {
24592462
const {
2460-
cache
2463+
pathCache
24612464
} = JSONPath;
2462-
if (Object.hasOwn(cache, expr)) {
2463-
return /** @type {string[]} */cache[expr].concat();
2465+
if (Object.hasOwn(pathCache, expr)) {
2466+
return pathCache[expr].concat();
24642467
}
24652468
/** @type {string[]} */
24662469
const subx = [];
@@ -2499,8 +2502,8 @@ JSONPath.toPathArray = function (expr) {
24992502
const match = exp.match(/#(\d+)/u);
25002503
return !match || !match[1] ? exp : subx[Number(match[1])];
25012504
});
2502-
cache[expr] = exprList;
2503-
return /** @type {string[]} */cache[expr].concat();
2505+
pathCache[expr] = exprList;
2506+
return pathCache[expr].concat();
25042507
};
25052508

25062509
/**

dist/index-browser-esm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-browser-esm.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-browser-umd.cjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,9 @@
24252425
/** @type {Record<string, unknown>} */
24262426
JSONPath.cache = {};
24272427

2428+
/** @type {Record<string, string[]>} */
2429+
JSONPath.pathCache = {};
2430+
24282431
/**
24292432
* @param {string[]} pathArr Array to convert
24302433
* @returns {string} The path string
@@ -2463,10 +2466,10 @@
24632466
*/
24642467
JSONPath.toPathArray = function (expr) {
24652468
const {
2466-
cache
2469+
pathCache
24672470
} = JSONPath;
2468-
if (Object.hasOwn(cache, expr)) {
2469-
return /** @type {string[]} */cache[expr].concat();
2471+
if (Object.hasOwn(pathCache, expr)) {
2472+
return pathCache[expr].concat();
24702473
}
24712474
/** @type {string[]} */
24722475
const subx = [];
@@ -2505,8 +2508,8 @@
25052508
const match = exp.match(/#(\d+)/u);
25062509
return !match || !match[1] ? exp : subx[Number(match[1])];
25072510
});
2508-
cache[expr] = exprList;
2509-
return /** @type {string[]} */cache[expr].concat();
2511+
pathCache[expr] = exprList;
2512+
return pathCache[expr].concat();
25102513
};
25112514

25122515
/**

dist/index-browser-umd.min.cjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/index-browser-umd.min.cjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index-node-cjs.cjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,9 @@ JSONPath.prototype = JSONPathClass.prototype;
24232423
/** @type {Record<string, unknown>} */
24242424
JSONPath.cache = {};
24252425

2426+
/** @type {Record<string, string[]>} */
2427+
JSONPath.pathCache = {};
2428+
24262429
/**
24272430
* @param {string[]} pathArr Array to convert
24282431
* @returns {string} The path string
@@ -2461,10 +2464,10 @@ JSONPath.toPointer = function (pointer) {
24612464
*/
24622465
JSONPath.toPathArray = function (expr) {
24632466
const {
2464-
cache
2467+
pathCache
24652468
} = JSONPath;
2466-
if (Object.hasOwn(cache, expr)) {
2467-
return /** @type {string[]} */cache[expr].concat();
2469+
if (Object.hasOwn(pathCache, expr)) {
2470+
return pathCache[expr].concat();
24682471
}
24692472
/** @type {string[]} */
24702473
const subx = [];
@@ -2503,8 +2506,8 @@ JSONPath.toPathArray = function (expr) {
25032506
const match = exp.match(/#(\d+)/u);
25042507
return !match || !match[1] ? exp : subx[Number(match[1])];
25052508
});
2506-
cache[expr] = exprList;
2507-
return /** @type {string[]} */cache[expr].concat();
2509+
pathCache[expr] = exprList;
2510+
return pathCache[expr].concat();
25082511
};
25092512

25102513
/**

dist/index-node-esm.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,6 +2421,9 @@ JSONPath.prototype = JSONPathClass.prototype;
24212421
/** @type {Record<string, unknown>} */
24222422
JSONPath.cache = {};
24232423

2424+
/** @type {Record<string, string[]>} */
2425+
JSONPath.pathCache = {};
2426+
24242427
/**
24252428
* @param {string[]} pathArr Array to convert
24262429
* @returns {string} The path string
@@ -2459,10 +2462,10 @@ JSONPath.toPointer = function (pointer) {
24592462
*/
24602463
JSONPath.toPathArray = function (expr) {
24612464
const {
2462-
cache
2465+
pathCache
24632466
} = JSONPath;
2464-
if (Object.hasOwn(cache, expr)) {
2465-
return /** @type {string[]} */cache[expr].concat();
2467+
if (Object.hasOwn(pathCache, expr)) {
2468+
return pathCache[expr].concat();
24662469
}
24672470
/** @type {string[]} */
24682471
const subx = [];
@@ -2501,8 +2504,8 @@ JSONPath.toPathArray = function (expr) {
25012504
const match = exp.match(/#(\d+)/u);
25022505
return !match || !match[1] ? exp : subx[Number(match[1])];
25032506
});
2504-
cache[expr] = exprList;
2505-
return /** @type {string[]} */cache[expr].concat();
2507+
pathCache[expr] = exprList;
2508+
return pathCache[expr].concat();
25062509
};
25072510

25082511
/**

src/jsonpath.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,9 @@ JSONPath.prototype = JSONPathClass.prototype;
11051105
/** @type {Record<string, unknown>} */
11061106
JSONPath.cache = {};
11071107

1108+
/** @type {Record<string, string[]>} */
1109+
JSONPath.pathCache = {};
1110+
11081111
/**
11091112
* @param {string[]} pathArr Array to convert
11101113
* @returns {string} The path string
@@ -1142,9 +1145,9 @@ JSONPath.toPointer = function (pointer) {
11421145
* @returns {string[]}
11431146
*/
11441147
JSONPath.toPathArray = function (expr) {
1145-
const {cache} = JSONPath;
1146-
if (Object.hasOwn(cache, expr)) {
1147-
return /** @type {string[]} */ (cache[expr]).concat();
1148+
const {pathCache} = JSONPath;
1149+
if (Object.hasOwn(pathCache, expr)) {
1150+
return pathCache[expr].concat();
11481151
}
11491152
/** @type {string[]} */
11501153
const subx = [];
@@ -1192,8 +1195,8 @@ JSONPath.toPathArray = function (expr) {
11921195
const match = exp.match(/#(\d+)/u);
11931196
return !match || !match[1] ? exp : subx[Number(match[1])];
11941197
});
1195-
cache[expr] = exprList;
1196-
return /** @type {string[]} */ (cache[expr]).concat();
1198+
pathCache[expr] = exprList;
1199+
return pathCache[expr].concat();
11971200
};
11981201

11991202
export {JSONPath, JSONPathClass};

0 commit comments

Comments
 (0)