Skip to content

Commit 79cd5b0

Browse files
committed
fix handling of nodes
1 parent a2fd792 commit 79cd5b0

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/stylis-rtl.test.ts

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

44
const stylis = (css: string, extraPlugins: Middleware[] = []) =>
5-
serialize(compile(css), middleware([...extraPlugins, stylisRtlPlugin, stringify]));
5+
serialize(compile(css), middleware([stylisRtlPlugin, ...extraPlugins, stringify]));
66

77
describe('integration test with stylis', () => {
88
it('flips simple rules', () => {

src/stylis-rtl.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import cssjanus from 'cssjanus';
2-
import { COMMENT, compile, DECLARATION, IMPORT, RULESET, serialize, strlen, Middleware } from 'stylis';
2+
import {
3+
COMMENT,
4+
compile,
5+
DECLARATION,
6+
IMPORT,
7+
RULESET,
8+
serialize,
9+
strlen,
10+
Middleware,
11+
KEYFRAMES,
12+
MEDIA,
13+
SUPPORTS,
14+
} from 'stylis';
315

416
type MiddlewareParams = Parameters<Middleware>;
517

@@ -35,7 +47,11 @@ function stylisRTLPlugin(
3547
children: MiddlewareParams[2],
3648
callback: MiddlewareParams[3]
3749
): string | void {
38-
if (!element.root) {
50+
if (
51+
element.type === KEYFRAMES ||
52+
element.type === SUPPORTS ||
53+
(element.type === RULESET && (!element.parent || element.parent.type === MEDIA || element.parent.type === RULESET))
54+
) {
3955
const stringified = cssjanus.transform(stringifyPreserveComments(element, index, children));
4056
element.children = stringified ? compile(stringified)[0].children : [];
4157

0 commit comments

Comments
 (0)