remove-fake-nodes.js 659 B

1234567891011121314151617181920
  1. "use strict";
  2. exports.__esModule = true;
  3. // eemeli/yaml uses fake `plain`s to store comments https://github.com/eemeli/yaml/commit/c04ab2c2
  4. function removeFakeNodes(node) {
  5. if ("children" in node) {
  6. if (node.children.length === 1) {
  7. var child = node.children[0];
  8. if (child.type === "plain" &&
  9. child.tag === null &&
  10. child.anchor === null &&
  11. child.value === "") {
  12. node.children.splice(0, 1);
  13. return node;
  14. }
  15. }
  16. node.children.forEach(removeFakeNodes);
  17. }
  18. return node;
  19. }
  20. exports.removeFakeNodes = removeFakeNodes;