Skip to content

Commit 701b1f8

Browse files
authored
Fixed flipping of the nested rules and supports queries (#21)
1 parent 4c24bc2 commit 701b1f8

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/stylis-rtl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function stringifyPreserveComments(element, index, children, callback) {
2323
}
2424

2525
function stylisRTLPlugin(element: Object, index: number, children: Object[], callback: Function): ?string {
26-
if (element.type === KEYFRAMES || (element.type === RULESET && (!element.parent || element.parent.type === MEDIA))) {
26+
if (!element.root) {
2727
const stringified = cssjanus.transform(
2828
stringifyPreserveComments(element, index, children, callback)
2929
);

src/stylis-rtl.test.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { compile, middleware, prefixer, serialize, stringify } from 'stylis';
33
import stylisRtlPlugin from './stylis-rtl';
44

55
const stylis = (css, extraPlugins = []) =>
6-
serialize(compile(css), middleware([stylisRtlPlugin, ...extraPlugins, stringify]));
6+
serialize(compile(css), middleware([...extraPlugins, stylisRtlPlugin, stringify]));
77

88
describe('integration test with stylis', () => {
99
it('flips simple rules', () => {
@@ -74,6 +74,23 @@ describe('integration test with stylis', () => {
7474
);
7575
});
7676

77+
it('flips supports queries', () => {
78+
expect(
79+
stylis(
80+
`@supports (display: flex) {
81+
.a {
82+
padding-left: 5px;
83+
margin-right: 5px;
84+
border-left: 1px solid red;
85+
}
86+
}
87+
`
88+
)
89+
).toMatchInlineSnapshot(
90+
`"@supports (display: flex){.a{padding-right:5px;margin-left:5px;border-right:1px solid red;}}"`
91+
);
92+
});
93+
7794
it('works in tandem with prefixer', () => {
7895
expect(
7996
stylis(
@@ -103,4 +120,17 @@ describe('integration test with stylis', () => {
103120
`)
104121
).toMatchInlineSnapshot(`".cls .nested{color:hotpink;}"`);
105122
});
123+
124+
it("works for nested rules", () => {
125+
expect(
126+
stylis(`
127+
.cls {
128+
margin-right: 32px;
129+
& .first-child {
130+
margin-right: 32px;
131+
}
132+
}
133+
`)
134+
).toMatchInlineSnapshot(`".cls{margin-left:32px;}.cls .first-child{margin-left:32px;}"`);
135+
});
106136
});

0 commit comments

Comments
 (0)