comment.js 674 B

123456789101112131415161718192021222324252627282930313233343536
  1. const Range = require('./range')
  2. /**
  3. * @typedef {import("../types").CommentRawData} CommentRawData
  4. */
  5. class Comment {
  6. /**
  7. * @param {Range[]} ranges
  8. * @param {boolean} [resolved]
  9. */
  10. constructor(ranges, resolved = false) {
  11. this.ranges = ranges
  12. this.resolved = resolved
  13. }
  14. toRaw() {
  15. return {
  16. resolved: this.resolved,
  17. ranges: this.ranges.map(range => range.toRaw()),
  18. }
  19. }
  20. /**
  21. * @param {CommentRawData} rawComment
  22. * @returns {Comment}
  23. */
  24. static fromRaw(rawComment) {
  25. return new Comment(
  26. rawComment.ranges.map(range => Range.fromRaw(range)),
  27. rawComment.resolved
  28. )
  29. }
  30. }
  31. module.exports = Comment