postcss-nested 5.0.2 → 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -4
- package/index.d.ts +17 -13
- package/index.js +49 -29
- package/package.json +4 -4
- package/CHANGELOG.md +0 -100
package/README.md
CHANGED
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
|
|
28
28
|
@at-root html {
|
|
29
29
|
--font: 16px
|
|
30
|
-
}
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
```
|
|
@@ -60,10 +59,12 @@ html {
|
|
|
60
59
|
|
|
61
60
|
Related plugins:
|
|
62
61
|
|
|
62
|
+
* Use [`postcss-atroot`] for `@at-root` at-rule to move nested child
|
|
63
|
+
to the CSS root.
|
|
63
64
|
* Use [`postcss-current-selector`] **after** this plugin if you want
|
|
64
|
-
to use current selector in properties or variables values.
|
|
65
|
+
to use current selector in properties or variables values.
|
|
65
66
|
* Use [`postcss-nested-ancestors`] **before** this plugin if you want
|
|
66
|
-
to reference any ancestor element directly in your selectors with `^&`.
|
|
67
|
+
to reference any ancestor element directly in your selectors with `^&`.
|
|
67
68
|
|
|
68
69
|
Alternatives:
|
|
69
70
|
|
|
@@ -76,6 +77,7 @@ Alternatives:
|
|
|
76
77
|
alt="Sponsored by Evil Martians" width="236" height="54">
|
|
77
78
|
</a>
|
|
78
79
|
|
|
80
|
+
[`postcss-atroot`]: https://github.com/OEvgeny/postcss-atroot
|
|
79
81
|
[`postcss-current-selector`]: https://github.com/komlev/postcss-current-selector
|
|
80
82
|
[`postcss-nested-ancestors`]: https://github.com/toomuchdesign/postcss-nested-ancestors
|
|
81
83
|
[`postcss-nested-props`]: https://github.com/jedmao/postcss-nested-props
|
|
@@ -92,7 +94,7 @@ Alternatives:
|
|
|
92
94
|
npm install --save-dev postcss postcss-nested
|
|
93
95
|
```
|
|
94
96
|
|
|
95
|
-
**Step 2:** Check
|
|
97
|
+
**Step 2:** Check your project for existing PostCSS config: `postcss.config.js`
|
|
96
98
|
in the project root, `"postcss"` section in `package.json`
|
|
97
99
|
or `postcss` in bundle config.
|
|
98
100
|
|
package/index.d.ts
CHANGED
|
@@ -1,30 +1,34 @@
|
|
|
1
|
-
// Original definitions (@types/postcss-nested)
|
|
1
|
+
// Original definitions (@types/postcss-nested)
|
|
2
|
+
// by Maxim Vorontsov <https://github.com/VorontsovMaxim>
|
|
2
3
|
|
|
3
|
-
import { PluginCreator } from 'postcss'
|
|
4
|
+
import { PluginCreator } from 'postcss'
|
|
4
5
|
|
|
5
6
|
declare namespace nested {
|
|
6
7
|
interface Options {
|
|
7
8
|
/**
|
|
8
|
-
* By default, plugin will bubble only
|
|
9
|
+
* By default, plugin will bubble only `@media` and `@supports` at-rules.
|
|
9
10
|
* You can add your custom at-rules to this list by this option.
|
|
10
11
|
*/
|
|
11
|
-
bubble?: string[]
|
|
12
|
+
bubble?: string[]
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
* By default, plugin will unwrap only
|
|
15
|
-
* You can add your custom at-rules
|
|
15
|
+
* By default, plugin will unwrap only `@font-face`, `@keyframes`,
|
|
16
|
+
* and `@document` at-rules. You can add your custom at-rules
|
|
17
|
+
* to this list by this option.
|
|
16
18
|
*/
|
|
17
|
-
unwrap?: string[]
|
|
19
|
+
unwrap?: string[]
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
|
-
* By default, plugin will strip out any empty selector generated
|
|
21
|
-
* levels. You can set this option to true
|
|
22
|
+
* By default, plugin will strip out any empty selector generated
|
|
23
|
+
* by intermediate nesting levels. You can set this option to `true`
|
|
24
|
+
* to preserve them.
|
|
22
25
|
*/
|
|
23
|
-
preserveEmpty?: boolean
|
|
26
|
+
preserveEmpty?: boolean
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
type Nested = PluginCreator<Options
|
|
29
|
+
type Nested = PluginCreator<Options>
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
declare const nested: nested.Nested
|
|
30
|
-
|
|
32
|
+
declare const nested: nested.Nested
|
|
33
|
+
|
|
34
|
+
export = nested
|
package/index.js
CHANGED
|
@@ -43,13 +43,15 @@ function selectors (parent, child) {
|
|
|
43
43
|
let parentNode = parse(i, parent)
|
|
44
44
|
|
|
45
45
|
child.selectors.forEach(j => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
if (j.length) {
|
|
47
|
+
let node = parse(j, child)
|
|
48
|
+
let replaced = replace(node, parentNode)
|
|
49
|
+
if (!replaced) {
|
|
50
|
+
node.prepend(parser.combinator({ value: ' ' }))
|
|
51
|
+
node.prepend(parentNode.clone())
|
|
52
|
+
}
|
|
53
|
+
result.push(node.toString())
|
|
51
54
|
}
|
|
52
|
-
result.push(node.toString())
|
|
53
55
|
})
|
|
54
56
|
})
|
|
55
57
|
return result
|
|
@@ -64,26 +66,32 @@ function pickComment (comment, after) {
|
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
child.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
69
|
+
function createFnAtruleChilds (bubble) {
|
|
70
|
+
return function atruleChilds (rule, atrule, bubbling) {
|
|
71
|
+
let children = []
|
|
72
|
+
atrule.each(child => {
|
|
73
|
+
if (child.type === 'comment') {
|
|
74
|
+
children.push(child)
|
|
75
|
+
} else if (child.type === 'decl') {
|
|
76
|
+
children.push(child)
|
|
77
|
+
} else if (child.type === 'rule' && bubbling) {
|
|
78
|
+
child.selectors = selectors(rule, child)
|
|
79
|
+
} else if (child.type === 'atrule') {
|
|
80
|
+
if (child.nodes && bubble[child.name]) {
|
|
81
|
+
atruleChilds(rule, child, true)
|
|
82
|
+
} else {
|
|
83
|
+
children.push(child)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
if (bubbling) {
|
|
88
|
+
if (children.length) {
|
|
89
|
+
let clone = rule.clone({ nodes: [] })
|
|
90
|
+
for (let child of children) {
|
|
91
|
+
clone.append(child)
|
|
92
|
+
}
|
|
93
|
+
atrule.prepend(clone)
|
|
85
94
|
}
|
|
86
|
-
atrule.prepend(clone)
|
|
87
95
|
}
|
|
88
96
|
}
|
|
89
97
|
}
|
|
@@ -118,12 +126,22 @@ function atruleNames (defaults, custom) {
|
|
|
118
126
|
|
|
119
127
|
module.exports = (opts = {}) => {
|
|
120
128
|
let bubble = atruleNames(['media', 'supports'], opts.bubble)
|
|
121
|
-
let
|
|
129
|
+
let atruleChilds = createFnAtruleChilds(bubble)
|
|
130
|
+
let unwrap = atruleNames(
|
|
131
|
+
[
|
|
132
|
+
'document',
|
|
133
|
+
'font-face',
|
|
134
|
+
'keyframes',
|
|
135
|
+
'-webkit-keyframes',
|
|
136
|
+
'-moz-keyframes'
|
|
137
|
+
],
|
|
138
|
+
opts.unwrap
|
|
139
|
+
)
|
|
122
140
|
let preserveEmpty = opts.preserveEmpty
|
|
123
141
|
|
|
124
142
|
return {
|
|
125
143
|
postcssPlugin: 'postcss-nested',
|
|
126
|
-
|
|
144
|
+
Rule (rule, { Rule }) {
|
|
127
145
|
let unwrapped = false
|
|
128
146
|
let after = rule
|
|
129
147
|
let copyDeclarations = false
|
|
@@ -143,8 +161,6 @@ module.exports = (opts = {}) => {
|
|
|
143
161
|
after.after(child)
|
|
144
162
|
after = child
|
|
145
163
|
} else if (child.type === 'atrule') {
|
|
146
|
-
copyDeclarations = false
|
|
147
|
-
|
|
148
164
|
if (declarations.length) {
|
|
149
165
|
after = pickDeclarations(rule.selector, declarations, after, Rule)
|
|
150
166
|
declarations = []
|
|
@@ -163,17 +179,21 @@ module.exports = (opts = {}) => {
|
|
|
163
179
|
after = nodes
|
|
164
180
|
child.remove()
|
|
165
181
|
} else if (bubble[child.name]) {
|
|
182
|
+
copyDeclarations = true
|
|
166
183
|
unwrapped = true
|
|
167
184
|
atruleChilds(rule, child, true)
|
|
168
185
|
after = pickComment(child.prev(), after)
|
|
169
186
|
after.after(child)
|
|
170
187
|
after = child
|
|
171
188
|
} else if (unwrap[child.name]) {
|
|
189
|
+
copyDeclarations = true
|
|
172
190
|
unwrapped = true
|
|
173
191
|
atruleChilds(rule, child, false)
|
|
174
192
|
after = pickComment(child.prev(), after)
|
|
175
193
|
after.after(child)
|
|
176
194
|
after = child
|
|
195
|
+
} else if (copyDeclarations) {
|
|
196
|
+
declarations.push(child)
|
|
177
197
|
}
|
|
178
198
|
} else if (child.type === 'decl' && copyDeclarations) {
|
|
179
199
|
declarations.push(child)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-nested",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.6",
|
|
4
4
|
"description": "PostCSS plugin to unwrap nested rules like how Sass does it",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"postcss",
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"repository": "postcss/postcss-nested",
|
|
15
15
|
"engines": {
|
|
16
|
-
"node": ">=
|
|
16
|
+
"node": ">=12.0"
|
|
17
17
|
},
|
|
18
18
|
"funding": {
|
|
19
19
|
"type": "opencollective",
|
|
20
20
|
"url": "https://opencollective.com/postcss/"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"postcss": "^8.
|
|
23
|
+
"postcss": "^8.2.14"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"postcss-selector-parser": "^6.0.
|
|
26
|
+
"postcss-selector-parser": "^6.0.6"
|
|
27
27
|
}
|
|
28
28
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
3
|
-
|
|
4
|
-
## 5.0.2
|
|
5
|
-
* Fixed compatibility with `postcss-mixins` by moving to visitor API.
|
|
6
|
-
|
|
7
|
-
## 5.0.1
|
|
8
|
-
* Fixed PostCSS 8.1 compatibility.
|
|
9
|
-
* Added funding links.
|
|
10
|
-
|
|
11
|
-
## 5.0
|
|
12
|
-
* Moved to PostCSS 8.
|
|
13
|
-
* Moved `postcss` to `peerDependencies`.
|
|
14
|
-
|
|
15
|
-
## 4.2.3
|
|
16
|
-
* Fixed declarations after nested rule and before at-rule (by Rodion Demikhov).
|
|
17
|
-
|
|
18
|
-
## 4.2.2
|
|
19
|
-
* Fixed wrong specificity order of declarations (by Rodion Demikhov).
|
|
20
|
-
|
|
21
|
-
## 4.2.1
|
|
22
|
-
* Fix TypeScript definitions (by Avi Vahl).
|
|
23
|
-
|
|
24
|
-
## 4.2
|
|
25
|
-
* Add `@at-root` support (by Jason Quense).
|
|
26
|
-
|
|
27
|
-
## 4.1.2
|
|
28
|
-
* Improve error messsage on broken selector
|
|
29
|
-
|
|
30
|
-
## 4.1.1
|
|
31
|
-
* Add `&(:hover)` support (by Ben Delarre).
|
|
32
|
-
|
|
33
|
-
## 4.1
|
|
34
|
-
* Add `unwrap` option.
|
|
35
|
-
|
|
36
|
-
## 4.0
|
|
37
|
-
* Use PostCSS 7 (by Aleks Hudochenkov).
|
|
38
|
-
* Remove Node.js 4 support.
|
|
39
|
-
|
|
40
|
-
## 3.0
|
|
41
|
-
* Add `@font-face` to bubbling at-rules (by Valeriy Komlev).
|
|
42
|
-
* Add special logic for `@font-face` bubbling (by Phanindra Pydisetty).
|
|
43
|
-
* Use PostCSS selector parser 3.0.
|
|
44
|
-
|
|
45
|
-
## 2.1.2
|
|
46
|
-
* Fix replacing multiple `&`.
|
|
47
|
-
|
|
48
|
-
## 2.1.1
|
|
49
|
-
* Fix `:not(&)` support.
|
|
50
|
-
|
|
51
|
-
## 2.1
|
|
52
|
-
* Add `preserveEmpty` option (by Federico Zivolo).
|
|
53
|
-
|
|
54
|
-
## 2.0.4
|
|
55
|
-
* Fix finding `&` in some selectors (by Stepan Mikhaylyuk).
|
|
56
|
-
|
|
57
|
-
## 2.0.3
|
|
58
|
-
* Doesn’t replace `&` inside string (by Paul Kiddle).
|
|
59
|
-
|
|
60
|
-
## 2.0.2
|
|
61
|
-
* Fix comments moving regression.
|
|
62
|
-
|
|
63
|
-
## 2.0.1
|
|
64
|
-
* Fix rules order regression (by Dmitry Vibe).
|
|
65
|
-
|
|
66
|
-
## 2.0
|
|
67
|
-
* Use PostCSS 6 API.
|
|
68
|
-
|
|
69
|
-
## 1.0.1
|
|
70
|
-
* Clean up npm package.
|
|
71
|
-
|
|
72
|
-
## 1.0
|
|
73
|
-
* Use PostCSS 5.0 API.
|
|
74
|
-
* Do not add spaces to selector in compressed CSS.
|
|
75
|
-
* Move nodes with its comment above.
|
|
76
|
-
|
|
77
|
-
## 0.3.2
|
|
78
|
-
* Fix `@supports` at-rule support (by Ben Briggs).
|
|
79
|
-
|
|
80
|
-
## 0.3.1
|
|
81
|
-
* Pass PostCSS Plugin Guidelines.
|
|
82
|
-
|
|
83
|
-
## 0.3
|
|
84
|
-
* Do not unwrap custom at-rules.
|
|
85
|
-
* Add `bubble` option to unwrap some custom at-rules.
|
|
86
|
-
* Support PostCSS 4.1 API.
|
|
87
|
-
* Fix last semicolon after unwrapping.
|
|
88
|
-
|
|
89
|
-
## 0.2.2
|
|
90
|
-
* Module returns function to have common PostCSS API.
|
|
91
|
-
|
|
92
|
-
## 0.2.1
|
|
93
|
-
* Add comma support to selectors unwrap.
|
|
94
|
-
|
|
95
|
-
## 0.2
|
|
96
|
-
* Use PostCSS 4.0.
|
|
97
|
-
* Fix indent, when move rules to other parent.
|
|
98
|
-
|
|
99
|
-
## 0.1
|
|
100
|
-
* Initial release.
|