function getAstForJsonPointer(ast, pointer) {
  let currentValue = ast;
  let currentProperty;
  pointer.forEach((token) => {
    if (!currentValue) {
      throw new Error("Invalid reference: " + pointer.join("/"));
    }
    if (currentValue.type === "Literal") {
      throw new Error("Invalid reference token: " + token);
    } else if (currentValue.type === "Array") {
      const maybeCurrent = currentValue.children[parseInt(token, 10)];
      if (!maybeCurrent) {
        throw new Error("Invalid reference token: " + token);
      }
      currentValue = maybeCurrent;
      currentProperty = void 0;
    } else if (currentValue.type === "Object") {
      const maybeProperty = currentValue.children.find((child) => child.key.value === token);
      if (!maybeProperty) {
        throw new Error("Invalid reference token: " + token);
      }
      currentValue = maybeProperty.value;
      currentProperty = maybeProperty;
    }
  });
  return { value: currentValue, property: currentProperty };
}
export {
  getAstForJsonPointer
};
//# sourceMappingURL=pointer-utils.js.map
