Skip to content
This repository was archived by the owner on Jun 6, 2022. It is now read-only.

By matching anything after the custom selector we avoid a potential p… #17

Merged
merged 2 commits into from
Jun 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* :--foo
* 注意:CSS 选择器区分大小写
*/
var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)([^,]*)/g
var re_CUSTOM_SELECTOR = /([^,]*?)(:-{2,}[\w-]+)(.*)/g

/**
* 暴露插件
Expand Down Expand Up @@ -58,8 +58,8 @@ function customSelector(options) {
for (var prop in customSelectors) {
if (rule.selector.indexOf(prop) >= 0) {
customSelector = customSelectors[prop]

// $2 = <extension-name> (自定义的选择器名称)

rule.selector = rule.selector.replace(re_CUSTOM_SELECTOR, function($0, $1, $2, $3) {
if ($2 === prop) {
return customSelector.split(",").map(function(selector) {
Expand Down
11 changes: 11 additions & 0 deletions test/fixtures/matches.css
Original file line number Diff line number Diff line change
@@ -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;
}
11 changes: 11 additions & 0 deletions test/fixtures/matches.expected.css
Original file line number Diff line number Diff line change
@@ -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;
}
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down