Mirror: The small sibling of the graphql package, slimmed down for client-side libraries.

Fix discrepancies in visitor implementation

Changed files
+10 -10
alias
language
+10 -10
alias/language/visitor.mjs
···
}
function traverse(node, key, parent) {
let result;
result = callback(node, key, parent, false);
if (result === false) {
return;
} else if (result && typeof result.kind === 'string') {
node = result;
}
ancestors.push(node);
-
const copy = {};
-
let hasEdited = false;
for (const nodeKey in node) {
-
const value = node[nodeKey];
-
-
let newValue;
path.push(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') {
path.push(index);
result = traverse(value[index], index, node);
path.pop();
if (result !== undefined) {
-
newValue[index] = result;
hasEdited = true;
}
}
···
} else if (value != null && typeof value.kind === 'string') {
result = traverse(value, nodeKey, node);
if (result !== undefined) {
-
newValue = result;
hasEdited = true;
}
}
path.pop();
-
copy[nodeKey] = hasEdited ? newValue : value;
}
ancestors.pop();
if (hasEdited) node = copy;
-
return callback(node, key, parent, true);
}
try {
···
}
function traverse(node, key, parent) {
+
let hasEdited = false;
let result;
result = callback(node, key, parent, false);
if (result === false) {
return;
} else if (result && typeof result.kind === 'string') {
+
hasEdited = true;
node = result;
}
ancestors.push(node);
+
const copy = { ...node };
for (const nodeKey in node) {
+
let value = node[nodeKey];
path.push(nodeKey);
if (Array.isArray(value)) {
+
value = value.slice();
for (let index = 0; index < value.length; index++) {
if (value[index] != null && typeof value[index].kind === 'string') {
path.push(index);
result = traverse(value[index], index, node);
path.pop();
if (result !== undefined) {
+
value[index] = result;
hasEdited = true;
}
}
···
} else if (value != null && typeof value.kind === 'string') {
result = traverse(value, nodeKey, node);
if (result !== undefined) {
+
value = result;
hasEdited = true;
}
}
path.pop();
+
if (hasEdited) copy[nodeKey] = value;
}
ancestors.pop();
if (hasEdited) node = copy;
+
result = callback(node, key, parent, true);
+
return hasEdited && result === undefined ? node : result;
}
try {