Skip to content

Commit dec788d

Browse files
MoOxromainmenke
authored andcommitted
Fixed: support of pseudo classes that use parenthesis
Ref postcss/postcss-selector-matches#2
1 parent 8761ef9 commit dec788d

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

plugins/postcss-selector-not/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.0.2 - 2015-06-13
2+
3+
- Fixed: support of pseudo classes that use parenthesis
4+
15
# 1.0.1 - 2015-04-30
26

37
- Fixed: the module now works in non babel environments

plugins/postcss-selector-not/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcss-selector-not",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "PostCSS plugin to transform :not() W3C CSS leve 4 pseudo class to :not() CSS level 3 selectors",
55
"keywords": [
66
"postcss",

plugins/postcss-selector-not/src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import list from "postcss/lib/list"
44
import balancedMatch from "balanced-match"
55

66
function explodeSelector(pseudoClass, selector) {
7-
if (selector && selector.indexOf(pseudoClass) > -1) {
8-
const start = `${pseudoClass}(`
9-
const end = ")"
10-
const matches = balancedMatch(start, end, selector)
7+
const position = selector.indexOf(pseudoClass)
8+
if (selector && position > -1) {
9+
const pre = selector.slice(0, position)
10+
const matches = balancedMatch("(", ")", selector.slice(position))
1111
const selectors = []
1212
const bodySelectors = matches.body ?
1313
list
@@ -17,7 +17,7 @@ function explodeSelector(pseudoClass, selector) {
1717
const postSelectors = matches.post ? explodeSelector(pseudoClass, matches.post) : [""]
1818
postSelectors.forEach(postSelector => {
1919
bodySelectors.forEach(bodySelector => {
20-
selectors.push(`${matches.pre}${pseudoClass}(${bodySelector})${postSelector}`)
20+
selectors.push(`${pre}${pseudoClass}(${bodySelector})${postSelector}`)
2121
})
2222
})
2323
return selectors

plugins/postcss-selector-not/test/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,11 @@ tape("postcss-selector-not", t => {
5050
"should transform :not() recursively"
5151
)
5252

53+
t.equal(
54+
transform(".foo:not(:nth-child(-n+2), .bar) {}"),
55+
".foo:not(:nth-child(-n+2)), .foo:not(.bar) {}",
56+
"should transform childs with parenthesis"
57+
)
58+
5359
t.end()
5460
})

0 commit comments

Comments
 (0)