Skip to content

Commit 9777f17

Browse files
ahdinosauryoshuawuyts
authored andcommitted
don't prefix if selector *starts with* :root
also, update to work with comma-separated selectors Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 29af79a commit 9777f17

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ function postcssPrefix (prefix, options) {
77

88
return function (root) {
99
root.walkRules(function (rule) {
10-
if (rule.selector === ':root') return
11-
rule.selector = prefix + rule.selector
10+
rule.selectors = rule.selectors.map(function (selector) {
11+
if (rule.selector.indexOf(':root') === 0) return selector
12+
return prefix + selector
13+
})
14+
rule.selector = rule.selectors.join(', ')
1215
})
1316
}
1417
}

test/fixture-out.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
:root {
22
--color-red: #f00;
3+
}
4+
5+
:root a {
36
--color-blue: #00f;
47
}
58

9+
:root ul, :root li {
10+
--color-green: #0f0;
11+
}
12+
613
#hello-world h1 {}
714
#hello-world h1.title {}
815
#hello-world h2#thing {}

test/fixture.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
:root {
22
--color-red: #f00;
3+
}
4+
5+
:root a {
36
--color-blue: #00f;
47
}
58

9+
:root ul, :root li {
10+
--color-green: #0f0;
11+
}
12+
613
h1 {}
714
h1.title {}
815
h2#thing {}

0 commit comments

Comments
 (0)