declaration.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 _warnOnce = require('./warn-once');
  5. var _warnOnce2 = _interopRequireDefault(_warnOnce);
  6. var _node = require('./node');
  7. var _node2 = _interopRequireDefault(_node);
  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 a CSS declaration.
  14. *
  15. * @extends Node
  16. *
  17. * @example
  18. * const root = postcss.parse('a { color: black }');
  19. * const decl = root.first.first;
  20. * decl.type //=> 'decl'
  21. * decl.toString() //=> ' color: black'
  22. */
  23. var Declaration = function (_Node) {
  24. _inherits(Declaration, _Node);
  25. function Declaration(defaults) {
  26. _classCallCheck(this, Declaration);
  27. var _this = _possibleConstructorReturn(this, _Node.call(this, defaults));
  28. _this.type = 'decl';
  29. return _this;
  30. }
  31. _createClass(Declaration, [{
  32. key: '_value',
  33. get: function get() {
  34. (0, _warnOnce2.default)('Node#_value was deprecated. Use Node#raws.value');
  35. return this.raws.value;
  36. },
  37. set: function set(val) {
  38. (0, _warnOnce2.default)('Node#_value was deprecated. Use Node#raws.value');
  39. this.raws.value = val;
  40. }
  41. }, {
  42. key: '_important',
  43. get: function get() {
  44. (0, _warnOnce2.default)('Node#_important was deprecated. Use Node#raws.important');
  45. return this.raws.important;
  46. },
  47. set: function set(val) {
  48. (0, _warnOnce2.default)('Node#_important was deprecated. Use Node#raws.important');
  49. this.raws.important = val;
  50. }
  51. /**
  52. * @memberof Declaration#
  53. * @member {string} prop - the declaration’s property name
  54. *
  55. * @example
  56. * const root = postcss.parse('a { color: black }');
  57. * const decl = root.first.first;
  58. * decl.prop //=> 'color'
  59. */
  60. /**
  61. * @memberof Declaration#
  62. * @member {string} value - the declaration’s value
  63. *
  64. * @example
  65. * const root = postcss.parse('a { color: black }');
  66. * const decl = root.first.first;
  67. * decl.value //=> 'black'
  68. */
  69. /**
  70. * @memberof Declaration#
  71. * @member {boolean} important - `true` if the declaration
  72. * has an !important annotation.
  73. *
  74. * @example
  75. * const root = postcss.parse('a { color: black !important; color: red }');
  76. * root.first.first.important //=> true
  77. * root.first.last.important //=> undefined
  78. */
  79. /**
  80. * @memberof Declaration#
  81. * @member {object} raws - Information to generate byte-to-byte equal
  82. * node string as it was in the origin input.
  83. *
  84. * Every parser saves its own properties,
  85. * but the default CSS parser uses:
  86. *
  87. * * `before`: the space symbols before the node. It also stores `*`
  88. * and `_` symbols before the declaration (IE hack).
  89. * * `between`: the symbols between the property and value
  90. * for declarations.
  91. * * `important`: the content of the important statement,
  92. * if it is not just `!important`.
  93. *
  94. * PostCSS cleans declaration from comments and extra spaces,
  95. * but it stores origin content in raws properties.
  96. * As such, if you don’t change a declaration’s value,
  97. * PostCSS will use the raw value with comments.
  98. *
  99. * @example
  100. * const root = postcss.parse('a {\n color:black\n}')
  101. * root.first.first.raws //=> { before: '\n ', between: ':' }
  102. */
  103. }]);
  104. return Declaration;
  105. }(_node2.default);
  106. exports.default = Declaration;
  107. module.exports = exports['default'];
  108. //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImRlY2xhcmF0aW9uLmVzNiJdLCJuYW1lcyI6WyJEZWNsYXJhdGlvbiIsImRlZmF1bHRzIiwidHlwZSIsInJhd3MiLCJ2YWx1ZSIsInZhbCIsImltcG9ydGFudCJdLCJtYXBwaW5ncyI6Ijs7Ozs7O0FBQUE7Ozs7QUFDQTs7Ozs7Ozs7Ozs7O0FBRUE7Ozs7Ozs7Ozs7O0lBV01BLFc7OztBQUVGLHlCQUFZQyxRQUFaLEVBQXNCO0FBQUE7O0FBQUEscURBQ2xCLGlCQUFNQSxRQUFOLENBRGtCOztBQUVsQixjQUFLQyxJQUFMLEdBQVksTUFBWjtBQUZrQjtBQUdyQjs7Ozs0QkFFWTtBQUNULG9DQUFTLGlEQUFUO0FBQ0EsbUJBQU8sS0FBS0MsSUFBTCxDQUFVQyxLQUFqQjtBQUNILFM7MEJBRVVDLEcsRUFBSztBQUNaLG9DQUFTLGlEQUFUO0FBQ0EsaUJBQUtGLElBQUwsQ0FBVUMsS0FBVixHQUFrQkMsR0FBbEI7QUFDSDs7OzRCQUVnQjtBQUNiLG9DQUFTLHlEQUFUO0FBQ0EsbUJBQU8sS0FBS0YsSUFBTCxDQUFVRyxTQUFqQjtBQUNILFM7MEJBRWNELEcsRUFBSztBQUNoQixvQ0FBUyx5REFBVDtBQUNBLGlCQUFLRixJQUFMLENBQVVHLFNBQVYsR0FBc0JELEdBQXRCO0FBQ0g7O0FBRUQ7Ozs7Ozs7Ozs7QUFVQTs7Ozs7Ozs7OztBQVVBOzs7Ozs7Ozs7OztBQVdBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7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