1 |
|
2 | import manageUnresolved from './manage-unresolved';
|
3 | import transformNode from './transform-node';
|
4 |
|
5 |
|
6 | export default function transformContentAtrule(rule, opts) {
|
7 |
|
8 | if (opts.transform.includes('@content')) {
|
9 |
|
10 | const mixin = getClosestMixin(rule);
|
11 |
|
12 |
|
13 | if (mixin) {
|
14 |
|
15 | const clone = mixin.original.clone({
|
16 | parent: rule.parent,
|
17 | variables: rule.variables
|
18 | });
|
19 |
|
20 |
|
21 | transformNode(clone, opts);
|
22 |
|
23 |
|
24 | rule.parent.insertBefore(rule, clone.nodes);
|
25 |
|
26 | rule.remove();
|
27 | } else {
|
28 |
|
29 | manageUnresolved(rule, opts, '@content', 'Could not resolve the mixin for @content');
|
30 | }
|
31 | }
|
32 | }
|
33 |
|
34 |
|
35 | const getClosestMixin = node => 'atrule' === node.type && 'mixin' === node.name
|
36 | ? node
|
37 | : node.parent && getClosestMixin(node.parent);
|