Skip to content

Commit 1deec47

Browse files
committed
fix reassignment json.js
1 parent 52f137a commit 1deec47

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/formatters/json.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,20 @@ const formatJson = (data, parentPath = '') => {
1414
condition,
1515
};
1616

17+
// Используем деструктуризацию и условное добавление свойств
1718
if (keyOld !== undefined || newValue !== undefined) {
18-
resultObj.oldValue = keyOld;
19-
resultObj.newValue = newValue;
20-
} else {
21-
resultObj.value = value;
19+
return {
20+
...resultObj,
21+
oldValue: keyOld,
22+
newValue,
23+
...(children && { children: iner(children, currentPath) }),
24+
};
2225
}
23-
24-
if (children) {
25-
resultObj.children = iner(children, currentPath);
26-
}
27-
28-
return resultObj;
26+
return {
27+
...resultObj,
28+
value,
29+
...(children && { children: iner(children, currentPath) }),
30+
};
2931
});
3032

3133
const result = iner(data, parentPath);

0 commit comments

Comments
 (0)