Skip to content
Merged
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
33 changes: 33 additions & 0 deletions src/__tests__/native/variable-cycles.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,36 @@ test("repeated sibling variable references are not cycles", () => {
render(<View testID="sample" className="sample" />);
expect(screen.getByTestId("sample").props.style).toStrictEqual({ width: 40 });
});

const nested = (
<View className="parent">
<View className="mid">
<View testID="child" className="child" />
</View>
</View>
);

// A variable reaches a descendant unresolved, so this cycle closes on the element that reads it
test("one variable reached again from two branches of one value, inherited, drops the reading declaration", () => {
registerCSS(
`.parent { --a: red; --b: blue; --c: green; --unrelated: 1; }
.mid { --a: var(--b) var(--c); --b: var(--a); --c: var(--a); --unrelated: 0.5; }
.child { color: var(--a); opacity: var(--unrelated); }`,
{ inlineVariables: false },
);
render(nested);
expect(screen.getByTestId("child").props.style).toStrictEqual({
opacity: 0.5,
});
});

test("a cycle in a variable declared once is cut by the compiler", () => {
registerCSS(
`.mid { --unrelated: 0.5; }
.child { --z: var(--z); width: var(--z); opacity: var(--unrelated); }`,
);
render(nested);
expect(screen.getByTestId("child").props.style).toStrictEqual({
opacity: 0.5,
});
});
Loading