(node, item, list)
| 2 | import { hasNoChildren } from './utils.js'; |
| 3 | |
| 4 | export default function cleanAtrule(node, item, list) { |
| 5 | if (node.block) { |
| 6 | // otherwise removed at-rule don't prevent @import for removal |
| 7 | if (this.stylesheet !== null) { |
| 8 | this.stylesheet.firstAtrulesAllowed = false; |
| 9 | } |
| 10 | |
| 11 | if (hasNoChildren(node.block)) { |
| 12 | list.remove(item); |
| 13 | return; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | switch (node.name) { |
| 18 | case 'charset': |
| 19 | if (hasNoChildren(node.prelude)) { |
| 20 | list.remove(item); |
| 21 | return; |
| 22 | } |
| 23 | |
| 24 | // if there is any rule before @charset -> remove it |
| 25 | if (item.prev) { |
| 26 | list.remove(item); |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | break; |
| 31 | |
| 32 | case 'import': |
| 33 | if (this.stylesheet === null || !this.stylesheet.firstAtrulesAllowed) { |
| 34 | list.remove(item); |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | // if there are some rules that not an @import or @charset before @import |
| 39 | // remove it |
| 40 | list.prevUntil(item.prev, function(rule) { |
| 41 | if (rule.type === 'Atrule') { |
| 42 | if (rule.name === 'import' || rule.name === 'charset') { |
| 43 | return; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | this.root.firstAtrulesAllowed = false; |
| 48 | list.remove(item); |
| 49 | |
| 50 | return true; |
| 51 | }, this); |
| 52 | |
| 53 | break; |
| 54 | |
| 55 | default: { |
| 56 | const name = resolveKeyword(node.name).basename; |
| 57 | |
| 58 | if (name === 'keyframes' || |
| 59 | name === 'media' || |
| 60 | name === 'supports') { |
| 61 |
nothing calls this directly
no test coverage detected
searching dependent graphs…