Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// filter for mediaqueries to be used or without any mediaquery
var selectorsMq = cssTools.filterByMqs(selectors, opts.useMqs);
// filter for pseudo elements to be used
var selectorsPseudo = cssTools.filterByPseudos(selectorsMq, opts.usePseudos);
// remove PseudoClass from its SimpleSelector for proper matching
cssTools.cleanPseudos(selectorsPseudo);
// stable sort selectors
var sortedSelectors = cssTools.sortSelectors(selectorsPseudo).reverse();
// apply <style> styles to matched elements
for (var selector of sortedSelectors) {
var selectorStr = csstree.translate(selector.item.data),
selectedEls = null;
try {
selectedEls = document.querySelectorAll(selectorStr);
} catch (selectError) {
if (selectError.constructor === SyntaxError) {
console.warn(
'Warning: Syntax error when trying to select \n\n' +
selectorStr +
'\n\n, skipped. Error details: ' +
selectError,
);
continue;
}
throw selectError;
}</style>
Object.keys(cleaned).forEach(url => {
// console.log('For URL', url);
const obj = cleaned[url]
const cleanedAst = csstree.fromPlainObject(obj)
const cleanedCSS = csstree.translate(cleanedAst)
console.log(cleanedCSS)
})
rule.block.children.each(declaration => {
if (ignoreDeclarations && ignoreDeclarations.indexOf(declaration.property.toLowerCase()) >= 0) {
return // skip because it is ignored
}
// Append to a list of locations
const key = cssTree.translate(declaration)
let locs = cssDeclarations[key]
locs = locs || []
locs.push(declaration.loc)
cssDeclarations[key] = locs
})
return cssTree.translate(selector)
if (style.cssAst.children.isEmpty()) {
// clean up now emtpy
const converted = rule.prelude.children.map((selector) => {
rule.block.children.each(declaration => {
if (ignoreDeclarations && ignoreDeclarations.indexOf(declaration.property.toLowerCase()) >= 0) {
return // skip because it is ignored
}
// Append to a list of locations
const key = cssTree.translate(declaration)
let locs = cssDeclarations[key]
locs = locs || []
locs.push(declaration.loc)
cssDeclarations[key] = locs
})
return cssTree.translate(selector)
})
cssRules.push(converted)
export default function normaliseCssAst (css) {
return parseCssAst(
csstree.translate(
parseCssAst(css)
)
)
}
return selectors.filter(function(selector) {
var pseudoSelectorsStr = csstree.translate({
type: 'Selector',
children: new List().fromArray(
selector.pseudos.map(function(pseudo) {
return pseudo.item.data;
}),
),
});
return ~usePseudos.indexOf(pseudoSelectorsStr);
});
}
export function csstreeToStyleDeclaration(declaration) {
var propertyName = declaration.property,
propertyValue = csstree.translate(declaration.value),
propertyPriority = declaration.important ? 'important' : '';
return {
name: propertyName,
value: propertyValue,
priority: propertyPriority,
};
}
return selectors.filter(function(selector) {
if (selector.atrule === null) {
return ~useMqs.indexOf('');
}
var mqName = selector.atrule.name;
var mqStr = mqName;
if (selector.atrule.expression.type === 'MediaQueryList') {
var mqExpr = csstree.translate(selector.atrule.expression);
mqStr = [mqName, mqExpr].join(' ');
}
return ~useMqs.indexOf(mqStr);
});
}
function benchCSSTree () {
return csstree.translate(csstree.parse(test));
}