Skip to content

Commit 8293c2d

Browse files
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 <[email protected]>
1 parent bef3838 commit 8293c2d

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

nesting/plugin.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ module.exports = function nesting(opts = postcssNested) {
1414
})
1515

1616
let plugin = (() => {
17-
if (typeof opts === 'function') {
17+
if (
18+
typeof opts === 'function' ||
19+
(typeof opts === 'object' && opts?.hasOwnProperty('postcssPlugin'))
20+
) {
1821
return opts
1922
}
2023

tests/postcss-plugins/nesting/index.test.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ it('should default to the bundled postcss-nested plugin (no options)', async ()
7474
`)
7575
})
7676

77-
it('should default to the bundled postcss-nested plugin (empty ooptions)', async () => {
77+
it('should default to the bundled postcss-nested plugin (empty options)', async () => {
7878
let input = css`
7979
.foo {
8080
color: black;
@@ -97,6 +97,29 @@ it('should default to the bundled postcss-nested plugin (empty ooptions)', async
9797
`)
9898
})
9999

100+
it('should be possible to use postcss-nested plugin with options', async () => {
101+
let input = css`
102+
.foo {
103+
color: black;
104+
@screen md {
105+
color: blue;
106+
}
107+
}
108+
`
109+
110+
expect(await run(input, postcssNested({ noIsPseudoSelector: true }))).toMatchCss(css`
111+
.foo {
112+
color: black;
113+
}
114+
115+
@media screen(md) {
116+
.foo {
117+
color: blue;
118+
}
119+
}
120+
`)
121+
})
122+
100123
test('@screen rules are replaced with media queries', async () => {
101124
let input = css`
102125
.foo {

0 commit comments

Comments
 (0)