Skip to content

Commit 48bb43a

Browse files
committed
add open() and close() brace helpers
1 parent d6864f1 commit 48bb43a

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

index.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ module.exports = function(css){
1515
return { stylesheet: { rules: rules() }};
1616
}
1717

18+
/**
19+
* Opening brace.
20+
*/
21+
22+
function open() {
23+
return match(/^{\s*/);
24+
}
25+
26+
/**
27+
* Closing brace.
28+
*/
29+
30+
function close() {
31+
return match(/^}\s*/);
32+
}
33+
1834
/**
1935
* Parse ruleset.
2036
*/
@@ -143,7 +159,7 @@ module.exports = function(css){
143159
var name = m[1];
144160

145161
// {
146-
if (!match(/^{\s*/)) return;
162+
if (!open()) return;
147163
comments();
148164

149165
var frame;
@@ -153,8 +169,7 @@ module.exports = function(css){
153169
comments();
154170
}
155171

156-
// }
157-
if (!match(/^}\s*/)) return;
172+
if (!close()) return;
158173

159174
return {
160175
name: name,
@@ -201,8 +216,7 @@ module.exports = function(css){
201216
function declarations() {
202217
var decls = [];
203218

204-
// {
205-
if (!match(/^{\s*/)) return;
219+
if (!open()) return;
206220
comments();
207221

208222
// declarations
@@ -212,8 +226,7 @@ module.exports = function(css){
212226
comments();
213227
}
214228

215-
// }
216-
if (!match(/^}\s*/)) return;
229+
if (!close()) return;
217230
return decls;
218231
}
219232

0 commit comments

Comments
 (0)