Skip to content

Commit 6af9e26

Browse files
gmaclennanyoshuawuyts
authored andcommitted
Add support for :host-context (#10)
* Add support for host-context See https://www.html5rocks.com/en/tutorials/webcomponents/shadowdom-201/#toc-style-host * Add test for :host(.class)
1 parent 0c62db6 commit 6af9e26

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ function postcssPrefix (prefix, options) {
3333
const replacement = Selector.selector()
3434
replacement.nodes = [prefixNode].concat(selector.clone().nodes)
3535
selector.replaceWith(replacement)
36+
} else if (selector.type === 'pseudo' && selector.value === ':host-context') {
37+
const prefixNode = getPrefixNode(prefix)
38+
const replacement = Selector.selector()
39+
const prevNodes = selector.clone().nodes
40+
replacement.nodes = prevNodes.concat(' ', prefixNode, ', ', prefixNode, prevNodes)
41+
selector.replaceWith(replacement)
3642
}
3743
})
3844
}

test/fixture-out.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#hello-world { color: green; }
1414
#hello-world:hover { color: blue; }
1515

16+
#hello-world.test { color: aqua; }
17+
18+
.test #hello-world, #hello-world.test { color: red; }
19+
1620
h1 {}
1721
h1.title {}
1822
h2#thing {}

test/fixture.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
:host { color: green; }
1414
:host(:hover) { color: blue; }
1515

16+
:host(.test) { color: aqua; }
17+
18+
:host-context(.test) { color: red; }
19+
1620
h1 {}
1721
h1.title {}
1822
h2#thing {}

0 commit comments

Comments
 (0)