Skip to content

Commit bb4e11a

Browse files
committed
add comments array and option
1 parent e4c33ae commit bb4e11a

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

index.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
module.exports = function(css, options){
33
options = options || {};
44

5+
/**
6+
* Root node.
7+
*/
8+
9+
var root = {
10+
type: 'stylesheet',
11+
stylesheet: {},
12+
comments: []
13+
};
14+
515
/**
616
* Positional.
717
*/
@@ -48,19 +58,6 @@ module.exports = function(css, options){
4858
return node;
4959
}
5060

51-
/**
52-
* Parse stylesheet.
53-
*/
54-
55-
function stylesheet() {
56-
return {
57-
type: 'stylesheet',
58-
stylesheet: {
59-
rules: rules()
60-
}
61-
};
62-
}
63-
6461
/**
6562
* Opening brace.
6663
*/
@@ -118,11 +115,13 @@ module.exports = function(css, options){
118115
* Parse comments;
119116
*/
120117

121-
function comments(rules) {
118+
function comments() {
122119
var c;
123-
rules = rules || [];
124-
while (c = comment()) rules.push(c);
125-
return rules;
120+
while (c = comment()) {
121+
if (options.comments) {
122+
root.comments.push(c);
123+
}
124+
}
126125
}
127126

128127
/**
@@ -197,13 +196,13 @@ module.exports = function(css, options){
197196
var decls = [];
198197

199198
if (!open()) return;
200-
comments(decls);
199+
comments();
201200

202201
// declarations
203202
var decl;
204203
while (decl = declaration()) {
205204
decls.push(decl);
206-
comments(decls);
205+
comments();
207206
}
208207

209208
if (!close()) return;
@@ -447,6 +446,8 @@ module.exports = function(css, options){
447446
});
448447
}
449448

450-
return stylesheet();
449+
root.stylesheet.rules = rules();
450+
451+
return root;
451452
};
452453

0 commit comments

Comments
 (0)