Skip to content

Commit

Permalink
Fix getPropertyNodeFromPath conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed May 8, 2022
1 parent 9a9f1a4 commit d10adcf
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion server/src/jsonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,23 @@ export function getPropertyNodeFromPath(root: ASTNode, path: string): ASTNode |
while (segments.length) {
const segment = segments[0];
segments = segments?.slice(1);
const isLast = !segments.length;
if (currentNode.type == "object") {
const property = currentNode.properties.find((p) => p.keyNode.value == segment);
if (property && !segments.length) return property;
if (property && isLast) return property;
if (!property?.valueNode) return null;
if (property.valueNode.type == "object") {
currentNode = property.valueNode;
} else if (property.valueNode.type == "array") {
currentNode = property.valueNode;
} else {
return null;
}
} else if (currentNode.type == "array") {
const index = Number(segment);
const itemAtIndex = currentNode.items.at(index);
if (itemAtIndex) {
currentNode = itemAtIndex;
} else {
return null;
}
Expand Down

0 comments on commit d10adcf

Please sign in to comment.