Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
1.1 KB
|
Line | |
---|
1 | var List = require('css-tree').List;
|
---|
2 | var walk = require('css-tree').walk;
|
---|
3 |
|
---|
4 | function processRule(node, item, list) {
|
---|
5 | var selectors = node.prelude.children;
|
---|
6 |
|
---|
7 | // generate new rule sets:
|
---|
8 | // .a, .b { color: red; }
|
---|
9 | // ->
|
---|
10 | // .a { color: red; }
|
---|
11 | // .b { color: red; }
|
---|
12 |
|
---|
13 | // while there are more than 1 simple selector split for rulesets
|
---|
14 | while (selectors.head !== selectors.tail) {
|
---|
15 | var newSelectors = new List();
|
---|
16 | newSelectors.insert(selectors.remove(selectors.head));
|
---|
17 |
|
---|
18 | list.insert(list.createItem({
|
---|
19 | type: 'Rule',
|
---|
20 | loc: node.loc,
|
---|
21 | prelude: {
|
---|
22 | type: 'SelectorList',
|
---|
23 | loc: node.prelude.loc,
|
---|
24 | children: newSelectors
|
---|
25 | },
|
---|
26 | block: {
|
---|
27 | type: 'Block',
|
---|
28 | loc: node.block.loc,
|
---|
29 | children: node.block.children.copy()
|
---|
30 | },
|
---|
31 | pseudoSignature: node.pseudoSignature
|
---|
32 | }), item);
|
---|
33 | }
|
---|
34 | }
|
---|
35 |
|
---|
36 | module.exports = function disjoinRule(ast) {
|
---|
37 | walk(ast, {
|
---|
38 | visit: 'Rule',
|
---|
39 | reverse: true,
|
---|
40 | enter: processRule
|
---|
41 | });
|
---|
42 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.