Skip to content

Commit 5e3f7a4

Browse files
committed
fix optional whitespace
1 parent aa64d57 commit 5e3f7a4

File tree

3 files changed

+61
-9
lines changed

3 files changed

+61
-9
lines changed

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,20 @@ module.exports = function(css){
8080

8181
function declaration() {
8282
// prop
83-
var prop = match(/^([-\w]+) */);
83+
var prop = match(/^([-\w]+)\s*/);
8484
if (!prop) return;
8585
prop = prop[0];
8686

8787
// :
88-
if (!match(/^:/)) return;
88+
if (!match(/^:\s*/)) return;
8989

9090
// val
91-
var val = match(/^([^};]+)/);
91+
var val = match(/^([^};]+)\s*/);
9292
if (!val) return;
9393
val = val[0].trim();
9494

9595
// ;
96-
match(/^;\s+/);
96+
match(/^;\s*/);
9797

9898
return { property: prop, value: val };
9999
}
@@ -110,7 +110,7 @@ module.exports = function(css){
110110
comments();
111111

112112
// {
113-
if (!match(/^{\s+/)) return;
113+
if (!match(/^{\s*/)) return;
114114
comments();
115115

116116
// declarations

test/cases/messed-up.css

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
body{foo:'bar'}
2-
this is really
3-
{ terrible:
4-
'css'}
1+
body { foo
2+
:
3+
'bar' }
4+
5+
body{foo:bar;bar:baz}
6+
body
7+
{
8+
foo
9+
:
10+
bar
11+
;
12+
bar
13+
:
14+
baz
15+
}

test/cases/messed-up.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"stylesheet": {
3+
"rules": [
4+
{
5+
"selector": "body",
6+
"declarations": [
7+
{
8+
"property": "foo\n ",
9+
"value": "'bar'"
10+
}
11+
]
12+
},
13+
{
14+
"selector": "body",
15+
"declarations": [
16+
{
17+
"property": "foo",
18+
"value": "bar"
19+
},
20+
{
21+
"property": "bar",
22+
"value": "baz"
23+
}
24+
]
25+
},
26+
{
27+
"selector": "body",
28+
"declarations": [
29+
{
30+
"property": "foo\n ",
31+
"value": "bar"
32+
},
33+
{
34+
"property": "bar\n ",
35+
"value": "baz"
36+
}
37+
]
38+
}
39+
]
40+
}
41+
}

0 commit comments

Comments
 (0)