Ensure nesting plugins can receive options (#7016)

* fix: options for nesting / nested plugins

* add tests to ensure passing options to postcss plugin works

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
This commit is contained in:
Lubomír Blažek 2022-01-14 16:20:06 +01:00 committed by GitHub
parent bef3838552
commit 8293c2d33d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 2 deletions

View File

@ -14,7 +14,10 @@ module.exports = function nesting(opts = postcssNested) {
})
let plugin = (() => {
if (typeof opts === 'function') {
if (
typeof opts === 'function' ||
(typeof opts === 'object' && opts?.hasOwnProperty('postcssPlugin'))
) {
return opts
}

View File

@ -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 {