comments.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
  4. exports.addComment = addComment;
  5. exports.addComments = addComments;
  6. function shareCommentsWithSiblings() {
  7. if (typeof this.key === "string") return;
  8. var node = this.node;
  9. if (!node) return;
  10. var trailing = node.trailingComments;
  11. var leading = node.leadingComments;
  12. if (!trailing && !leading) return;
  13. var prev = this.getSibling(this.key - 1);
  14. var next = this.getSibling(this.key + 1);
  15. if (!prev.node) prev = next;
  16. if (!next.node) next = prev;
  17. prev.addComments("trailing", leading);
  18. next.addComments("leading", trailing);
  19. }
  20. function addComment(type, content, line) {
  21. this.addComments(type, [{
  22. type: line ? "CommentLine" : "CommentBlock",
  23. value: content
  24. }]);
  25. }
  26. function addComments(type, comments) {
  27. if (!comments) return;
  28. var node = this.node;
  29. if (!node) return;
  30. var key = type + "Comments";
  31. if (node[key]) {
  32. node[key] = node[key].concat(comments);
  33. } else {
  34. node[key] = comments;
  35. }
  36. }