Skip to content

Commit 04068d6

Browse files
authored
fix: rotate declaration parsing (#91)
1 parent 940a607 commit 04068d6

File tree

3 files changed

+50
-31
lines changed

3 files changed

+50
-31
lines changed

src/compiler/__tests__/declarations.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import { compile } from "../compiler";
1+
import { compileWithAutoDebug } from "react-native-css/jest";
22

3+
// prettier-ignore
34
const tests = [
45
["caret-color: black", [{ d: [["#000", ["cursorColor"]]], s: [1, 1] }]],
56
["stroke: black;", [{ d: [["#000", ["stroke"]]], s: [1, 1] }]],
7+
["rotate: 3deg;", [{ d: [[[{}, "rotateZ", "3deg"], "rotateZ"]], s: [1, 1] }]],
8+
["rotate: x 3deg;", [{ d: [[[{}, "rotateX", "3deg"], "rotateX"]], s: [1, 1] }]],
69
] as const;
710

811
test.each(tests)("declarations for %s", (declarations, expected) => {
9-
const compiled = compile(`.my-class { ${declarations} }`);
12+
const compiled = compileWithAutoDebug(`.my-class { ${declarations} }`);
1013

1114
const stylesheet = compiled.stylesheet();
1215

src/compiler/declarations.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -762,21 +762,29 @@ function parseRotate(
762762
{ value }: DeclarationType<"rotate">,
763763
builder: StylesheetBuilder,
764764
) {
765-
builder.addDescriptor("rotateX", [
766-
{},
767-
"rotateX",
768-
parseAngle(value.x, builder),
769-
]);
770-
builder.addDescriptor("rotateY", [
771-
{},
772-
"rotateY",
773-
parseAngle(value.y, builder),
774-
]);
775-
builder.addDescriptor("rotateZ", [
776-
{},
777-
"rotateZ",
778-
parseAngle(value.z, builder),
779-
]);
765+
if (value.x) {
766+
builder.addDescriptor("rotateX", [
767+
{},
768+
"rotateX",
769+
parseAngle(value.angle, builder),
770+
]);
771+
}
772+
773+
if (value.y) {
774+
builder.addDescriptor("rotateY", [
775+
{},
776+
"rotateY",
777+
parseAngle(value.angle, builder),
778+
]);
779+
}
780+
781+
if (value.z) {
782+
builder.addDescriptor("rotateZ", [
783+
{},
784+
"rotateZ",
785+
parseAngle(value.angle, builder),
786+
]);
787+
}
780788
}
781789

782790
function parseScale(

src/jest/index.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,10 @@ const debugDefault = Boolean(
3232

3333
export function registerCSS(
3434
css: string,
35-
{
36-
debug = debugDefault,
37-
...options
38-
}: CompilerOptions & { debug?: boolean } = {},
35+
options: CompilerOptions & { debug?: boolean } = {},
3936
) {
40-
const logger = debug
41-
? (text: string) => {
42-
// Just log the rules
43-
if (text.startsWith("[")) {
44-
console.log(`Rules:\n---\n${text}`);
45-
}
46-
}
47-
: undefined;
48-
49-
const compiled = compile(css, { ...options, logger });
37+
const { debug } = options;
38+
const compiled = compileWithAutoDebug(css, options);
5039
if (debug) {
5140
console.log(
5241
`Compiled:\n---\n${inspect(
@@ -63,3 +52,22 @@ export function registerCSS(
6352

6453
return compiled;
6554
}
55+
56+
export function compileWithAutoDebug(
57+
css: string,
58+
{
59+
debug = debugDefault,
60+
...options
61+
}: CompilerOptions & { debug?: boolean } = {},
62+
) {
63+
const logger = debug
64+
? (text: string) => {
65+
// Just log the rules
66+
if (text.startsWith("[")) {
67+
console.log(`Rules:\n---\n${text}`);
68+
}
69+
}
70+
: undefined;
71+
72+
return compile(css, { ...options, logger });
73+
}

0 commit comments

Comments
 (0)