UNPKG

766 BJavaScriptView Raw
1// tooling
2import transformNode from './transform-node';
3
4// transform @content at-rules
5export default function transformContentAtrule(atrule, result, opts) {
6 const closest = getClosestMixin(atrule);
7
8 if (closest) {
9 // clone the mixin at-rule
10 const clone = closest.original.clone({
11 parent: atrule.parent,
12 variables: atrule.variables
13 });
14
15 // transform the clone
16 transformNode(clone, result, opts);
17
18 // insert the children of the clone before the @content at-rule
19 atrule.parent.insertBefore(atrule, clone.nodes);
20 }
21
22 // remove the @content at-rule
23 atrule.remove();
24}
25
26// return the closest @mixin at-rule
27const getClosestMixin = node => 'atrule' === node.type && 'mixin' === node.name
28 ? node
29: node.parent && getClosestMixin(node.parent);