Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/__tests__/compiler/declarations.test.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { compile } from "react-native-css/compiler";
import { compileWithAutoDebug } from "react-native-css/jest";

// prettier-ignore
Expand Down Expand Up @@ -29,3 +30,44 @@ test.each(tests)("declarations for %s", (declarations, expected) => {

expect(myClassDeclarations).toStrictEqual(expected);
});

test.each([
[
"left weight only",
"color-mix(in oklab, var(--left) 90%, transparent)",
["oklab", [{}, "var", "left", 1], "90%", "transparent"],
],
[
"right weight only",
"color-mix(in srgb, var(--left), var(--right) 25%)",
["srgb", [{}, "var", "left", 1], [{}, "var", "right", 1], "25%"],
],
[
"neither weight",
"color-mix(in srgb, var(--left), var(--right))",
["srgb", [{}, "var", "left", 1], [{}, "var", "right", 1]],
],
] as const)(
"color-mix serializes without absent weights: %s",
(_, value, expected) => {
const stylesheet = JSON.parse(
JSON.stringify(
compile(`.test { background-color: ${value}; }`, {
inlineVariables: false,
}).stylesheet(),
),
) as ReturnType<ReturnType<typeof compile>["stylesheet"]>;
const declaration = stylesheet.s?.[0]?.[1]?.[0]?.d?.find(
(entry) =>
Array.isArray(entry) &&
Array.isArray(entry[0]) &&
entry[0][1] === "colorMix",
);

expect(
Array.isArray(declaration) && Array.isArray(declaration[0])
? declaration[0][2]
: undefined,
).toStrictEqual(expected);
},
);
19 changes: 8 additions & 11 deletions src/compiler/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2801,17 +2801,14 @@ export function parseColorMix(
return;
}

return [
{},
"colorMix",
[
colorSpaceArg,
leftColorArg,
leftColorPercentage,
rightColorArg,
rightColorPercentage,
],
];
// Optional weights must not leave undefined array entries: Metro serializes
// them as null, which the native colorMix resolver cannot consume.
const args: StyleDescriptor[] = [colorSpaceArg, leftColorArg];
if (leftColorPercentage !== undefined) args.push(leftColorPercentage);
args.push(rightColorArg);
if (rightColorPercentage !== undefined) args.push(rightColorPercentage);

return [{}, "colorMix", args];
}

export function parseCalcArguments(
Expand Down