Skip to content

Commit 1513e79

Browse files
committed
feat: improve parsing of rules with comma seperated styles
1 parent 4d4b691 commit 1513e79

File tree

21 files changed

+420
-212
lines changed

21 files changed

+420
-212
lines changed

CONTRIBUTING.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,20 @@ _Do not create pull requests for these reasons:_
180180

181181
> [!IMPORTANT]
182182
> The Metro transformer does not fast refresh. After you make a change, you will need to recompile the project and restart the Metro server with a clean cache.
183-
>
184-
> ```bash
185-
> # Build the project
186-
> yarn build
187-
>
188-
> # Start the Metro server with a clean cache
189-
> yarn example start --clean
190-
> ```
191183
192184
Development on the Metro transformer is done by running the example project.
193185

186+
Debugging with breakpoints is supported if you run the project in VSCode's JavaScript Debug Terminal, or by setting the NodeJS debugger environment variables
187+
188+
### Compiler
189+
190+
> [!IMPORTANT]
191+
> The Metro transformer does not fast refresh. After you make a change, you will need to recompile the project and restart the Metro server with a clean cache.
192+
193+
The easiest way to debug the compiler is through Test Driven Development (TDD). The tests are located in the `src/__tests__/compiler` directory.
194+
195+
You can use the JavaScript debugger, but you will need to use VSCode's JavaScript Debug Terminal, or set the NodeJS debugger environment variables to enable the debugger.
196+
194197
### Babel Plugin
195198

196199
> [!IMPORTANT]

example/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ export default function App() {
66
return (
77
<>
88
<View className="justify-center items-center h-full">
9-
<Text className="text-blue-500">Test Component</Text>
9+
<Text className="text-blue-500 shadow-lg shadow-red">
10+
Test Component
11+
</Text>
1012
</View>
1113
</>
1214
);
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { View } from "react-native-css/components/View";
2+
import { registerCSS, render, screen, testID } from "react-native-css/jest";
3+
4+
/**
5+
* Tailwind CSS utilities
6+
*
7+
* These tests are designed to ensure that complex Tailwind CSS utilities are compiled correctly.
8+
* For the full Tailwind CSS test suite, see the Nativewind repository.
9+
*/
10+
11+
test("box-shadow", () => {
12+
const compiled = registerCSS(`
13+
.shadow-xl {
14+
--tw-shadow: 0 20px 25px -5px var(--tw-shadow-color, rgb(0 0 0 / 0.1)), 0 8px 10px -6px var(--tw-shadow-color, rgb(0 0 0 / 0.1));
15+
box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
16+
}
17+
.shadow-red-500 {
18+
--tw-shadow-color: oklch(63.7% 0.237 25.331);
19+
@supports (color: color-mix(in lab, red, red)) {
20+
--tw-shadow-color: color-mix(in oklab, var(--color-red-500) var(--tw-shadow-alpha), transparent);
21+
}
22+
}
23+
`);
24+
25+
expect(compiled).toStrictEqual({
26+
s: [
27+
[
28+
"shadow-xl",
29+
[
30+
{
31+
d: [
32+
[
33+
[
34+
{},
35+
"@boxShadow",
36+
[
37+
[{}, "var", "tw-inset-shadow", 1],
38+
[{}, "var", "tw-inset-ring-shadow", 1],
39+
[{}, "var", "tw-ring-offset-shadow", 1],
40+
[{}, "var", "tw-ring-shadow", 1],
41+
[{}, "var", "tw-shadow", 1],
42+
],
43+
1,
44+
],
45+
"boxShadow",
46+
1,
47+
],
48+
],
49+
dv: 1,
50+
s: [1, 1],
51+
v: [
52+
[
53+
"tw-shadow",
54+
[
55+
[
56+
0,
57+
20,
58+
25,
59+
-5,
60+
[{}, "var", ["tw-shadow-color", "#0000001a"], 1],
61+
],
62+
[
63+
0,
64+
8,
65+
10,
66+
-6,
67+
[{}, "var", ["tw-shadow-color", "#0000001a"], 1],
68+
],
69+
],
70+
],
71+
],
72+
},
73+
],
74+
],
75+
[
76+
"shadow-red-500",
77+
[
78+
{
79+
s: [2, 1],
80+
v: [["tw-shadow-color", "#fb2c36"]],
81+
},
82+
],
83+
],
84+
],
85+
});
86+
87+
render(<View testID={testID} className="shadow-xl shadow-red-500" />);
88+
const component = screen.getByTestId(testID);
89+
90+
expect(component.type).toBe("View");
91+
expect(component.props).toStrictEqual({
92+
children: undefined,
93+
style: {
94+
boxShadow: [
95+
{
96+
blurRadius: 25,
97+
color: "#fb2c36",
98+
offsetX: 0,
99+
offsetY: 20,
100+
spreadDistance: -5,
101+
},
102+
{
103+
blurRadius: 10,
104+
color: "#fb2c36",
105+
offsetX: 0,
106+
offsetY: 8,
107+
spreadDistance: -6,
108+
},
109+
],
110+
},
111+
testID,
112+
});
113+
});

src/compiler/__tests__/compiler.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,6 @@ test("breaks apart comma separated variables", () => {
240240
`);
241241

242242
expect(compiled).toStrictEqual({
243-
vr: [["test", [[["blue"], ["green"]]]]],
243+
vr: [["test", [["blue", "green"]]]],
244244
});
245245
});

src/compiler/compiler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export function compile(
6868
},
6969
StyleSheetExit(sheet) {
7070
logger(`Found ${sheet.rules.length} rules to process`);
71+
logger(JSON.stringify(sheet.rules, null, 2));
7172

7273
for (const rule of sheet.rules) {
7374
// Extract the style declarations and animations from the current rule

src/compiler/compiler.types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,12 @@ export type StyleFunction =
125125
| [
126126
Record<never, never>,
127127
string, // string
128-
undefined | StyleDescriptor[], // arguments
128+
StyleDescriptor, // arguments
129129
]
130130
| [
131131
Record<never, never>,
132132
string, // string
133-
undefined | StyleDescriptor[], // arguments
133+
StyleDescriptor, // arguments
134134
1, // Should process after styles have been calculated
135135
];
136136

@@ -144,7 +144,7 @@ export type LightDarkVariable =
144144

145145
export type InlineVariable = {
146146
[VAR_SYMBOL]: "inline";
147-
[key: string]: StyleDescriptor | undefined;
147+
[key: string]: unknown | undefined;
148148
};
149149

150150
/****************************** Animations V1 ******************************/

0 commit comments

Comments
 (0)