postcss-nested 0.3.0 → 1.0.1
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/CHANGELOG.md +14 -0
- package/README.md +17 -5
- package/index.js +36 -22
- package/package.json +29 -22
- package/.eslintrc +0 -21
- package/.npmignore +0 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## 1.0.1
|
|
2
|
+
* Clean up npm package.
|
|
3
|
+
|
|
4
|
+
## 1.0
|
|
5
|
+
* Use PostCSS 5.0 API.
|
|
6
|
+
* Do not add spaces to selector in compressed CSS.
|
|
7
|
+
* Move nodes with its comment above.
|
|
8
|
+
|
|
9
|
+
## 0.3.2
|
|
10
|
+
* Fix `@supports` at-rule support (by Ben Briggs).
|
|
11
|
+
|
|
12
|
+
## 0.3.1
|
|
13
|
+
* Pass PostCSS Plugin Guidelines.
|
|
14
|
+
|
|
1
15
|
## 0.3
|
|
2
16
|
* Do not unwrap custom at-rules.
|
|
3
17
|
* Add `bubble` option to unwrap some custom at-rules.
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<img align="right" width="135" height="95"
|
|
4
4
|
title="Philosopher’s stone, logo of PostCSS"
|
|
5
|
-
src="http://postcss.github.io/postcss/logo-leftp.
|
|
5
|
+
src="http://postcss.github.io/postcss/logo-leftp.svg">
|
|
6
6
|
|
|
7
7
|
[PostCSS] plugin to unwrap nested rules like how Sass does it.
|
|
8
8
|
|
|
@@ -42,13 +42,25 @@ body.is_dark .phone_title {
|
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
Use [postcss-current-selector] **after** this plugin if you want to use current selector in properties or variables values.
|
|
46
|
+
|
|
47
|
+
Use [postcss-nested-ancestors] **before** this plugin if you want to reference any ancestor element directly in your selectors with `^&`.
|
|
48
|
+
|
|
49
|
+
See also [postcss-nesting], which implements [Tab Atkin's proposed syntax](https://tabatkins.github.io/specs/css-nesting/) (requires the `&` and introduces `@nest`).
|
|
50
|
+
|
|
51
|
+
There is also [postcss-nested-props] for nested properties like `font-size`.
|
|
52
|
+
|
|
45
53
|
<a href="https://evilmartians.com/?utm_source=postcss-nested">
|
|
46
54
|
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54">
|
|
47
55
|
</a>
|
|
48
56
|
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
57
|
+
[postcss-current-selector]: https://github.com/komlev/postcss-current-selector
|
|
58
|
+
[postcss-nested-ancestors]: https://github.com/toomuchdesign/postcss-nested-ancestors
|
|
59
|
+
[postcss-nested-props]: https://github.com/jedmao/postcss-nested-props
|
|
60
|
+
[postcss-nesting]: https://github.com/jonathantneal/postcss-nesting
|
|
61
|
+
[PostCSS]: https://github.com/postcss/postcss
|
|
62
|
+
[ci-img]: https://travis-ci.org/postcss/postcss-nested.svg
|
|
63
|
+
[ci]: https://travis-ci.org/postcss/postcss-nested
|
|
52
64
|
|
|
53
65
|
## Usage
|
|
54
66
|
|
|
@@ -62,7 +74,7 @@ See [PostCSS] docs for examples for your environment.
|
|
|
62
74
|
|
|
63
75
|
### `bubble`
|
|
64
76
|
|
|
65
|
-
By default, plugin will unwrap only `@media`, `@
|
|
77
|
+
By default, plugin will unwrap only `@media`, `@supports` and `@document`
|
|
66
78
|
at-rules. You can add your custom at-rules to this list by `bubble` option:
|
|
67
79
|
|
|
68
80
|
```js
|
package/index.js
CHANGED
|
@@ -1,59 +1,73 @@
|
|
|
1
1
|
var postcss = require('postcss');
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
function selectors(parent, node) {
|
|
4
|
+
var result = [];
|
|
5
|
+
parent.selectors.forEach(function (i) {
|
|
6
|
+
node.selectors.forEach(function (j) {
|
|
6
7
|
if ( j.indexOf('&') === -1 ) {
|
|
7
|
-
|
|
8
|
+
result.push(i + ' ' + j);
|
|
8
9
|
} else {
|
|
9
|
-
|
|
10
|
+
result.push(j.replace(/&/g, i));
|
|
10
11
|
}
|
|
11
|
-
})
|
|
12
|
-
})
|
|
13
|
-
|
|
12
|
+
});
|
|
13
|
+
});
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function pickComment(comment, after) {
|
|
18
|
+
if ( comment && comment.type === 'comment' ) {
|
|
19
|
+
return comment.moveAfter(after);
|
|
20
|
+
} else {
|
|
21
|
+
return after;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
14
24
|
|
|
15
|
-
|
|
16
|
-
var
|
|
25
|
+
function atruleChilds(rule, atrule) {
|
|
26
|
+
var children = [];
|
|
17
27
|
atrule.each(function (child) {
|
|
18
|
-
if ( child.type === '
|
|
19
|
-
|
|
28
|
+
if ( child.type === 'comment' ) {
|
|
29
|
+
children.push( child );
|
|
30
|
+
} if ( child.type === 'decl' ) {
|
|
31
|
+
children.push( child );
|
|
20
32
|
} else if ( child.type === 'rule' ) {
|
|
21
|
-
child.
|
|
33
|
+
child.selectors = selectors(rule, child);
|
|
22
34
|
} else if ( child.type === 'atrule' ) {
|
|
23
35
|
atruleChilds(rule, child);
|
|
24
36
|
}
|
|
25
37
|
});
|
|
26
|
-
if (
|
|
38
|
+
if ( children.length ) {
|
|
27
39
|
var clone = rule.clone({ nodes: [] });
|
|
28
|
-
for ( var i = 0; i <
|
|
40
|
+
for ( var i = 0; i < children.length; i++ ) children[i].moveTo(clone);
|
|
29
41
|
atrule.prepend(clone);
|
|
30
42
|
}
|
|
31
|
-
}
|
|
43
|
+
}
|
|
32
44
|
|
|
33
|
-
|
|
45
|
+
function processRule(rule, bubble) {
|
|
34
46
|
var unwrapped = false;
|
|
35
47
|
var after = rule;
|
|
36
48
|
rule.each(function (child) {
|
|
37
49
|
if ( child.type === 'rule' ) {
|
|
38
50
|
unwrapped = true;
|
|
39
|
-
child.
|
|
51
|
+
child.selectors = selectors(rule, child);
|
|
52
|
+
after = pickComment(child.prev(), after);
|
|
40
53
|
after = child.moveAfter(after);
|
|
41
54
|
} else if ( child.type === 'atrule' ) {
|
|
42
55
|
if ( bubble.indexOf(child.name) !== -1 ) {
|
|
43
56
|
unwrapped = true;
|
|
44
57
|
atruleChilds(rule, child);
|
|
58
|
+
after = pickComment(child.prev(), after);
|
|
45
59
|
after = child.moveAfter(after);
|
|
46
60
|
}
|
|
47
61
|
}
|
|
48
62
|
});
|
|
49
63
|
if ( unwrapped ) {
|
|
50
|
-
rule.semicolon = true;
|
|
51
|
-
if ( rule.nodes.length === 0 ) rule.
|
|
64
|
+
rule.raws.semicolon = true;
|
|
65
|
+
if ( rule.nodes.length === 0 ) rule.remove();
|
|
52
66
|
}
|
|
53
|
-
}
|
|
67
|
+
}
|
|
54
68
|
|
|
55
69
|
module.exports = postcss.plugin('postcss-nested', function (opts) {
|
|
56
|
-
var bubble = ['media', '
|
|
70
|
+
var bubble = ['media', 'supports', 'document'];
|
|
57
71
|
if ( opts && opts.bubble ) {
|
|
58
72
|
bubble = bubble.concat(opts.bubble.map(function (i) {
|
|
59
73
|
return i.replace(/^@/, '');
|
package/package.json
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
2
|
+
"name": "postcss-nested",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "PostCSS plugin to unwrap nested rules like how Sass does it.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"postcss",
|
|
7
|
+
"css",
|
|
8
|
+
"postcss-plugin",
|
|
9
|
+
"sass",
|
|
10
|
+
"nested"
|
|
11
|
+
],
|
|
12
|
+
"author": "Andrey Sitnik <andrey@sitnik.ru>",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": "postcss/postcss-nested",
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"postcss": "^5.2.17"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"eslint": "^3.12.2",
|
|
20
|
+
"eslint-config-postcss": "^2.0.2",
|
|
21
|
+
"jest": "^18.0.0"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"test": "jest && eslint *.js"
|
|
25
|
+
},
|
|
26
|
+
"eslintConfig": {
|
|
27
|
+
"extends": "eslint-config-postcss/es5",
|
|
28
|
+
"env": {
|
|
29
|
+
"jest": true
|
|
24
30
|
}
|
|
31
|
+
}
|
|
25
32
|
}
|
package/.eslintrc
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"rules": {
|
|
3
|
-
"no-unused-expressions": [0],
|
|
4
|
-
"no-underscore-dangle": [0],
|
|
5
|
-
"no-reserved-keys": [2],
|
|
6
|
-
"no-multi-spaces": [0],
|
|
7
|
-
"no-extra-parens": [2],
|
|
8
|
-
"no-unused-vars": [2],
|
|
9
|
-
"no-loop-func": [0],
|
|
10
|
-
"key-spacing": [0],
|
|
11
|
-
"max-len": [2],
|
|
12
|
-
"strict": [0],
|
|
13
|
-
"indent": [2],
|
|
14
|
-
"quotes": [2, "single", "avoid-escape"],
|
|
15
|
-
"curly": [0]
|
|
16
|
-
},
|
|
17
|
-
"env": {
|
|
18
|
-
"mocha": true,
|
|
19
|
-
"node": true
|
|
20
|
-
}
|
|
21
|
-
}
|