Skip to content

Commit 5e7c263

Browse files
committed
Add test, fix style
1 parent 6ce2cfe commit 5e7c263

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

__tests__/parseObjectStyles.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,32 @@ test('it parses nested media queries', () => {
123123
`)
124124
})
125125

126+
test('it bubbles nested screen rules', () => {
127+
const result = parseObjectStyles({
128+
'.foo': {
129+
backgroundColor: 'red',
130+
color: 'white',
131+
padding: '1rem',
132+
'@screen sm': {
133+
backgroundColor: 'orange',
134+
},
135+
},
136+
})
137+
138+
expect(css(result)).toMatchCss(`
139+
.foo {
140+
background-color: red;
141+
color: white;
142+
padding: 1rem;
143+
}
144+
@screen sm {
145+
.foo {
146+
background-color: orange;
147+
}
148+
}
149+
`)
150+
})
151+
126152
test('it parses pseudo-selectors in nested media queries', () => {
127153
const result = parseObjectStyles({
128154
'.foo': {

src/util/parseObjectStyles.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ export default function parseObjectStyles(styles) {
88
return parseObjectStyles([styles])
99
}
1010

11-
return _.flatMap(
12-
styles,
13-
style => postcss([postcssNested({ bubble: ['screen'] })]).process(style, { parser: postcssJs }).root.nodes
14-
)
11+
return _.flatMap(styles, style => {
12+
return postcss([
13+
postcssNested({
14+
bubble: ['screen'],
15+
}),
16+
]).process(style, {
17+
parser: postcssJs,
18+
}).root.nodes
19+
})
1520
}

0 commit comments

Comments
 (0)