Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue 46 #55

Merged
merged 2 commits into from

2 participants

Kristofer Joseph TJ Holowaychuk
Kristofer Joseph

Fixes issue #46 by removing empty selectors.

TJ Holowaychuk tj merged commit 74450e6 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
24 lib/plugins/extend.js
View
@@ -1,4 +1,3 @@
-
/**
* Module dependencies.
*/
@@ -11,16 +10,23 @@ var debug = require('debug')('rework:extend');
module.exports = function() {
debug('use extend');
- return function(style, rework){
- var map = {};
- style.rules.forEach(function(rule){
- if (!rule.declarations) return;
- rule.selectors.forEach(function(sel, i){
+ return function(style, rework) {
+ var map = {},
+ rules = style.rules.length,
+ j = 0;
+ for (j; j < rules; j++) {
+ var rule = style.rules[j];
+ if (!rule || !rule.selectors) return;
+ rule.selectors.forEach(function(sel, i) {
map[sel] = rule;
if ('%' == sel[0]) rule.selectors.splice(i, 1);
});
visit(rule, map);
- });
+ if (!rule.declarations.length) {
+ style.rules.splice(j, 1);
+ j--;
+ }
+ };
}
};
@@ -43,12 +49,12 @@ function visit(rule, map) {
if (!extend) throw new Error('failed to extend "' + val + '"');
var keys = Object.keys(map);
- keys.forEach(function(key){
+ keys.forEach(function(key) {
if (0 != key.indexOf(val)) return;
var extend = map[key];
var suffix = key.replace(val, '');
debug('extend %j with %j', rule.selectors, extend.selectors);
- extend.selectors = extend.selectors.concat(rule.selectors.map(function(sel){
+ extend.selectors = extend.selectors.concat(rule.selectors.map(function(sel) {
return sel + suffix;
}));
});
5 test/fixtures/extend.nested.placeholder.out.css
View
@@ -19,8 +19,3 @@ input[type='submit']:hover .icon {
.actions a {
padding: 5px 10px
}
-
-button,
-input[type='submit'] {
-
-}
6 test/fixtures/extend.out.css
View
@@ -14,12 +14,8 @@ a.join {
padding: 10px 15px
}
-a.join {
-
-}
-
a.button
input[type='submit'],
input[type='button'] {
margin: 2px
-}
+}
Something went wrong with that request. Please try again.