define-parents.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. exports.__esModule = true;
  3. function defineParents(node, parent) {
  4. if (parent === void 0) { parent = null; }
  5. if ("children" in node) {
  6. node.children.forEach(function (child) {
  7. return defineParents(child, node);
  8. });
  9. }
  10. if ("anchor" in node && node.anchor) {
  11. defineParents(node.anchor, node);
  12. }
  13. if ("tag" in node && node.tag) {
  14. defineParents(node.tag, node);
  15. }
  16. // istanbul ignore next
  17. if ("leadingComments" in node) {
  18. node.leadingComments.forEach(function (comment) { return defineParents(comment, node); });
  19. }
  20. if ("middleComments" in node) {
  21. node.middleComments.forEach(function (comment) { return defineParents(comment, node); });
  22. }
  23. if ("indicatorComment" in node && node.indicatorComment) {
  24. defineParents(node.indicatorComment, node);
  25. }
  26. if ("trailingComment" in node && node.trailingComment) {
  27. defineParents(node.trailingComment, node);
  28. }
  29. if ("endComments" in node) {
  30. node.endComments.forEach(function (comment) { return defineParents(comment, node); });
  31. }
  32. Object.defineProperty(node, "_parent", {
  33. value: parent,
  34. enumerable: false
  35. });
  36. }
  37. exports.defineParents = defineParents;