From e15df6c060d37f4598d14c6d2cc36a0ba876d268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Tue, 5 Feb 2019 15:57:54 +0100 Subject: [PATCH 1/3] initial sub selector fix --- index.js | 3 --- test/fixture-out.css | 5 +++++ test/fixture.css | 5 +++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 8c54b26..e933210 100644 --- a/index.js +++ b/index.js @@ -22,9 +22,6 @@ function postcssPrefix (prefix, options) { // don't prefix if parent is not selector if (selector.parent.type !== 'selector') return - // don't prefix if not first node in container - if (selector.parent.nodes[0] !== selector) return - // don't prefix pseudo selector args unless it's `:not` if (selector.parent.parent.type === 'pseudo' && selector.parent.parent.value !== ':not') { return diff --git a/test/fixture-out.css b/test/fixture-out.css index 106ed3e..e868cb2 100644 --- a/test/fixture-out.css +++ b/test/fixture-out.css @@ -40,3 +40,8 @@ h2#thing {} .stuff:nth-last-of-type(2) {} .stuff:not(p) {} + +.sub #hello-world {} +.sub:not(#hello-world x) {} +.sub:not(x #hello-world y) {} +.sub#hello-world:not(a#hello-world) {} diff --git a/test/fixture.css b/test/fixture.css index cfba3b3..42762cd 100644 --- a/test/fixture.css +++ b/test/fixture.css @@ -40,3 +40,8 @@ h2#thing {} .stuff:nth-last-of-type(2) {} .stuff:not(p) {} + +.sub :host {} +.sub:not(:host x) {} +.sub:not(x :host y) {} +.sub:host:not(a:host) {} From 0ff61e26f9a05faf2159683fe8bc086de1815d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Tue, 5 Feb 2019 16:31:33 +0100 Subject: [PATCH 2/3] fix a:host:not(b:host) edge case --- index.js | 5 ++--- package.json | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e933210..d855ad5 100644 --- a/index.js +++ b/index.js @@ -11,14 +11,13 @@ function postcssPrefix (prefix, options) { return function walk (root) { root.walkRules(function (rule) { const selector = Selector(transformSelectors) - .process(rule.selector).result - + .processSync(rule.selector) rule.selector = selector }) } function transformSelectors (selectors) { - selectors.eachInside(function (selector) { + selectors.walk(function (selector) { // don't prefix if parent is not selector if (selector.parent.type !== 'selector') return diff --git a/package.json b/package.json index b4e4e9c..f51f9b0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "repository": "stackcss/postcss-prefix", "dependencies": { "postcss": "^5.0.8", - "postcss-selector-parser": "^1.3.0" + "postcss-selector-parser": "^5.0.0" }, "devDependencies": { "tape": "^4.2.1" From de223d12915248b2eabd1068f8ca5fc521902ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Tue, 5 Feb 2019 16:33:36 +0100 Subject: [PATCH 3/3] downgrade postcss-selector-parser for node 4 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f51f9b0..fd7de40 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "repository": "stackcss/postcss-prefix", "dependencies": { "postcss": "^5.0.8", - "postcss-selector-parser": "^5.0.0" + "postcss-selector-parser": "^4.0.0" }, "devDependencies": { "tape": "^4.2.1"