You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.1 KiB
47 lines
1.1 KiB
2 years ago
|
'use strict';
|
||
|
|
||
|
const cssTree = require('css-tree');
|
||
|
|
||
|
function processRule(node, item, list) {
|
||
|
const selectors = node.prelude.children;
|
||
|
|
||
|
// generate new rule sets:
|
||
|
// .a, .b { color: red; }
|
||
|
// ->
|
||
|
// .a { color: red; }
|
||
|
// .b { color: red; }
|
||
|
|
||
|
// while there are more than 1 simple selector split for rulesets
|
||
|
while (selectors.head !== selectors.tail) {
|
||
|
const newSelectors = new cssTree.List();
|
||
|
|
||
|
newSelectors.insert(selectors.remove(selectors.head));
|
||
|
|
||
|
list.insert(list.createItem({
|
||
|
type: 'Rule',
|
||
|
loc: node.loc,
|
||
|
prelude: {
|
||
|
type: 'SelectorList',
|
||
|
loc: node.prelude.loc,
|
||
|
children: newSelectors
|
||
|
},
|
||
|
block: {
|
||
|
type: 'Block',
|
||
|
loc: node.block.loc,
|
||
|
children: node.block.children.copy()
|
||
|
},
|
||
|
pseudoSignature: node.pseudoSignature
|
||
|
}), item);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function disjoinRule(ast) {
|
||
|
cssTree.walk(ast, {
|
||
|
visit: 'Rule',
|
||
|
reverse: true,
|
||
|
enter: processRule
|
||
|
});
|
||
|
}
|
||
|
|
||
|
module.exports = disjoinRule;
|