isInlineComment.js 761 B

123456789101112131415161718192021
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = isInlineComment;
  6. /**
  7. * Check if a comment is inline one (i.e. on the same line as some non-comment
  8. * code). Only works with comments that are not ignored by PostCSS. To work
  9. * with those that are ignored use `findCommentInRaws`
  10. *
  11. * @param {Comment} comment - PostCSS comment node
  12. * @return {boolean} true, if the comment is an inline one
  13. */
  14. function isInlineComment(comment) {
  15. var nextNode = comment.next();
  16. var isBeforeSomething = !!nextNode && nextNode.type !== "comment" && comment.source.end.line === nextNode.source.start.line;
  17. var isAfterSomething = comment.raws.before.search(/\n/) === -1;
  18. return isAfterSomething || isBeforeSomething;
  19. }