diff --git a/index.js b/index.js index 84dcb4a..0e94305 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ * :--foo * 注意:CSS 选择器区分大小写 */ -var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)([^,]*)/g +var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)(.*)/g /** * 暴露插件 @@ -58,8 +58,8 @@ function customSelector(options) { for (var prop in customSelectors) { if (rule.selector.indexOf(prop) >= 0) { customSelector = customSelectors[prop] + // $2 = (自定义的选择器名称) - rule.selector = rule.selector.replace(re_CUSTOM_SELECTOR, function($0, $1, $2, $3) { if ($2 === prop) { return customSelector.split(",").map(function(selector) { diff --git a/test/fixtures/matches.css b/test/fixtures/matches.css new file mode 100644 index 0000000..70390fb --- /dev/null +++ b/test/fixtures/matches.css @@ -0,0 +1,11 @@ +@custom-selector :--buttons button, .button; + +:--buttons:matches(:focus) { + border: red; + display: block; +} + +:--buttons:matches(:focus, .is-focused) { + border: red; + display: block; +} \ No newline at end of file diff --git a/test/fixtures/matches.expected.css b/test/fixtures/matches.expected.css new file mode 100644 index 0000000..eaa6cae --- /dev/null +++ b/test/fixtures/matches.expected.css @@ -0,0 +1,11 @@ +button:matches(:focus), +.button:matches(:focus) { + border: red; + display: block; +} + +button:matches(:focus, .is-focused), +.button:matches(:focus, .is-focused) { + border: red; + display: block; +} \ No newline at end of file diff --git a/test/index.js b/test/index.js index b343735..6257465 100644 --- a/test/index.js +++ b/test/index.js @@ -25,6 +25,7 @@ test("@custom-selector", function(t) { compareFixtures(t, "pseudo", "should transform pseudo") compareFixtures(t, "multiline", "should transform multiline") compareFixtures(t, "some-hyphen-selector", "should transform some-hyphen-selector") + compareFixtures(t, "matches", "should transform matches selector") compareFixtures(t, "extension", "should transform local extensions", { extensions: {