Blame view

node_modules/csso/lib/compressor/clean/Atrule.js 1.5 KB
aaac7fed   liuqimichale   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
  module.exports = function cleanAtrule(node, item, list) {
      if (node.block) {
          // otherwise removed at-rule don't prevent @import for removal
          this.root.firstAtrulesAllowed = false;
  
          if (node.block.type === 'Block' && node.block.declarations.isEmpty()) {
              list.remove(item);
              return;
          }
  
          if (node.block.type === 'StyleSheet' && node.block.rules.isEmpty()) {
              list.remove(item);
              return;
          }
      }
  
      switch (node.name) {
          case 'charset':
              if (node.expression.sequence.isEmpty()) {
                  list.remove(item);
                  return;
              }
  
              // if there is any rule before @charset -> remove it
              if (item.prev) {
                  list.remove(item);
                  return;
              }
  
              break;
  
          case 'import':
              if (!this.root.firstAtrulesAllowed) {
                  list.remove(item);
                  return;
              }
  
              // if there are some rules that not an @import or @charset before @import
              // remove it
              list.prevUntil(item.prev, function(rule) {
                  if (rule.type === 'Atrule') {
                      if (rule.name === 'import' || rule.name === 'charset') {
                          return;
                      }
                  }
  
                  this.root.firstAtrulesAllowed = false;
                  list.remove(item);
                  return true;
              }, this);
  
              break;
      }
  };