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.

30 lines
661 B

4 years ago
  1. var Token = require('../../tokenizer/token');
  2. var serializeAll = require('../../writer/one-time').all;
  3. var serializeRules = require('../../writer/one-time').rules;
  4. function removeDuplicateMediaQueries(tokens) {
  5. var candidates = {};
  6. var candidate;
  7. var token;
  8. var key;
  9. var i, l;
  10. for (i = 0, l = tokens.length; i < l; i++) {
  11. token = tokens[i];
  12. if (token[0] != Token.NESTED_BLOCK) {
  13. continue;
  14. }
  15. key = serializeRules(token[1]) + '%' + serializeAll(token[2]);
  16. candidate = candidates[key];
  17. if (candidate) {
  18. candidate[2] = [];
  19. }
  20. candidates[key] = token;
  21. }
  22. }
  23. module.exports = removeDuplicateMediaQueries;