Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.analyzeString = function analyzeString (text, browserScope, lineShift = 0, fileName, callback, options = {"contrib":null}){
const report = [];
const ast = cssTree.parse(text,{positions:true});
cssTree.walk(ast,(node) => {
if(node.type === "Declaration"){
if(node.property in bcd.css.properties){
Object.keys(browserScope).map((browser)=>{
const supportBrowser = bcd.css.properties[node.property].__compat.support[browser];
let versionAddedProp;
if(Array.isArray(supportBrowser)){
// E.g. CSS property with prefixes
versionAddedProp = supportBrowser[0].version_added;
} else if(supportBrowser) {
versionAddedProp = supportBrowser.version_added;
}
if((versionAddedProp !== null) && ((!versionAddedProp) || (versionAddedProp !== true && semver.lt(semver.coerce(browserScope[browser]), semver.coerce(versionAddedProp)) ))){
report.push({
"featureName": "Property: " + node.property,
"browser":browser,
.then(result => {
const resultRules = csstree.toPlainObject(csstree.parse(result)).children
const originalRules = csstree.toPlainObject(csstree.parse(originalCss)).children
resultRules.should.have.length.lessThan(originalRules.length)
// not be empty
})
})
}
@media all {
body {
pointer-events: null;
}
}
`
const propertiesToRemove = [
'(.*)transition(.*)',
'cursor',
'pointer-events',
'(-webkit-)?tap-highlight-color',
'(.*)user-select'
]
const ast = csstree.parse(originalCss)
const beforeRemoval = countDeclarations(ast)
unwantedPropertiesRemover(ast, propertiesToRemove)
beforeRemoval.should.eql(8)
countDeclarations(ast).should.eql(0)
})
function styleParser (styleFile) {
const ast = csstree.parse(styleFile, {
parseValue: false,
onParseError ({formattedMessage}) {
logger.error(formattedMessage)
}
}),
selectorsArr = []
let selectorsSet = new Set()
csstree.walk(ast, {
visit: 'ClassSelector',
enter (node) {
selectorsSet.add(node.name)
}
})
for (const item of selectorsSet) {
(async () => {
const { body } = await got.get(url).catch(() => ({ body: '' }))
const parsed = csstree.parse(body)
if (parsed.type !== 'StyleSheet') {
return
}
await replaceImports(parsed, url)
list.replace(item, parsed.children)
})()
)
convert(styles: string) {
const font: Font = {
font_family: undefined,
font_size: undefined,
font_weight: undefined
};
const ast = csstree.parse(styles, {
context: 'declarationList'
});
ast.children.forEach(child => {
if (child.property === 'font-size') {
child.value.children.forEach(value => {
if (value.type === 'Dimension') {
font.font_size = parseInt(value.value);
}
});
}
if (child.property === 'font-family') {
child.value.children.forEach(value => {
if (value.type === 'Identifier') {
font.font_family = value.name;
}
function getParentSelectors(selector) {
if (!selector) return [];
const parentSelectors = [];
const selectorAst = csstree.parse(selector, { context: 'selector' });
let generatedCSS;
while (selectorAst.children.tail) {
selectorAst.children.prevUntil(
selectorAst.children.tail,
(node, item, list) => {
list.remove(item);
return node.type === 'Combinator' || node.type === 'WhiteSpace';
}
);
generatedCSS = csstree.generate(selectorAst);
if (generatedCSS) {
parentSelectors.push(generatedCSS);
}
}
return parentSelectors.reverse();
const stylesheetAstArray = styles.map((style) => {
const ast = parse(style, {
parseValue: false,
parseRulePrelude: false
});
return toPlainObject(ast)
});
function transformCss(style){
let ast=csstree.parse(style);
csstree.walk(ast,function(node){
if(node.type=="Comment"){//Change the comment because the limit of css-tree
node.type="Raw";
node.value="\n/*"+node.value+"*/\n";
}
if(node.type=="TypeSelector"){
if(node.name.startsWith("wx-"))node.name=node.name.slice(3);
else if(node.name=="body")node.name="page";
}
if(node.children){
const removeType=["webkit","moz","ms","o"];
let list={};
node.children.each((son,item)=>{
if(son.type=="Declaration"){
if(list[son.property]){
let a=item,b=list[son.property],x=son,y=b.data,ans=null;
function validate(css, filename) {
var errors = [];
var ast = csstree.parse(css, {
filename: filename,
positions: true,
onParseError: function(error) {
errors.push(error);
}
});
csstree.walk(ast, {
visit: 'Declaration',
enter: function(node) {
var match = syntax.matchDeclaration(node);
var error = match.error;
if (error) {
var message = error.rawMessage || error.message || error;