push
github
370 of 483 branches covered (76.6%)
2268 of 3240 relevant lines covered (70.0%)
16.68 hits per line
1 |
import { List } from 'css-tree'; |
|
2 |
|
1✔ |
3 |
export default function compressBackground(node) { |
1✔ |
4 |
function flush() { |
× |
5 |
if (!buffer.length) {
|
× |
6 |
buffer.unshift( |
× |
7 |
{ |
× |
8 |
type: 'Number', |
× |
9 |
loc: null, |
× |
10 |
value: '0' |
× |
11 |
}, |
× |
12 |
{ |
× |
13 |
type: 'Number', |
× |
14 |
loc: null, |
× |
15 |
value: '0' |
× |
16 |
} |
× |
17 |
); |
× |
18 |
} |
× |
19 |
|
× |
20 |
newValue.push.apply(newValue, buffer); |
× |
21 |
|
× |
22 |
buffer = []; |
× |
23 |
} |
× |
24 |
|
× |
25 |
let newValue = []; |
× |
26 |
let buffer = []; |
× |
27 |
|
× |
28 |
node.children.forEach((node) => { |
× |
29 |
if (node.type === 'Operator' && node.value === ',') { |
× |
30 |
flush(); |
× |
31 |
newValue.push(node); |
× |
32 |
return;
|
× |
33 |
} |
× |
34 |
|
× |
35 |
// remove defaults
|
× |
36 |
if (node.type === 'Identifier') { |
× |
37 |
if (node.name === 'transparent' || |
× |
38 |
node.name === 'none' ||
|
× |
39 |
node.name === 'repeat' ||
|
× |
40 |
node.name === 'scroll') {
|
× |
41 |
return;
|
× |
42 |
} |
× |
43 |
} |
× |
44 |
|
× |
45 |
buffer.push(node); |
× |
46 |
}); |
× |
47 |
|
× |
48 |
flush(); |
× |
49 |
node.children = new List().fromArray(newValue);
|
× |
50 |
}; |
1✔ |