1 |
|
2 | import getArrayedString from './get-arrayed-string';
|
3 | import getReplacedString from './get-replaced-string';
|
4 | import setVariable from './set-variable';
|
5 | import transformNode from './transform-node';
|
6 |
|
7 |
|
8 | export default function transformEachAtrule(atrule, result, opts) {
|
9 |
|
10 | const params = atrule.params.split(matchInOperator);
|
11 |
|
12 |
|
13 | const args = (params[0] || '').trim().split(' ');
|
14 | const name = args[0].trim().slice(1);
|
15 | const itername = args.length > 1 ? args[1].trim().slice(1) : null;
|
16 | const array = getArrayedString(getReplacedString(params.slice(1).join(matchInOperator), atrule, result, opts), true);
|
17 | const end = array.length;
|
18 |
|
19 |
|
20 | for (let incrementor = 0; incrementor < end; ++incrementor) {
|
21 |
|
22 | setVariable(atrule, name, array[incrementor], opts);
|
23 |
|
24 |
|
25 | if (itername) {
|
26 | setVariable(atrule, itername, incrementor, opts);
|
27 | }
|
28 |
|
29 |
|
30 | const clone = atrule.clone({
|
31 | parent: atrule.parent,
|
32 | variables: atrule.variables
|
33 | });
|
34 |
|
35 |
|
36 | transformNode(clone, result, opts);
|
37 |
|
38 |
|
39 | atrule.parent.insertBefore(atrule, clone.nodes);
|
40 | }
|
41 |
|
42 |
|
43 | atrule.remove();
|
44 | }
|
45 |
|
46 | const matchInOperator = ' in ';
|