postcss-nested
Advanced tools
Comparing version 2.0.4 to 2.1.0
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). | ||
## 2.1 | ||
* Add `preserveEmpty` option (by Federico Zivolo). | ||
## 2.0.4 | ||
@@ -5,0 +8,0 @@ * Fix finding `&` in some selectors (by Stepan Mikhaylyuk). |
@@ -63,3 +63,3 @@ var postcss = require('postcss'); | ||
function processRule(rule, bubble) { | ||
function processRule(rule, bubble, preserveEmpty) { | ||
var unwrapped = false; | ||
@@ -84,3 +84,3 @@ var after = rule; | ||
}); | ||
if ( unwrapped ) { | ||
if ( unwrapped && preserveEmpty !== true ) { | ||
rule.raws.semicolon = true; | ||
@@ -98,2 +98,3 @@ if ( rule.nodes.length === 0 ) rule.remove(); | ||
} | ||
var preserveEmpty = opts ? opts.preserveEmpty : false; | ||
@@ -103,3 +104,3 @@ var process = function (node) { | ||
if ( child.type === 'rule' ) { | ||
processRule(child, bubble); | ||
processRule(child, bubble, preserveEmpty); | ||
} else if ( child.type === 'atrule' ) { | ||
@@ -106,0 +107,0 @@ process(child); |
{ | ||
"name": "postcss-nested", | ||
"version": "2.0.4", | ||
"version": "2.1.0", | ||
"description": "PostCSS plugin to unwrap nested rules like how Sass does it.", | ||
@@ -16,7 +16,7 @@ "keywords": [ | ||
"dependencies": { | ||
"postcss": "^6.0.6", | ||
"postcss": "^6.0.8", | ||
"postcss-selector-parser": "^2.2.3" | ||
}, | ||
"devDependencies": { | ||
"eslint": "^4.2.0", | ||
"eslint": "^4.3.0", | ||
"eslint-config-postcss": "^2.0.2", | ||
@@ -23,0 +23,0 @@ "jest": "^20.0.4" |
@@ -81,3 +81,27 @@ # PostCSS Nested [![Build Status][ci-img]][ci] | ||
```js | ||
postcss([ require('postcss-nested')({ bubble: ['phone'] }) ] | ||
postcss([ require('postcss-nested')({ bubble: ['phone'] }) ]) | ||
``` | ||
### `preserveEmpty` | ||
By default, plugin will strip out any empty selector generated by intermediate | ||
nesting levels. You can set `preserveEmpty` to `true` to preserve them. | ||
```css | ||
.a { | ||
.b { | ||
color: black; | ||
} | ||
} | ||
``` | ||
Will be compiled to: | ||
```css | ||
.a { } | ||
.a .b { | ||
color: black; | ||
} | ||
``` | ||
This is especially useful if you want to export the empty classes with `postcss-modules`. |
8876
98
107
Updatedpostcss@^6.0.8