b7e7b14d9e668c97313b0a93b9bb9e531cb3e980e5c27a740de897270e5a5731670cac190dd2ca8418ee30b650c56e1b3680785bc108437a0c72a823821f43 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var lexer = require('css-tree').lexer;
  2. var packNumber = require('./Number').pack;
  3. var blacklist = new Set([
  4. // see https://github.com/jakubpawlowicz/clean-css/issues/957
  5. 'width',
  6. 'min-width',
  7. 'max-width',
  8. 'height',
  9. 'min-height',
  10. 'max-height',
  11. // issue #410: Don’t remove units in flex-basis value for (-ms-)flex shorthand
  12. // issue #362: shouldn't remove unit in -ms-flex since it breaks flex in IE10/11
  13. // issue #200: shouldn't remove unit in flex since it breaks flex in IE10/11
  14. 'flex',
  15. '-ms-flex'
  16. ]);
  17. module.exports = function compressPercentage(node, item) {
  18. node.value = packNumber(node.value, item);
  19. if (node.value === '0' && this.declaration && !blacklist.has(this.declaration.property)) {
  20. // try to convert a number
  21. item.data = {
  22. type: 'Number',
  23. loc: node.loc,
  24. value: node.value
  25. };
  26. // that's ok only when new value matches on length
  27. if (!lexer.matchDeclaration(this.declaration).isType(item.data, 'length')) {
  28. // otherwise rollback changes
  29. item.data = node;
  30. }
  31. }
  32. };