at-rule.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  4. var _container = require('./container');
  5. var _container2 = _interopRequireDefault(_container);
  6. var _warnOnce = require('./warn-once');
  7. var _warnOnce2 = _interopRequireDefault(_warnOnce);
  8. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  9. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  10. function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  11. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  12. /**
  13. * Represents an at-rule.
  14. *
  15. * If it’s followed in the CSS by a {} block, this node will have
  16. * a nodes property representing its children.
  17. *
  18. * @extends Container
  19. *
  20. * @example
  21. * const root = postcss.parse('@charset "UTF-8"; @media print {}');
  22. *
  23. * const charset = root.first;
  24. * charset.type //=> 'atrule'
  25. * charset.nodes //=> undefined
  26. *
  27. * const media = root.last;
  28. * media.nodes //=> []
  29. */
  30. var AtRule = function (_Container) {
  31. _inherits(AtRule, _Container);
  32. function AtRule(defaults) {
  33. _classCallCheck(this, AtRule);
  34. var _this = _possibleConstructorReturn(this, _Container.call(this, defaults));
  35. _this.type = 'atrule';
  36. return _this;
  37. }
  38. AtRule.prototype.append = function append() {
  39. var _Container$prototype$;
  40. if (!this.nodes) this.nodes = [];
  41. for (var _len = arguments.length, children = Array(_len), _key = 0; _key < _len; _key++) {
  42. children[_key] = arguments[_key];
  43. }
  44. return (_Container$prototype$ = _Container.prototype.append).call.apply(_Container$prototype$, [this].concat(children));
  45. };
  46. AtRule.prototype.prepend = function prepend() {
  47. var _Container$prototype$2;
  48. if (!this.nodes) this.nodes = [];
  49. for (var _len2 = arguments.length, children = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  50. children[_key2] = arguments[_key2];
  51. }
  52. return (_Container$prototype$2 = _Container.prototype.prepend).call.apply(_Container$prototype$2, [this].concat(children));
  53. };
  54. _createClass(AtRule, [{
  55. key: 'afterName',
  56. get: function get() {
  57. (0, _warnOnce2.default)('AtRule#afterName was deprecated. Use AtRule#raws.afterName');
  58. return this.raws.afterName;
  59. },
  60. set: function set(val) {
  61. (0, _warnOnce2.default)('AtRule#afterName was deprecated. Use AtRule#raws.afterName');
  62. this.raws.afterName = val;
  63. }
  64. }, {
  65. key: '_params',
  66. get: function get() {
  67. (0, _warnOnce2.default)('AtRule#_params was deprecated. Use AtRule#raws.params');
  68. return this.raws.params;
  69. },
  70. set: function set(val) {
  71. (0, _warnOnce2.default)('AtRule#_params was deprecated. Use AtRule#raws.params');
  72. this.raws.params = val;
  73. }
  74. /**
  75. * @memberof AtRule#
  76. * @member {string} name - the at-rule’s name immediately follows the `@`
  77. *
  78. * @example
  79. * const root = postcss.parse('@media print {}');
  80. * media.name //=> 'media'
  81. * const media = root.first;
  82. */
  83. /**
  84. * @memberof AtRule#
  85. * @member {string} params - the at-rule’s parameters, the values
  86. * that follow the at-rule’s name but precede
  87. * any {} block
  88. *
  89. * @example
  90. * const root = postcss.parse('@media print, screen {}');
  91. * const media = root.first;
  92. * media.params //=> 'print, screen'
  93. */
  94. /**
  95. * @memberof AtRule#
  96. * @member {object} raws - Information to generate byte-to-byte equal
  97. * node string as it was in the origin input.
  98. *
  99. * Every parser saves its own properties,
  100. * but the default CSS parser uses:
  101. *
  102. * * `before`: the space symbols before the node. It also stores `*`
  103. * and `_` symbols before the declaration (IE hack).
  104. * * `after`: the space symbols after the last child of the node
  105. * to the end of the node.
  106. * * `between`: the symbols between the property and value
  107. * for declarations, selector and `{` for rules, or last parameter
  108. * and `{` for at-rules.
  109. * * `semicolon`: contains true if the last child has
  110. * an (optional) semicolon.
  111. * * `afterName`: the space between the at-rule name and its parameters.
  112. *
  113. * PostCSS cleans at-rule parameters from comments and extra spaces,
  114. * but it stores origin content in raws properties.
  115. * As such, if you don’t change a declaration’s value,
  116. * PostCSS will use the raw value with comments.
  117. *
  118. * @example
  119. * const root = postcss.parse(' @media\nprint {\n}')
  120. * root.first.first.raws //=> { before: ' ',
  121. * // between: ' ',
  122. * // afterName: '\n',
  123. * // after: '\n' }
  124. */
  125. }]);
  126. return AtRule;
  127. }(_container2.default);
  128. exports.default = AtRule;
  129. module.exports = exports['default'];
  130. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImF0LXJ1bGUuZXM2Il0sIm5hbWVzIjpbIkF0UnVsZSIsImRlZmF1bHRzIiwidHlwZSIsImFwcGVuZCIsIm5vZGVzIiwiY2hpbGRyZW4iLCJwcmVwZW5kIiwicmF3cyIsImFmdGVyTmFtZSIsInZhbCIsInBhcmFtcyJdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUE7Ozs7QUFDQTs7Ozs7Ozs7Ozs7O0FBRUE7Ozs7Ozs7Ozs7Ozs7Ozs7OztJQWtCTUEsTTs7O0FBRUYsb0JBQVlDLFFBQVosRUFBc0I7QUFB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