UNPKG

686 BJavaScriptView Raw
1export default function cloneNodes(nodes, source = undefined, raws = undefined) {
2 return nodes.map((node) => {
3 let cloned = node.clone()
4
5 // We always want override the source map
6 // except when explicitly told not to
7 let shouldOverwriteSource = node.raws.tailwind?.preserveSource !== true || !cloned.source
8
9 if (source !== undefined && shouldOverwriteSource) {
10 cloned.source = source
11
12 if ('walk' in cloned) {
13 cloned.walk((child) => {
14 child.source = source
15 })
16 }
17 }
18
19 if (raws !== undefined) {
20 cloned.raws.tailwind = {
21 ...cloned.raws.tailwind,
22 ...raws,
23 }
24 }
25
26 return cloned
27 })
28}