UNPKG

html-flavors

Version:
54 lines (48 loc) 1.55 kB
"use strict"; var postcss = require('postcss-scss'); function convertFromPostCss(root, onVisit) { var visit = (node, parent) => { let children = node.nodes && node.nodes.map(child => visit(child, node)); let name; var type = node.type; switch(node.type) { case 'rule': name = node.selector; break; case 'decl': children = [ {type: 'prop', name: node.prop}, {type: 'value', name: node.value + (node.important? '!important' : '') }, ]; break; case 'atrule': type = '@' + node.name; name = node.params; break; default: name = node.name; } var resultNode = { type: type, name: name, source: node.source, toString() {return '#' + this.id}, children: children, }; onVisit && onVisit(resultNode, node); return resultNode; }; return { type: 'file', name: '???check parseCss???', children: root.nodes.map(visit) }; }; module.exports = function loadCss (css, shouldNormalize, onVisit) { var root = postcss.parse(css); var ast = convertFromPostCss(root, onVisit); console.log('loadCss', ast); if (shouldNormalize) throw new Error('normalize is not implemented'); return ast; //return shouldNormalize? normalize(ast) : ast; };