2019-04-16 11:49:12 -04:00
|
|
|
function indentRecursive(node, indent = 0) {
|
|
|
|
|
node.each &&
|
|
|
|
|
node.each((child, i) => {
|
|
|
|
|
if (!child.raws.before || child.raws.before.includes('\n')) {
|
|
|
|
|
child.raws.before = `\n${node.type !== 'rule' && i > 0 ? '\n' : ''}${' '.repeat(indent)}`
|
|
|
|
|
}
|
|
|
|
|
child.raws.after = `\n${' '.repeat(indent)}`
|
|
|
|
|
indentRecursive(child, indent + 1)
|
|
|
|
|
})
|
2019-04-16 11:43:17 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function formatNodes(root) {
|
|
|
|
|
indentRecursive(root)
|
|
|
|
|
root.first.raws.before = ''
|
|
|
|
|
}
|