yaml-unist-parser
Version:
A YAML parser that produces output compatible with unist
19 lines (18 loc) • 973 B
JavaScript
//#region src/utils/define-parents.ts
function defineParents(node, parent = null) {
if ("children" in node) node.children.forEach((child) => defineParents(child, node));
if ("anchor" in node && node.anchor) defineParents(node.anchor, node);
if ("tag" in node && node.tag) defineParents(node.tag, node);
// istanbul ignore if -- @preserve
if ("leadingComments" in node) node.leadingComments.forEach((comment) => defineParents(comment, node));
if ("middleComments" in node) node.middleComments.forEach((comment) => defineParents(comment, node));
if ("indicatorComment" in node && node.indicatorComment) defineParents(node.indicatorComment, node);
if ("trailingComment" in node && node.trailingComment) defineParents(node.trailingComment, node);
if ("endComments" in node) node.endComments.forEach((comment) => defineParents(comment, node));
Object.defineProperty(node, "_parent", {
value: parent,
enumerable: false
});
}
//#endregion
export { defineParents };