From ad421513ea6ac033ea657c91649eab4b09a19b2f Mon Sep 17 00:00:00 2001 From: Martin Hristov Date: Thu, 18 Apr 2019 11:40:42 +0300 Subject: [PATCH] fix(postcss-merge-rules): prevent merging of :host(tag) and tag Fixes: https://github.com/cssnano/cssnano/issues/730 --- .all-contributorsrc | 12 +++++++++++- CONTRIBUTORS.md | 3 +++ packages/postcss-merge-rules/src/__tests__/index.js | 8 ++++++++ packages/postcss-merge-rules/src/index.js | 5 +++++ 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 18600c6fc..6d8513f29 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -620,7 +620,17 @@ "contributions": [ "maintenance" ] + }, + { + "login": "MapTo0", + "name": "Martin", + "avatar_url": "https://avatars.githubusercontent.com/u/5821279?v=4", + "profile": "https://github.com/MapTo0", + "contributions": [ + "code" + ] } ], - "repoType": "github" + "repoType": "github", + "commitConvention": "none" } diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f842e9a63..f708b8c39 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -87,6 +87,9 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
Gene Mecija

🐛 💻 ⚠️
Ludovico Fischer

🚧 + +
Martin

💻 + diff --git a/packages/postcss-merge-rules/src/__tests__/index.js b/packages/postcss-merge-rules/src/__tests__/index.js index 505654015..43ed8e5a7 100644 --- a/packages/postcss-merge-rules/src/__tests__/index.js +++ b/packages/postcss-merge-rules/src/__tests__/index.js @@ -619,6 +619,14 @@ test('should not crash when node.raws.value is null (2)', () => { ); }); +test( + 'should not merge :host(tagname) with tagname', + processCSS( + ':host(tag){display:block}tag{display:block}', + ':host(tag){display:block}tag{display:block}' + ) +); + test( 'should merge multiple media queries', processCSS( diff --git a/packages/postcss-merge-rules/src/index.js b/packages/postcss-merge-rules/src/index.js index eda11f530..ce1e8b915 100644 --- a/packages/postcss-merge-rules/src/index.js +++ b/packages/postcss-merge-rules/src/index.js @@ -94,6 +94,11 @@ function canMerge(ruleA, ruleB, browsers, compatibilityCache) { const b = ruleB.selectors; const selectors = a.concat(b); + const hasHost = selectors.some((selector) => selector.includes(':host')); + + if (hasHost) { + return false; + } if (!ensureCompatibility(selectors, browsers, compatibilityCache)) { return false;