//#region src/v2/features/editor/helpers/json/json-ast.ts
/**
* Traverses the AST of a JSON document to find the node at the provided JsonPath.
* Returns undefined if the path does not exist in the AST.
*
* @param node - The root AST node to begin traversal from.
* @param path - The path to traverse within the AST, as an array of keys/indices.
* @returns The AST node at the specified path, or undefined if not found.
*/
var getJsonAstNodeAtPath = (node, path) => {
	let current = node;
	for (const segment of path) {
		if (!current) return;
		if (current.type === "object") {
			const key = String(segment);
			current = current.properties.find((p) => p.keyNode.value === key)?.valueNode;
			continue;
		}
		if (current.type === "array") {
			const index = typeof segment === "number" ? segment : Number.parseInt(String(segment), 10);
			if (!Number.isFinite(index) || index < 0 || index >= current.items.length) return;
			current = current.items[index];
			continue;
		}
		return;
	}
	return current;
};
//#endregion
export { getJsonAstNodeAtPath };

//# sourceMappingURL=json-ast.js.map