Skip to content

Commit eb7a8df

Browse files
authored
fix: @prop with unparsed declarations (#97)
1 parent 8dd703d commit eb7a8df

File tree

4 files changed

+49
-12
lines changed

4 files changed

+49
-12
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,46 @@ test("@prop target (nested @media)", () => {
4040
});
4141
});
4242

43+
test("@prop target unparsed", () => {
44+
const compiled = registerCSS(`
45+
:root {
46+
--color-black: #000;
47+
}
48+
49+
.my-class {
50+
@prop test;
51+
color: var(--color-black);
52+
}
53+
`);
54+
55+
expect(compiled.stylesheet()).toStrictEqual({
56+
s: [
57+
[
58+
"my-class",
59+
[
60+
{
61+
d: [[[{}, "var", "color-black", 1], ["test"], 1]],
62+
dv: 1,
63+
s: [2, 1],
64+
v: [["__rn-css-current-color", [{}, "var", "color-black", 1]]],
65+
},
66+
],
67+
],
68+
],
69+
vr: [["color-black", [["#000"]]]],
70+
});
71+
72+
render(<View testID={testID} className="my-class" />);
73+
const component = screen.getByTestId(testID);
74+
75+
expect(component.props).toStrictEqual({
76+
testID,
77+
children: undefined,
78+
test: "#000",
79+
style: {},
80+
});
81+
});
82+
4383
test("@prop value: target", () => {
4484
const compiled = registerCSS(`
4585
.my-class {

src/compiler/__tests__/declarations.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ const tests = [
66
["-rn-ripple-style: borderless;", [{ d: [[true, ["android_ripple", "borderless"]]], s: [1, 1] }]],
77
["caret-color: black", [{ d: [["#000", ["cursorColor"]]], s: [1, 1] }]],
88
["fill: black;", [{ d: [["#000", ["fill"]]], s: [1, 1] }]],
9-
["stroke: black;", [{ d: [["#000", ["stroke"]]], s: [1, 1] }]],
10-
["stroke-width: 1px;", [{ d: [[1, ["strokeWidth"]]], s: [1, 1] }]],
119
["rotate: 3deg;", [{ d: [[[{}, "rotateZ", "3deg"], "rotateZ"]], s: [1, 1] }]],
1210
["rotate: x 3deg;", [{ d: [[[{}, "rotateX", "3deg"], "rotateX"]], s: [1, 1] }]],
11+
["stroke-width: 1px;", [{ d: [[1, ["strokeWidth"]]], s: [1, 1] }]],
12+
["stroke: black;", [{ d: [["#000", ["stroke"]]], s: [1, 1] }]],
1313
] as const;
1414

1515
test.each(tests)("declarations for %s", (declarations, expected) => {

src/compiler/compiler.types.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ export type StyleDeclaration =
9999
| Record<string, StyleDescriptor>
100100
/** A style that needs to be set */
101101
| [StyleDescriptor, string | string[]]
102-
/** A value that can only be computed at runtime */
103-
| [StyleFunction, string | string[]]
104102
/** A value that can only be computed at runtime, and only after styles have been calculated */
105-
| [StyleFunction, string | string[], 1];
103+
| [StyleDescriptor, string | string[], 1];
106104

107105
export type StyleDescriptor =
108106
| string

src/compiler/stylesheet.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -410,22 +410,21 @@ export class StylesheetBuilder {
410410
propPath = property;
411411
}
412412

413-
if (isStyleFunction(value)) {
413+
if (forceTuple && !Array.isArray(propPath)) {
414+
propPath = [propPath];
415+
}
416+
417+
if (isStyleFunction(value) || Array.isArray(propPath)) {
414418
if (delayed) {
415419
declarations.push([value, propPath, 1]);
416420
} else {
417421
declarations.push([value, propPath]);
418422
}
419-
} else if (forceTuple || Array.isArray(propPath)) {
420-
declarations.push([
421-
value,
422-
Array.isArray(propPath) ? propPath : [propPath],
423-
]);
424423
} else if (Array.isArray(value) && value.some(isStyleFunction)) {
425424
declarations.push([value, propPath]);
426425
} else if (typeof value === "string" && keywords.has(value)) {
427426
declarations.push([value, propPath]);
428-
} else {
427+
} else if (typeof propPath === "string") {
429428
let staticDeclarationRecord = staticDeclarations.get(declarations);
430429
if (!staticDeclarationRecord) {
431430
staticDeclarationRecord = {};

0 commit comments

Comments
 (0)