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

Commit 297488a

Browse files
committed
Fixed: spec has been previously misinterpreted and now transform correctly :not() level 4 to collapsed level 3
Close #1
1 parent 2cfd614 commit 297488a

File tree

6 files changed

+27
-43
lines changed

6 files changed

+27
-43
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.2.0 - 2015-06-13
2+
3+
- Fixed: spec has been previously misinterpreted and now transform correctly
4+
`:not()` level 4 to collapsed level 3
5+
([#1](https://github.com/postcss/postcss-selector-not/issues/1))
6+
- Removed: `lineBreak` option (useless now)
7+
18
# 1.1.0 - 2015-06-13
29

310
- Added: `lineBreak` option

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Maxime Thirouin
3+
Copyright (c) 2015 Maxime Thirouin
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

-8
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,6 @@ p:not(:first-child), p:not(.special) {
3737
}
3838
```
3939

40-
## Options
41-
42-
### `lineBreak`
43-
44-
(default: `false`)
45-
46-
Allows you to introduce a line break between generated selectors.
47-
4840
---
4941

5042
## [Changelog](CHANGELOG.md)

package.json

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

src/index.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,31 @@ function explodeSelector(pseudoClass, selector) {
99
const pre = selector.slice(0, position)
1010
const matches = balancedMatch("(", ")", selector.slice(position))
1111
const selectors = []
12-
const bodySelectors = matches.body ?
13-
list
12+
const bodySelectors = matches.body
13+
? list
1414
.comma(matches.body)
15-
.reduce((acc, s) => [...acc, ...explodeSelector(pseudoClass, s)], [])
16-
: [""]
17-
const postSelectors = matches.post ? explodeSelector(pseudoClass, matches.post) : [""]
18-
postSelectors.forEach(postSelector => {
19-
bodySelectors.forEach(bodySelector => {
20-
selectors.push(`${pre}${pseudoClass}(${bodySelector})${postSelector}`)
21-
})
22-
})
15+
.map(s => explodeSelector(pseudoClass, s))
16+
.join(`)${pseudoClass}(`)
17+
: ""
18+
const postSelectors = matches.post
19+
? explodeSelector(pseudoClass, matches.post)
20+
: ""
21+
selectors.push(`${pre}${pseudoClass}(${bodySelectors})${postSelectors}`)
2322
return selectors
2423
}
25-
return [selector]
24+
return selector
2625
}
2726

2827
function explodeSelectors(pseudoClass) {
29-
return (options = {}) => {
28+
return () => {
3029
return (css) => {
3130
css.eachRule(rule => {
3231
if (rule.selector && rule.selector.indexOf(pseudoClass) > -1) {
3332
rule.selector = explodeSelector(pseudoClass, rule.selector)
34-
.join("," + (options.lineBreak ? "\n" + rule.before : " "))
3533
}
3634
})
3735
}
3836
}
3937
}
4038

41-
4239
export default postcss.plugin("postcss-selector-not", explodeSelectors(":not"))

test/index.js

+7-19
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,37 @@ tape("postcss-selector-not", t => {
2222

2323
t.equal(
2424
transform(":not(a, b) {}"),
25-
":not(a), :not(b) {}",
25+
":not(a):not(b) {}",
2626
"should transform simple :not()"
2727
)
2828

2929
t.equal(
3030
transform("tag:not(.class, .class2) {}"),
31-
"tag:not(.class), tag:not(.class2) {}",
31+
"tag:not(.class):not(.class2) {}",
3232
"should transform directes :not()"
3333
)
3434

3535
t.equal(
3636
transform("tag :not(tag2, tag3) {}"),
37-
"tag :not(tag2), tag :not(tag3) {}",
37+
"tag :not(tag2):not(tag3) {}",
3838
"should transform :not()"
3939
)
4040

4141
t.equal(
4242
transform("tag :not(tag2, tag3) :not(tag4, tag5) {}"),
43-
"tag :not(tag2) :not(tag4), tag :not(tag3) :not(tag4), tag :not(tag2) :not(tag5), tag :not(tag3) :not(tag5) {}",
43+
"tag :not(tag2):not(tag3) :not(tag4):not(tag5) {}",
4444
"should transform mutltiples :not()"
4545
)
4646

4747
t.equal(
4848
transform("tag :not(tag2 :not(tag4, tag5), tag3) {}"),
49-
"tag :not(tag2 :not(tag4)), tag :not(tag2 :not(tag5)), tag :not(tag3) {}",
49+
"tag :not(tag2 :not(tag4):not(tag5)):not(tag3) {}",
5050
"should transform :not() recursively"
5151
)
5252

5353
t.equal(
5454
transform(".foo:not(:nth-child(-n+2), .bar) {}"),
55-
".foo:not(:nth-child(-n+2)), .foo:not(.bar) {}",
55+
".foo:not(:nth-child(-n+2)):not(.bar) {}",
5656
"should transform childs with parenthesis"
5757
)
5858

@@ -61,21 +61,9 @@ tape("postcss-selector-not", t => {
6161
.b,
6262
.c
6363
) {}`),
64-
"a:not(.b), a:not(.c) {}",
64+
"a:not(.b):not(.c) {}",
6565
"should works with lots of whitespace"
6666
)
6767

68-
t.equal(
69-
transform(".foo:not(:nth-child(-n+2), .bar) {}", {lineBreak: true}),
70-
".foo:not(:nth-child(-n+2)),\n.foo:not(.bar) {}",
71-
"should add line break if asked too"
72-
)
73-
74-
t.equal(
75-
transform(" .foo:not(:nth-child(-n+2), .bar) {}", {lineBreak: true}),
76-
" .foo:not(:nth-child(-n+2)),\n .foo:not(.bar) {}",
77-
"should add line break if asked too, and respect indentation"
78-
)
79-
8068
t.end()
8169
})

0 commit comments

Comments
 (0)