Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Concat AST with CSSTree. Note that CSSTree lost an original formatting on parsing.
const csstree = require('css-tree');
const ast1 = csstree.parse('.a { color: red }', {
filename: './a.css',
positions: true
});
const ast2 = csstree.parse('.b { color: red }', {
filename: './b.css',
positions: true
});
const ast = {
type: 'StyleSheet',
children: new csstree.List()
.appendList(ast1.children)
.appendList(ast2.children)
};
csstree.generate(ast, { sourceMap: true });
// { css: '.a ...', map: SourceMapGenerator }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment