Skip to content

Commit 9d337b6

Browse files
committed
By matching anything after the custom selector we avoid a potential problem with commas. We should trust postcss to not give us multiple selectors in its array
1 parent f43a62c commit 9d337b6

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* :--foo
44
* 注意:CSS 选择器区分大小写
55
*/
6-
var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)([^,]*)/g
6+
//var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)([^,]*)/g
7+
var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)(.*)/g
78

89
/**
910
* 暴露插件
@@ -52,7 +53,6 @@ function customSelector(options) {
5253
if (!options.lineBreak && options.lineBreak == false) {
5354
line_break = ' '
5455
}
55-
5656
// 转换自定义的选择器别名
5757
styles.eachRule(function(rule) {
5858
for (var prop in customSelectors) {

test/fixtures/matches.css

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@custom-selector :--buttons button, .button;
2+
3+
:--buttons:matches(:focus) {
4+
border: red;
5+
display: block;
6+
}
7+
8+
:--buttons:matches(:focus, .is-focused) {
9+
border: red;
10+
display: block;
11+
}

test/fixtures/matches.expected.css

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
button:matches(:focus),
2+
.button:matches(:focus) {
3+
border: red;
4+
display: block;
5+
}
6+
7+
button:matches(:focus, .is-focused),
8+
.button:matches(:focus, .is-focused) {
9+
border: red;
10+
display: block;
11+
}

test/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ test("@custom-selector", function(t) {
2525
compareFixtures(t, "pseudo", "should transform pseudo")
2626
compareFixtures(t, "multiline", "should transform multiline")
2727
compareFixtures(t, "some-hyphen-selector", "should transform some-hyphen-selector")
28+
compareFixtures(t, "matches", "should transform matches selector")
2829

2930
compareFixtures(t, "extension", "should transform local extensions", {
3031
extensions: {

0 commit comments

Comments
 (0)