Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure nesting plugins can receive options #7016

Merged
merged 2 commits into from Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion nesting/plugin.js
Expand Up @@ -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
}

Expand Down
25 changes: 24 additions & 1 deletion tests/postcss-plugins/nesting/index.test.js
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down