Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const isState = Object.keys(usageMapping).some(namespace => {
return node.name.startsWith(
'' + namespace + pseudoStates.booleanStateDelimiter
);
});
if (!isState) {
// is not a state
if (!this.context.names[node.name]) {
this.generateName(node.name);
}
node.name = this.context.names[node.name];
}
}
});
return stringifySelector(ast);
}
public generateName(name: string) {
node.type = 'class';
node.name = state;
} else {
node.type = 'attribute';
node.content = state;
}
}
} else if (
node.type === 'pseudo-element' ||
node.type === 'element' ||
node.type === 'nested-pseudo-class'
) {
throw new Error(`selector with ${node.type} is not supported yet.`);
}
});
return stringifySelector(ast);
}
ast.walkRules(rule => {
const selectorAst = parseSelector(rule.selector);
const overrideSelectors = selectorAst.nodes.reduce((selectors, selector) => {
if (hasStates(selector, context)) {
selectors.push(transformStates(cloneDeep(selector), context));
}
return selectors;
}, [] as SelectorAstNode[]);
if (overrideSelectors.length) {
selectorAst.nodes.push(...overrideSelectors);
rule.selector = stringifySelector(selectorAst);
}
});
}