comments.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.addComment = addComment;
  6. exports.addComments = addComments;
  7. exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
  8. var _t = require("@babel/types");
  9. const {
  10. addComment: _addComment,
  11. addComments: _addComments
  12. } = _t;
  13. function shareCommentsWithSiblings() {
  14. if (typeof this.key === "string") return;
  15. const node = this.node;
  16. if (!node) return;
  17. const trailing = node.trailingComments;
  18. const leading = node.leadingComments;
  19. if (!trailing && !leading) return;
  20. const prev = this.getSibling(this.key - 1);
  21. const next = this.getSibling(this.key + 1);
  22. const hasPrev = Boolean(prev.node);
  23. const hasNext = Boolean(next.node);
  24. if (hasPrev && !hasNext) {
  25. prev.addComments("trailing", trailing);
  26. } else if (hasNext && !hasPrev) {
  27. next.addComments("leading", leading);
  28. }
  29. }
  30. function addComment(type, content, line) {
  31. _addComment(this.node, type, content, line);
  32. }
  33. function addComments(type, comments) {
  34. _addComments(this.node, type, comments);
  35. }
  36. //# sourceMappingURL=comments.js.map