Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
css.eachRule(function(rule) {
if(rule.parent.type === "atrule" && /keyframes$/.test(rule.parent.name)) {
// ignore keyframe rules
return;
}
var selector = Tokenizer.parse(rule.selector);
var context = {
options: options,
global: globalMode,
hasPureGlobals: false
};
var newSelector;
try {
newSelector = localizeNode(selector, context);
} catch(e) {
throw rule.error(e.message);
}
if(pureMode && context.hasPureGlobals) {
throw rule.error("Selector '" + Tokenizer.stringify(selector) + "' is not pure " +
"(pure selectors must contain at least one local class or id)");
}
rule.nodes.forEach(function(decl) {
css.walkRules(function(rule) {
if(rule.parent.type === 'atrule' && /keyframes$/.test(rule.parent.name)) {
// ignore keyframe rules
return;
}
var selector = Tokenizer.parse(rule.selector);
var context = {
options: options,
global: globalMode,
hasPureGlobals: false
};
var newSelector;
try {
newSelector = localizeNode(selector, context);
} catch(e) {
throw rule.error(e.message);
}
if(pureMode && context.hasPureGlobals) {
throw rule.error('Selector "' + Tokenizer.stringify(selector) + '" is not pure ' +
'(pure selectors must contain at least one local class or id)');
}
// Less-syntax mixins parse as rules with no nodes
const getIdentifiers = (rule, result) => {
const selectors = Tokenizer.parse(rule.selector).nodes;
return selectors
.map(selector => {
const identifier = getSelectorIdentifier(selector);
if (identifier === null) {
result.warn(
`composition is only allowed in single class selector, not in '${Tokenizer.stringify(
selector
)}'`,
{ node: rule }
);
}
return identifier;
})
.filter(identifier => identifier !== null);
};
const localizeSelectors = (selectors, mode, getAlias) => {
const node = Tokenizer.parse(selectors);
return Tokenizer.stringify(
Object.assign({}, node, {
nodes: node.nodes.map(n => localizeNode(n, { mode, getAlias })),
})
);
};
const getValue = (messages, name) =>
export function parseSelector(selector: string): SelectorAstNode {
return tokenizer.parse(selector);
}
function generateClassesForSelector(selector) {
const { nodes } = first(parseSelector(selector).nodes)
const map = new Map()
let selectorPartNodes = []
/**
* 1. gather all the nodes until a pseudo element or dynamic pseudo selector
* 2. create a class for the selector part and add selector part/class to the map
*/
nodes.forEach((node, index) => {
/** we have a matched pseudo - drop the node, build the previous nodes to a string, and add it to the map entry */
if (node.type.startsWith('pseudo') && (pseudoElements.includes(node.name) || dynamicPseudoSelectors.includes(node.name))) {
const selectorPart = stringifySelectorNodes(selectorPartNodes)
map.set(toClass(selectorPart), selectorPart)
/**
* keep the previous last node on so that the selector continues to work
* .i.e. a:hover > b will become these selectors ['a', 'a > b']
const localizeSelectors = (selectors, mode, getAlias) => {
const node = Tokenizer.parse(selectors);
return Tokenizer.stringify(
Object.assign({}, node, {
nodes: node.nodes.map(n => localizeNode(n, { mode, getAlias }))
})
);
};
function queryableSelector(selector) {
const { nodes } = first(parseSelector(selector).nodes)
/** remove all non-static pseudo selectors/elements */
return stringifySelectorNodes(nodes.filter((node) => {
return !(node.type.startsWith('pseudo') && !staticPseudoSelectors.includes(node.name))
}))
}