Skip to content

Commit cc81645

Browse files
committed
Merge pull request reworkcss#39 from paulyoung/34-at-rule-above-comment
Comments above at-rules
2 parents e9f534c + 4238415 commit cc81645

File tree

11 files changed

+275
-68
lines changed

11 files changed

+275
-68
lines changed

index.js

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,12 @@ module.exports = function(css, options){
263263
var name = m[1];
264264

265265
if (!open()) return error("@keyframes missing '{'");
266-
comments();
267266

268267
var frame;
269-
var frames = [];
268+
var frames = comments();
270269
while (frame = keyframe()) {
271270
frames.push(frame);
272-
comments();
271+
frames = frames.concat(comments());
273272
}
274273

275274
if (!close()) return error("@keyframes missing '}'");
@@ -294,9 +293,8 @@ module.exports = function(css, options){
294293
var supports = m[1].trim();
295294

296295
if (!open()) return error("@supports missing '{'");
297-
comments();
298296

299-
var style = rules();
297+
var style = comments().concat(rules());
300298

301299
if (!close()) return error("@supports missing '}'");
302300

@@ -319,9 +317,8 @@ module.exports = function(css, options){
319317
var media = m[1].trim();
320318

321319
if (!open()) return error("@media missing '{'");
322-
comments();
323320

324-
var style = rules();
321+
var style = comments().concat(rules());
325322

326323
if (!close()) return error("@media missing '}'");
327324

@@ -342,16 +339,15 @@ module.exports = function(css, options){
342339
if (!m) return;
343340

344341
var sel = selector() || [];
345-
var decls = [];
346342

347343
if (!open()) return error("@page missing '{'");
348-
comments();
344+
var decls = comments();
349345

350346
// declarations
351347
var decl;
352348
while (decl = declaration()) {
353349
decls.push(decl);
354-
comments();
350+
decls = decls.concat(comments());
355351
}
356352

357353
if (!close()) return error("@page missing '}'");
@@ -376,9 +372,8 @@ module.exports = function(css, options){
376372
var doc = m[2].trim();
377373

378374
if (!open()) return error("@document missing '{'");
379-
comments();
380375

381-
var style = rules();
376+
var style = comments().concat(rules());
382377

383378
if (!close()) return error("@document missing '}'");
384379

test/cases/document.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@-moz-document url-prefix() {
2+
/* ui above */
23
.ui-select .ui-btn select {
4+
/* ui inside */
35
opacity:.0001
46
}
57
}

test/cases/document.json

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,63 @@
77
"document": "url-prefix()",
88
"vendor": "-moz-",
99
"rules": [
10+
{
11+
"type": "comment",
12+
"comment": " ui above ",
13+
"position": {
14+
"start": {
15+
"line": 2,
16+
"column": 3
17+
},
18+
"end": {
19+
"line": 2,
20+
"column": 17
21+
}
22+
}
23+
},
1024
{
1125
"type": "rule",
1226
"selectors": [
1327
".ui-select .ui-btn select"
1428
],
1529
"declarations": [
30+
{
31+
"type": "comment",
32+
"comment": " ui inside ",
33+
"position": {
34+
"start": {
35+
"line": 4,
36+
"column": 5
37+
},
38+
"end": {
39+
"line": 4,
40+
"column": 20
41+
}
42+
}
43+
},
1644
{
1745
"type": "declaration",
1846
"property": "opacity",
1947
"value": ".0001",
2048
"position": {
2149
"start": {
22-
"line": 3,
50+
"line": 5,
2351
"column": 5
2452
},
2553
"end": {
26-
"line": 4,
54+
"line": 6,
2755
"column": 3
2856
}
2957
}
3058
}
3159
],
3260
"position": {
3361
"start": {
34-
"line": 2,
62+
"line": 3,
3563
"column": 3
3664
},
3765
"end": {
38-
"line": 4,
66+
"line": 6,
3967
"column": 4
4068
}
4169
}
@@ -47,7 +75,7 @@
4775
"column": 1
4876
},
4977
"end": {
50-
"line": 5,
78+
"line": 7,
5179
"column": 2
5280
}
5381
}

test/cases/keyframes.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
@keyframes fade {
2+
/* from above */
23
from {
4+
/* from inside */
35
opacity: 0;
46
}
7+
8+
/* to above */
59
to {
10+
/* to inside */
611
opacity: 1;
712
}
813
}

test/cases/keyframes.json

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,68 +6,124 @@
66
"type": "keyframes",
77
"name": "fade",
88
"keyframes": [
9+
{
10+
"type": "comment",
11+
"comment": " from above ",
12+
"position": {
13+
"start": {
14+
"line": 2,
15+
"column": 3
16+
},
17+
"end": {
18+
"line": 2,
19+
"column": 19
20+
}
21+
}
22+
},
923
{
1024
"type": "keyframe",
1125
"values": [
1226
"from"
1327
],
1428
"declarations": [
29+
{
30+
"type": "comment",
31+
"comment": " from inside ",
32+
"position": {
33+
"start": {
34+
"line": 4,
35+
"column": 5
36+
},
37+
"end": {
38+
"line": 4,
39+
"column": 22
40+
}
41+
}
42+
},
1543
{
1644
"type": "declaration",
1745
"property": "opacity",
1846
"value": "0",
1947
"position": {
2048
"start": {
21-
"line": 3,
49+
"line": 5,
2250
"column": 5
2351
},
2452
"end": {
25-
"line": 3,
53+
"line": 5,
2654
"column": 15
2755
}
2856
}
2957
}
3058
],
3159
"position": {
3260
"start": {
33-
"line": 2,
61+
"line": 3,
3462
"column": 3
3563
},
3664
"end": {
37-
"line": 4,
65+
"line": 6,
3866
"column": 4
3967
}
4068
}
4169
},
70+
{
71+
"type": "comment",
72+
"comment": " to above ",
73+
"position": {
74+
"start": {
75+
"line": 8,
76+
"column": 3
77+
},
78+
"end": {
79+
"line": 8,
80+
"column": 17
81+
}
82+
}
83+
},
4284
{
4385
"type": "keyframe",
4486
"values": [
4587
"to"
4688
],
4789
"declarations": [
90+
{
91+
"type": "comment",
92+
"comment": " to inside ",
93+
"position": {
94+
"start": {
95+
"line": 10,
96+
"column": 5
97+
},
98+
"end": {
99+
"line": 10,
100+
"column": 20
101+
}
102+
}
103+
},
48104
{
49105
"type": "declaration",
50106
"property": "opacity",
51107
"value": "1",
52108
"position": {
53109
"start": {
54-
"line": 6,
110+
"line": 11,
55111
"column": 5
56112
},
57113
"end": {
58-
"line": 6,
114+
"line": 11,
59115
"column": 15
60116
}
61117
}
62118
}
63119
],
64120
"position": {
65121
"start": {
66-
"line": 5,
122+
"line": 9,
67123
"column": 3
68124
},
69125
"end": {
70-
"line": 7,
126+
"line": 12,
71127
"column": 4
72128
}
73129
}
@@ -79,7 +135,7 @@
79135
"column": 1
80136
},
81137
"end": {
82-
"line": 8,
138+
"line": 13,
83139
"column": 2
84140
}
85141
}

test/cases/media.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
@media screen, projection {
2+
/* html above */
23
html {
4+
/* html inside */
35
background: #fffef0;
46
color: #300;
57
}
8+
9+
/* body above */
610
body {
11+
/* body inside */
712
max-width: 35em;
813
margin: 0 auto;
914
}

0 commit comments

Comments
 (0)