beforeBlockString.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports["default"] = _default;
  6. /**
  7. * Given a CSS statement, return the string before the block.
  8. * For rules, this is the selector list (and surrounding whitespace).
  9. * For at-rules, this is the name and params (and surrounding whitespace).
  10. *
  11. * If there is no block, return empty string.
  12. *
  13. * @param {Rule|AtRule} statement - postcss rule or at-rule node
  14. * @param {object} options
  15. * @param {boolean} [options.noRawBefore] - Leave out the `before` string
  16. * @return {string}
  17. */
  18. function _default(statement) {
  19. var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
  20. noRawBefore = _ref.noRawBefore;
  21. var result = "";
  22. if (statement.type !== "rule" && statement.type !== "atrule") {
  23. return result;
  24. }
  25. if (!noRawBefore) {
  26. result += statement.raws.before;
  27. }
  28. if (statement.type === "rule") {
  29. result += statement.selector;
  30. } else {
  31. result += "@".concat(statement.name).concat(statement.raws.afterName).concat(statement.params);
  32. }
  33. var between = statement.raws.between;
  34. if (between !== undefined) {
  35. result += between;
  36. }
  37. return result;
  38. }