Skip to content

Commit 904c1f8

Browse files
Allow :host anywhere (#15)
* initial sub selector fix * fix a:host:not(b:host) edge case * downgrade postcss-selector-parser for node 4
1 parent d80baa4 commit 904c1f8

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

index.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,16 @@ function postcssPrefix (prefix, options) {
1111
return function walk (root) {
1212
root.walkRules(function (rule) {
1313
const selector = Selector(transformSelectors)
14-
.process(rule.selector).result
15-
14+
.processSync(rule.selector)
1615
rule.selector = selector
1716
})
1817
}
1918

2019
function transformSelectors (selectors) {
21-
selectors.eachInside(function (selector) {
20+
selectors.walk(function (selector) {
2221
// don't prefix if parent is not selector
2322
if (selector.parent.type !== 'selector') return
2423

25-
// don't prefix if not first node in container
26-
if (selector.parent.nodes[0] !== selector) return
27-
2824
// don't prefix pseudo selector args unless it's `:not`
2925
if (selector.parent.parent.type === 'pseudo' && selector.parent.parent.value !== ':not') {
3026
return

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"repository": "stackcss/postcss-prefix",
66
"dependencies": {
77
"postcss": "^5.0.8",
8-
"postcss-selector-parser": "^1.3.0"
8+
"postcss-selector-parser": "^4.0.0"
99
},
1010
"devDependencies": {
1111
"tape": "^4.2.1"

test/fixture-out.css

+5
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ h2#thing {}
4040
.stuff:nth-last-of-type(2) {}
4141

4242
.stuff:not(p) {}
43+
44+
.sub #hello-world {}
45+
.sub:not(#hello-world x) {}
46+
.sub:not(x #hello-world y) {}
47+
.sub#hello-world:not(a#hello-world) {}

test/fixture.css

+5
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ h2#thing {}
4040
.stuff:nth-last-of-type(2) {}
4141

4242
.stuff:not(p) {}
43+
44+
.sub :host {}
45+
.sub:not(:host x) {}
46+
.sub:not(x :host y) {}
47+
.sub:host:not(a:host) {}

0 commit comments

Comments
 (0)