Skip to content

Commit 7cef365

Browse files
committed
Fix @custom-media parsing
Previous test didn't check that the rule value was correctly terminated.
1 parent 6de72c0 commit 7cef365

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

History.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
HEAD
22
==================
33

4+
* add support for `@custom-media`
45
* allow commas inside selector functions
56
* allow empty property values
67
* changed default `options.position` value to `true`

index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = function(css, options){
7272
if (options.silent === true) {
7373
return false;
7474
}
75-
75+
7676
var err = new Error(msg + ' near line ' + lineno + ':' + column);
7777
err.filename = options.source;
7878
err.line = lineno;
@@ -160,7 +160,7 @@ module.exports = function(css, options){
160160
if (c !== false) {
161161
rules.push(c);
162162
}
163-
}
163+
}
164164
return rules;
165165
}
166166

@@ -400,7 +400,7 @@ module.exports = function(css, options){
400400

401401
function atcustommedia() {
402402
var pos = position();
403-
var m = match(/^@custom-media (--[^\s]+) *([^{]+);/);
403+
var m = match(/^@custom-media (--[^\s]+) *([^{;]+);/);
404404
if (!m) return;
405405

406406
return pos({

test/cases/custom-media.css

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
@custom-media --narrow-window (max-width: 30em);
2+
@custom-media --wide-window screen and (min-width: 40em);

test/cases/custom-media.json

+17-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,23 @@
1717
},
1818
"source": "custom-media.css"
1919
}
20+
},
21+
{
22+
"type": "custom-media",
23+
"name": "--wide-window",
24+
"media": "screen and (min-width: 40em)",
25+
"position": {
26+
"start": {
27+
"line": 2,
28+
"column": 1
29+
},
30+
"end": {
31+
"line": 2,
32+
"column": 58
33+
},
34+
"source": "custom-media.css"
35+
}
2036
}
2137
]
2238
}
23-
}
39+
}

0 commit comments

Comments
 (0)