You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
992 B

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _postcss = require('postcss');
  6. var _postcss2 = _interopRequireDefault(_postcss);
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. const plugin = 'postcss-discard-empty';
  9. function discardAndReport(css, result) {
  10. function discardEmpty(node) {
  11. const { type, nodes: sub, params } = node;
  12. if (sub) {
  13. node.each(discardEmpty);
  14. }
  15. if (type === 'decl' && !node.value || type === 'rule' && !node.selector || sub && !sub.length || type === 'atrule' && (!sub && !params || !params && !sub.length)) {
  16. node.remove();
  17. result.messages.push({
  18. type: 'removal',
  19. plugin,
  20. node
  21. });
  22. }
  23. }
  24. css.each(discardEmpty);
  25. }
  26. exports.default = _postcss2.default.plugin(plugin, () => discardAndReport);
  27. module.exports = exports['default'];