1 |
|
2 | import transformDecl from './transform-decl';
|
3 | import transformAtrule from './transform-atrule';
|
4 | import transformEachAtrule from './transform-each-atrule';
|
5 | import transformIfAtrule from './transform-if-atrule';
|
6 | import transformImportAtrule from './transform-import-atrule';
|
7 | import transformIncludeAtrule from './transform-include-atrule';
|
8 | import transformForAtrule from './transform-for-atrule';
|
9 | import transformMixinAtrule from './transform-mixin-atrule';
|
10 | import transformRule from './transform-rule';
|
11 | import transformContentAtrule from './transform-content-atrule';
|
12 | import waterfall from './waterfall';
|
13 |
|
14 | export default function transformNode(node, opts) {
|
15 | return waterfall(
|
16 | getNodesArray(node),
|
17 | child => transformRuleOrDecl(child, opts).then(() => {
|
18 |
|
19 | if (child.parent) {
|
20 | return transformNode(child, opts);
|
21 | }
|
22 | })
|
23 | );
|
24 | }
|
25 |
|
26 | function transformRuleOrDecl(child, opts) {
|
27 | return Promise.resolve().then(() => {
|
28 | const type = child.type;
|
29 |
|
30 | if ('atrule' === type) {
|
31 | const name = child.name.toLowerCase();
|
32 |
|
33 | if ('content' === name) {
|
34 |
|
35 | return transformContentAtrule(child, opts);
|
36 | } else if ('each' === name) {
|
37 |
|
38 | return transformEachAtrule(child, opts);
|
39 | } else if ('if' === name) {
|
40 |
|
41 | return transformIfAtrule(child, opts);
|
42 | } else if ('import' === name) {
|
43 | return transformImportAtrule(child, opts);
|
44 | } else if ('include' === name) {
|
45 |
|
46 | return transformIncludeAtrule(child, opts);
|
47 | } else if ('for' === name) {
|
48 |
|
49 | return transformForAtrule(child, opts);
|
50 | } else if ('mixin' === name) {
|
51 |
|
52 | return transformMixinAtrule(child, opts);
|
53 | } else {
|
54 |
|
55 | return transformAtrule(child, opts);
|
56 | }
|
57 | } else if ('decl' === type) {
|
58 |
|
59 | return transformDecl(child, opts);
|
60 | } else if ('rule' === type) {
|
61 |
|
62 | return transformRule(child, opts);
|
63 | }
|
64 | })
|
65 | }
|
66 |
|
67 |
|
68 | const getNodesArray = node => Array.from(Object(node).nodes || []);
|