Skip to content

Commit

Permalink
Ensure nesting plugins can receive options (#7016)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
lubomirblazekcz and RobinMalfait committed Jan 14, 2022
1 parent bef3838 commit 8293c2d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
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'))

This comment has been minimized.

Copy link
@chuntington

chuntington Jan 14, 2022

Contributor

Node.js versions 13 and below seem to throw an SyntaxError: Unexpected token '.' error here from the use of optional chaining syntax.

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

0 comments on commit 8293c2d

Please sign in to comment.