Skip to content

Commit b7b6bca

Browse files
committed
Parser now correctly parses attributes with whitespace before colon
1 parent 88ef602 commit b7b6bca

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ module.exports = function(css, options){
181181
// prop
182182
var prop = match(/^(\*?[-\/\*\w]+)\s*/);
183183
if (!prop) return;
184-
prop = prop[0];
184+
prop = prop[0].replace(/^\s+|\s+$/, '');
185185

186186
// :
187187
if (!match(/^:\s*/)) return error("property missing ':'");

test/cases/colon-space.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a {
2+
margin : auto;
3+
padding : 0;
4+
}

test/cases/colon-space.json

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"type": "stylesheet",
3+
"stylesheet": {
4+
"rules": [
5+
{
6+
"type": "rule",
7+
"selectors": [
8+
"a"
9+
],
10+
"declarations": [
11+
{
12+
"type": "declaration",
13+
"property": "margin",
14+
"value": "auto",
15+
"position": {
16+
"start": {
17+
"line": 2,
18+
"column": 5
19+
},
20+
"end": {
21+
"line": 2,
22+
"column": 19
23+
}
24+
}
25+
},
26+
{
27+
"type": "declaration",
28+
"property": "padding",
29+
"value": "0",
30+
"position": {
31+
"start": {
32+
"line": 3,
33+
"column": 5
34+
},
35+
"end": {
36+
"line": 3,
37+
"column": 16
38+
}
39+
}
40+
}
41+
],
42+
"position": {
43+
"start": {
44+
"line": 1,
45+
"column": 1
46+
},
47+
"end": {
48+
"line": 4,
49+
"column": 2
50+
}
51+
}
52+
}
53+
]
54+
}
55+
}

test/cases/messed-up.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"declarations": [
1111
{
1212
"type": "declaration",
13-
"property": "foo\n ",
13+
"property": "foo",
1414
"value": "'bar'",
1515
"position": {
1616
"start": {
@@ -91,7 +91,7 @@
9191
"declarations": [
9292
{
9393
"type": "declaration",
94-
"property": "foo\n ",
94+
"property": "foo",
9595
"value": "bar",
9696
"position": {
9797
"start": {
@@ -106,7 +106,7 @@
106106
},
107107
{
108108
"type": "declaration",
109-
"property": "bar\n ",
109+
"property": "bar",
110110
"value": "baz",
111111
"position": {
112112
"start": {

0 commit comments

Comments
 (0)