From 7debd45a815a0adbc1cc4988b645c3b5c6610d1e Mon Sep 17 00:00:00 2001 From: Zach Green Date: Wed, 31 May 2017 08:30:47 -0400 Subject: [PATCH] fix multiplied scope output --- lib/getChildRules.js | 7 +++++-- package.json | 2 +- src/getChildRules.js | 10 ++++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/getChildRules.js b/lib/getChildRules.js index 788978d..9667904 100644 --- a/lib/getChildRules.js +++ b/lib/getChildRules.js @@ -41,8 +41,11 @@ function getChildRules(css, parent) { name: atRule.name, params: atRule.params }); - // Should append even if parent selector - if (rule.selector === parent.selector || childRule) { + /** + * Should append even if parent selector, but make sure the two rules + * aren't identical. + */ + if ((rule.selector === parent.selector || childRule) && _postcss2.default.parse(rule).toString() !== _postcss2.default.parse(parent).toString()) { var clone = rule.clone(); criticalAtRule.append(clone); result.push(criticalAtRule); diff --git a/package.json b/package.json index 6190fbe..79466c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postcss-critical-css", - "version": "2.1.4", + "version": "2.1.5", "description": "Generate critical CSS using PostCSS", "main": "index.js", "repository": { diff --git a/src/getChildRules.js b/src/getChildRules.js index c6126f7..a5b359e 100644 --- a/src/getChildRules.js +++ b/src/getChildRules.js @@ -31,8 +31,14 @@ export function getChildRules (css: Object, parent: Object): Array { name: atRule.name, params: atRule.params }) - // Should append even if parent selector - if (rule.selector === parent.selector || childRule) { + /** + * Should append even if parent selector, but make sure the two rules + * aren't identical. + */ + if ( + (rule.selector === parent.selector || childRule) && + postcss.parse(rule).toString() !== postcss.parse(parent).toString() + ) { const clone = rule.clone() criticalAtRule.append(clone) result.push(criticalAtRule)