Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function parseCSS(
css: string,
extractStatic: boolean,
filename: string
): {
staticCSSRules: Array,
styles: { [string]: any },
composesCount: number
} {
// todo - handle errors
let root
if (typeof css === 'object') {
root = objParse(css, { from: filename })
} else {
root = parse(css, { from: filename })
}
let vars = 0
let composes: number = 0
root.walkDecls((decl: Decl): void => {
if (decl.prop === 'composes') {
if (!/xxx(\d+)xxx/gm.exec(decl.value)) {
throw new Error('composes must be a interpolation')
}
if (decl.parent.nodes[0] !== decl) {
throw new Error('composes must be the first rule')
}
if (decl.parent.type !== 'root') {
throw new Error('composes cannot be on nested selectors')
function createResetRule(selectors, reset) {
const selector = selectors.map(s => s.trim()).join(',\n');
const resetRule = postcss.rule({
selector,
source,
raws: {between: ' '}
});
const root = jsToCss(reset);
root.each(node => node.source = resetRule.source);
resetRule.append(root);
return resetRule;
}