···
function traverse(node, key, parent) {
result = callback(node, key, parent, false);
} else if (result && typeof result.kind === 'string') {
for (const nodeKey in node) {
-
const value = node[nodeKey];
if (Array.isArray(value)) {
-
newValue = value.slice();
for (let index = 0; index < value.length; index++) {
if (value[index] != null && typeof value[index].kind === 'string') {
result = traverse(value[index], index, node);
if (result !== undefined) {
-
newValue[index] = result;
···
} else if (value != null && typeof value.kind === 'string') {
result = traverse(value, nodeKey, node);
if (result !== undefined) {
-
copy[nodeKey] = hasEdited ? newValue : value;
if (hasEdited) node = copy;
-
return callback(node, key, parent, true);
···
function traverse(node, key, parent) {
result = callback(node, key, parent, false);
} else if (result && typeof result.kind === 'string') {
+
const copy = { ...node };
for (const nodeKey in node) {
+
let value = node[nodeKey];
if (Array.isArray(value)) {
for (let index = 0; index < value.length; index++) {
if (value[index] != null && typeof value[index].kind === 'string') {
result = traverse(value[index], index, node);
if (result !== undefined) {
···
} else if (value != null && typeof value.kind === 'string') {
result = traverse(value, nodeKey, node);
if (result !== undefined) {
+
if (hasEdited) copy[nodeKey] = value;
if (hasEdited) node = copy;
+
result = callback(node, key, parent, true);
+
return hasEdited && result === undefined ? node : result;