From 4a8a5ee8747f53c14911ae3cd2bc3443f8d761f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Bla=C5=BEek?= Date: Tue, 11 Jan 2022 16:09:47 +0100 Subject: [PATCH 1/2] fix: options for nesting / nested plugins --- nesting/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nesting/plugin.js b/nesting/plugin.js index 72bb24c27d33..cd776eb3c4fe 100644 --- a/nesting/plugin.js +++ b/nesting/plugin.js @@ -14,7 +14,7 @@ module.exports = function nesting(opts = postcssNested) { }) let plugin = (() => { - if (typeof opts === 'function') { + if (typeof opts === 'function' || typeof opts === 'object') { return opts } From e7c7a3c90e1637e02057b51008854b8c1a25ee77 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 14 Jan 2022 16:17:24 +0100 Subject: [PATCH 2/2] add tests to ensure passing options to postcss plugin works --- nesting/plugin.js | 5 ++++- tests/postcss-plugins/nesting/index.test.js | 25 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/nesting/plugin.js b/nesting/plugin.js index cd776eb3c4fe..2b5586648464 100644 --- a/nesting/plugin.js +++ b/nesting/plugin.js @@ -14,7 +14,10 @@ module.exports = function nesting(opts = postcssNested) { }) let plugin = (() => { - if (typeof opts === 'function' || typeof opts === 'object') { + if ( + typeof opts === 'function' || + (typeof opts === 'object' && opts?.hasOwnProperty('postcssPlugin')) + ) { return opts } diff --git a/tests/postcss-plugins/nesting/index.test.js b/tests/postcss-plugins/nesting/index.test.js index 03f184de14b2..2fcfb731d71a 100644 --- a/tests/postcss-plugins/nesting/index.test.js +++ b/tests/postcss-plugins/nesting/index.test.js @@ -74,7 +74,7 @@ it('should default to the bundled postcss-nested plugin (no options)', async () `) }) -it('should default to the bundled postcss-nested plugin (empty ooptions)', async () => { +it('should default to the bundled postcss-nested plugin (empty options)', async () => { let input = css` .foo { color: black; @@ -97,6 +97,29 @@ it('should default to the bundled postcss-nested plugin (empty ooptions)', async `) }) +it('should be possible to use postcss-nested plugin with options', async () => { + let input = css` + .foo { + color: black; + @screen md { + color: blue; + } + } + ` + + expect(await run(input, postcssNested({ noIsPseudoSelector: true }))).toMatchCss(css` + .foo { + color: black; + } + + @media screen(md) { + .foo { + color: blue; + } + } + `) +}) + test('@screen rules are replaced with media queries', async () => { let input = css` .foo {