Skip to content

Commit 364ef1f

Browse files
fix(non-blocking-json): fix parent passed to replacer
1 parent b20d4e5 commit 364ef1f

File tree

1 file changed

+6
-5
lines changed
  • packages/node_modules/non-blocking-json/src

1 file changed

+6
-5
lines changed

packages/node_modules/non-blocking-json/src/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,23 @@ const batch = (() => {
5454
value. It takes a "replacer" function which allows you to intercept
5555
the created result
5656
*/
57-
function getPaths(value, paths, replacer, currentPath = [], index = { current: 0 }) {
58-
const replacedValue = replacer ? replacer(currentPath, value) : value;
57+
function getPaths(value, parent, paths, replacer, currentPath = [], index = { current: 0 }) {
58+
const replacedValue = replacer ? replacer.call(parent, currentPath, value) : value;
59+
5960
if (typeof replacedValue === "function" || typeof replacedValue === "symbol" || replacedValue === undefined) {
6061
} else if (Array.isArray(replacedValue)) {
6162
paths[index.current++] = [currentPath.slice(), IS_ARRAY_START]
6263
for (let key in replacedValue) {
6364
currentPath.push(key);
64-
getPaths(replacedValue[key], paths, replacer ? replacer.bind(replacedValue) : replacer, currentPath, index);
65+
getPaths(replacedValue[key], replacedValue, paths, replacer, currentPath, index);
6566
currentPath.pop();
6667
}
6768
paths[index.current++] = [currentPath.slice(), IS_ARRAY_END]
6869
} else if (replacedValue !== null && typeof replacedValue === "object") {
6970
paths[index.current++] = [currentPath.slice(), IS_OBJECT_START]
7071
for (let key in replacedValue) {
7172
currentPath.push(key);
72-
getPaths(replacedValue[key], paths, replacer ? replacer.bind(replacedValue) : replacer, currentPath, index);
73+
getPaths(replacedValue[key], replacedValue, paths, replacer, currentPath, index);
7374
currentPath.pop();
7475
}
7576
paths[index.current++] = [currentPath.slice(), IS_OBJECT_END]
@@ -106,7 +107,7 @@ function getBatches(length: number) {
106107
*/
107108
export function stringify(value, replacer?) {
108109
return new Promise<string>(resolve => {
109-
const paths = getPaths(value, [], replacer ? replacer.bind(global || window) : replacer);
110+
const paths = getPaths(value, global || window, [], replacer);
110111
const batches = getBatches(paths.length)
111112
const structs = [];
112113
let prevKey = [];

0 commit comments

Comments
 (0)