Skip to content

Commit

Permalink
Add test, fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwathan committed May 27, 2019
1 parent 6ce2cfe commit 5e7c263
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
26 changes: 26 additions & 0 deletions __tests__/parseObjectStyles.test.js
Expand Up @@ -123,6 +123,32 @@ test('it parses nested media queries', () => {
`)
})

test('it bubbles nested screen rules', () => {
const result = parseObjectStyles({
'.foo': {
backgroundColor: 'red',
color: 'white',
padding: '1rem',
'@screen sm': {
backgroundColor: 'orange',
},
},
})

expect(css(result)).toMatchCss(`
.foo {
background-color: red;
color: white;
padding: 1rem;
}
@screen sm {
.foo {
background-color: orange;
}
}
`)
})

test('it parses pseudo-selectors in nested media queries', () => {
const result = parseObjectStyles({
'.foo': {
Expand Down
13 changes: 9 additions & 4 deletions src/util/parseObjectStyles.js
Expand Up @@ -8,8 +8,13 @@ export default function parseObjectStyles(styles) {
return parseObjectStyles([styles])
}

return _.flatMap(
styles,
style => postcss([postcssNested({ bubble: ['screen'] })]).process(style, { parser: postcssJs }).root.nodes
)
return _.flatMap(styles, style => {
return postcss([
postcssNested({
bubble: ['screen'],
}),
]).process(style, {
parser: postcssJs,
}).root.nodes
})
}

0 comments on commit 5e7c263

Please sign in to comment.