diff options
| author | ruki <waruqi@gmail.com> | 2018-11-08 00:38:48 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2018-11-07 21:53:09 +0800 |
| commit | 26105034da4fcce7ac883c899d781f016559310d (patch) | |
| tree | c459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/csso/lib/compressor/clean/Atrule.js | |
| parent | 2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff) | |
| download | xmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip | |
switch to vuepress
Diffstat (limited to 'node_modules/csso/lib/compressor/clean/Atrule.js')
| -rw-r--r-- | node_modules/csso/lib/compressor/clean/Atrule.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/node_modules/csso/lib/compressor/clean/Atrule.js b/node_modules/csso/lib/compressor/clean/Atrule.js new file mode 100644 index 00000000..d27db04b --- /dev/null +++ b/node_modules/csso/lib/compressor/clean/Atrule.js @@ -0,0 +1,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; + } +}; |
