Skip to content

Commit 1e88eb8

Browse files
authored
fix: anonymous @prop atRule (#83)
1 parent d8cb1bc commit 1e88eb8

File tree

3 files changed

+50
-36
lines changed

3 files changed

+50
-36
lines changed

src/compiler/__tests__/@prop.test.tsx

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,43 @@ import { registerCSS, testID } from "react-native-css/jest";
44

55
import { compile } from "../compiler";
66

7-
test("@prop single", () => {
7+
test("@prop target (nested @media)", () => {
8+
const compiled = registerCSS(`
9+
.my-class {
10+
@prop test;
11+
@media all {
12+
color: #00f;
13+
}
14+
}
15+
`);
16+
17+
expect(compiled.stylesheet()).toStrictEqual({
18+
s: [
19+
[
20+
"my-class",
21+
[
22+
{
23+
d: [["#00f", ["test"]]],
24+
v: [["__rn-css-color", "#00f"]],
25+
s: [2, 1],
26+
},
27+
],
28+
],
29+
],
30+
});
31+
32+
render(<View testID={testID} className="my-class" />);
33+
const component = screen.getByTestId(testID);
34+
35+
expect(component.props).toStrictEqual({
36+
testID,
37+
children: undefined,
38+
test: "#00f",
39+
style: {},
40+
});
41+
});
42+
43+
test("@prop value: target", () => {
844
const compiled = registerCSS(`
945
.my-class {
1046
color: red;
@@ -46,7 +82,7 @@ test("@prop single", () => {
4682
});
4783
});
4884

49-
test("@prop single, nested value", () => {
85+
test("@prop value: nested target", () => {
5086
const compiled = compile(`
5187
.test {
5288
color: red;
@@ -76,7 +112,7 @@ test("@prop single, nested value", () => {
76112
});
77113
});
78114

79-
test("@prop single, on target", () => {
115+
test("@prop value: wildcard target", () => {
80116
const compiled = compile(`
81117
.test {
82118
color: red;
@@ -106,7 +142,7 @@ test("@prop single, on target", () => {
106142
});
107143
});
108144

109-
test("@prop single, nested", () => {
145+
test("@prop value: wildcard nested target", () => {
110146
const compiled = registerCSS(`
111147
.my-class {
112148
color: red;
@@ -146,36 +182,6 @@ test("@prop single, nested", () => {
146182
});
147183
});
148184

149-
test("@prop single, top level, nested", () => {
150-
const compiled = compile(`
151-
.test {
152-
color: red;
153-
background-color: blue;
154-
@prop background-color: myBackgroundColor.test;
155-
}
156-
`);
157-
158-
expect(compiled.stylesheet()).toStrictEqual({
159-
s: [
160-
[
161-
"test",
162-
[
163-
{
164-
d: [
165-
{
166-
color: "#f00",
167-
},
168-
["#00f", ["myBackgroundColor", "test"]],
169-
],
170-
s: [1, 1],
171-
v: [["__rn-css-color", "#f00"]],
172-
},
173-
],
174-
],
175-
],
176-
});
177-
});
178-
179185
test("@prop multiple", () => {
180186
const compiled = compile(`
181187
.test {

src/compiler/atRules.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function propAtRuleBlock(
120120
return item.value.type === "colon";
121121
});
122122

123-
if (!from || from.length !== 1 || !to) {
123+
if (!from || from.length !== 1) {
124124
return mapping;
125125
}
126126

@@ -129,6 +129,11 @@ function propAtRuleBlock(
129129
return mapping;
130130
}
131131

132+
if (!to) {
133+
mapping["*"] = toRNProperty(fromToken.value.value);
134+
return mapping;
135+
}
136+
132137
mapping[toRNProperty(fromToken.value.value)] = to.flatMap((item, index) => {
133138
switch (item.value.type) {
134139
case "delim":

src/compiler/stylesheet.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,10 @@ export class StylesheetBuilder {
411411
declarations.push([value, propPath]);
412412
}
413413
} else if (forceTuple || Array.isArray(propPath)) {
414-
declarations.push([value, propPath]);
414+
declarations.push([
415+
value,
416+
Array.isArray(propPath) ? propPath : [propPath],
417+
]);
415418
} else if (Array.isArray(value) && value.some(isStyleFunction)) {
416419
declarations.push([value, propPath]);
417420
} else {

0 commit comments

Comments
 (0)