comments.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
  6. exports.addComment = addComment;
  7. exports.addComments = addComments;
  8. function t() {
  9. const data = _interopRequireWildcard(require("@babel/types"));
  10. t = function () {
  11. return data;
  12. };
  13. return data;
  14. }
  15. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  16. function shareCommentsWithSiblings() {
  17. if (typeof this.key === "string") return;
  18. const node = this.node;
  19. if (!node) return;
  20. const trailing = node.trailingComments;
  21. const leading = node.leadingComments;
  22. if (!trailing && !leading) return;
  23. const prev = this.getSibling(this.key - 1);
  24. const next = this.getSibling(this.key + 1);
  25. const hasPrev = Boolean(prev.node);
  26. const hasNext = Boolean(next.node);
  27. if (hasPrev && hasNext) {} else if (hasPrev) {
  28. prev.addComments("trailing", trailing);
  29. } else if (hasNext) {
  30. next.addComments("leading", leading);
  31. }
  32. }
  33. function addComment(type, content, line) {
  34. t().addComment(this.node, type, content, line);
  35. }
  36. function addComments(type, comments) {
  37. t().addComments(this.node, type, comments);
  38. }