Skip to content

Commit 1392a84

Browse files
committed
add @host support. Closes #54
1 parent a08f7e5 commit 1392a84

File tree

3 files changed

+87
-1
lines changed

3 files changed

+87
-1
lines changed

index.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,28 @@ module.exports = function(css, options){
306306
});
307307
}
308308

309+
/**
310+
* Parse host.
311+
*/
312+
313+
function athost() {
314+
var pos = position();
315+
var m = match(/^@host */);
316+
317+
if (!m) return;
318+
319+
if (!open()) return error("@host missing '{'");
320+
321+
var style = comments().concat(rules());
322+
323+
if (!close()) return error("@host missing '}'");
324+
325+
return pos({
326+
type: 'host',
327+
rules: style
328+
});
329+
}
330+
309331
/**
310332
* Parse media.
311333
*/
@@ -435,7 +457,8 @@ module.exports = function(css, options){
435457
|| atcharset()
436458
|| atnamespace()
437459
|| atdocument()
438-
|| atpage();
460+
|| atpage()
461+
|| athost();
439462
}
440463

441464
/**

test/cases/host.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@host {
2+
:scope {
3+
display: block;
4+
}
5+
}

test/cases/host.json

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

0 commit comments

Comments
 (0)