Last change
on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.9 KB
|
Rev | Line | |
---|
[6a3a178] | 1 | var resolveKeyword = require('css-tree').keyword;
|
---|
| 2 | var { hasNoChildren } = require('./utils');
|
---|
| 3 |
|
---|
| 4 | module.exports = 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 | return true;
|
---|
| 50 | }, this);
|
---|
| 51 |
|
---|
| 52 | break;
|
---|
| 53 |
|
---|
| 54 | default:
|
---|
| 55 | var name = resolveKeyword(node.name).basename;
|
---|
| 56 | if (name === 'keyframes' ||
|
---|
| 57 | name === 'media' ||
|
---|
| 58 | name === 'supports') {
|
---|
| 59 |
|
---|
| 60 | // drop at-rule with no prelude
|
---|
| 61 | if (hasNoChildren(node.prelude) || hasNoChildren(node.block)) {
|
---|
| 62 | list.remove(item);
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.