Skip to content

Instantly share code, notes, and snippets.

@lahmatiy
Created April 11, 2018 16:07
Show Gist options
  • Save lahmatiy/d3f8a76a2a761eecf3af010dc6e53a18 to your computer and use it in GitHub Desktop.
Save lahmatiy/d3f8a76a2a761eecf3af010dc6e53a18 to your computer and use it in GitHub Desktop.
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