From a57c44e8f2e85de2527fd088de69a4047f659ee6 Mon Sep 17 00:00:00 2001 From: Jon Thompson <660222+jonthomp@users.noreply.github.com> Date: Wed, 11 Nov 2026 00:23:21 +0000 Subject: [PATCH] fix(compiler): keep a custom property declared as 0 parseUnparsed returned nothing when its reduced token list was falsy, so `--my-var: 0` compiled to no declaration. A var() reading it fell through to the inherited value, the :root value or its fallback instead of 0. The check now drops only an undefined result. --- src/__tests__/native/variables.test.tsx | 14 ++++++++++++++ src/compiler/declarations.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/__tests__/native/variables.test.tsx b/src/__tests__/native/variables.test.tsx index 25ac30f5..15a2c5c2 100644 --- a/src/__tests__/native/variables.test.tsx +++ b/src/__tests__/native/variables.test.tsx @@ -53,6 +53,20 @@ test("combined inline variables", () => { }); }); +test("a custom property declared as 0 keeps its value", () => { + // Two definitions, so the compiler cannot inline `--my-var`. + registerCSS(` + .zero { --my-var: 0; } + .one { --my-var: 1; } + .test { opacity: var(--my-var, 0.5); } + `); + + render(); + + const component = screen.getByTestId(testID); + expect(component.props.style).toStrictEqual({ opacity: 0 }); +}); + test("inherit variables", () => { registerCSS(` .my-class-1 { width: var(--my-var); } diff --git a/src/compiler/declarations.ts b/src/compiler/declarations.ts index 2f0b8a4a..efdd9a50 100644 --- a/src/compiler/declarations.ts +++ b/src/compiler/declarations.ts @@ -1198,7 +1198,7 @@ export function parseUnparsed( property, allowAuto, ); - if (!args) return; + if (args === undefined) return; if (Array.isArray(args) && args.length === 1) { return args[0]; } else if (