You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.9 KiB

4 years ago
  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. var t = _interopRequireWildcard(require("@babel/types"));
  9. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
  10. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  11. function shareCommentsWithSiblings() {
  12. if (typeof this.key === "string") return;
  13. const node = this.node;
  14. if (!node) return;
  15. const trailing = node.trailingComments;
  16. const leading = node.leadingComments;
  17. if (!trailing && !leading) return;
  18. const prev = this.getSibling(this.key - 1);
  19. const next = this.getSibling(this.key + 1);
  20. const hasPrev = Boolean(prev.node);
  21. const hasNext = Boolean(next.node);
  22. if (hasPrev && hasNext) {} else if (hasPrev) {
  23. prev.addComments("trailing", trailing);
  24. } else if (hasNext) {
  25. next.addComments("leading", leading);
  26. }
  27. }
  28. function addComment(type, content, line) {
  29. t.addComment(this.node, type, content, line);
  30. }
  31. function addComments(type, comments) {
  32. t.addComments(this.node, type, comments);
  33. }