MCPcopy
hub / github.com/css/csso / cleanAtrule

Function cleanAtrule

lib/clean/Atrule.js:4–69  ·  view source on GitHub ↗
(node, item, list)

Source from the content-addressed store, hash-verified

2import { hasNoChildren } from './utils.js';
3
4export 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

Callers

nothing calls this directly

Calls 1

hasNoChildrenFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…