···
function traverse(node, key, parent) {
19
+
let hasEdited = false;
result = callback(node, key, parent, false);
} else if (result && typeof result.kind === 'string') {
31
+
const copy = { ...node };
31
-
let hasEdited = false;
for (const nodeKey in node) {
33
-
const value = node[nodeKey];
34
+
let value = node[nodeKey];
if (Array.isArray(value)) {
38
-
newValue = value.slice();
37
+
value = 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) {
45
-
newValue[index] = result;
44
+
value[index] = result;
···
} else if (value != null && typeof value.kind === 'string') {
result = traverse(value, nodeKey, node);
if (result !== undefined) {
60
-
copy[nodeKey] = hasEdited ? newValue : value;
59
+
if (hasEdited) copy[nodeKey] = value;
if (hasEdited) node = copy;
66
-
return callback(node, key, parent, true);
65
+
result = callback(node, key, parent, true);
66
+
return hasEdited && result === undefined ? node : result;