Rename formatNodes to formatCSS

This commit is contained in:
Adam Wathan 2019-04-17 08:07:42 -04:00
parent de1884fdd9
commit 93184084c6
2 changed files with 2 additions and 2 deletions

15
src/lib/formatCSS.js Normal file
View file

@ -0,0 +1,15 @@
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)
})
}
export default function formatNodes(root) {
indentRecursive(root)
root.first.raws.before = ''
}