Skip to content

Commit

Permalink
Merge pull request #25 from zgreen/21/bug/multiplied-output
Browse files Browse the repository at this point in the history
21/bug/multiplied output
  • Loading branch information
zgreen authored Jan 19, 2018
2 parents 837bd59 + c6504c0 commit c6145ba
Show file tree
Hide file tree
Showing 11 changed files with 5,713 additions and 44 deletions.
21 changes: 14 additions & 7 deletions lib/getCriticalRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ function clean(root) {
var test = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'critical-selector';

var clone = root.clone();
clone.walkDecls(test, function (decl) {
decl.remove();
});
if (clone.type === 'decl') {
clone.remove();
} else {
clone.walkDecls(test, function (decl) {
decl.remove();
});
}
return clone;
}

Expand Down Expand Up @@ -88,10 +92,13 @@ function establishContainer(node) {
*/
function updateCritical(root, update) {
var clonedRoot = root.clone();
update.clone().each(function (rule) {
var ruleRoot = rule.root();
clonedRoot.append(clean(ruleRoot));
});
if (update.type === 'rule') {
clonedRoot.append(clean(update.clone()));
} else {
update.clone().each(function (rule) {
clonedRoot.append(clean(rule.root()));
});
}
return clonedRoot;
}

Expand Down
Loading

0 comments on commit c6145ba

Please sign in to comment.