From 992a7cbe0ef4cdbaea70bc81de4f5a00f7ddf710 Mon Sep 17 00:00:00 2001 From: Mark Lawlor Date: Sat, 16 Aug 2025 07:34:48 +1000 Subject: [PATCH] fix: anonymous @prop atRule --- src/compiler/__tests__/@prop.test.tsx | 74 +++++++++++++++------------ src/compiler/atRules.ts | 7 ++- src/compiler/stylesheet.ts | 5 +- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/src/compiler/__tests__/@prop.test.tsx b/src/compiler/__tests__/@prop.test.tsx index 3789c977..988da477 100644 --- a/src/compiler/__tests__/@prop.test.tsx +++ b/src/compiler/__tests__/@prop.test.tsx @@ -4,7 +4,43 @@ import { registerCSS, testID } from "react-native-css/jest"; import { compile } from "../compiler"; -test("@prop single", () => { +test("@prop target (nested @media)", () => { + const compiled = registerCSS(` + .my-class { + @prop test; + @media all { + color: #00f; + } + } + `); + + expect(compiled.stylesheet()).toStrictEqual({ + s: [ + [ + "my-class", + [ + { + d: [["#00f", ["test"]]], + v: [["__rn-css-color", "#00f"]], + s: [2, 1], + }, + ], + ], + ], + }); + + render(); + const component = screen.getByTestId(testID); + + expect(component.props).toStrictEqual({ + testID, + children: undefined, + test: "#00f", + style: {}, + }); +}); + +test("@prop value: target", () => { const compiled = registerCSS(` .my-class { color: red; @@ -46,7 +82,7 @@ test("@prop single", () => { }); }); -test("@prop single, nested value", () => { +test("@prop value: nested target", () => { const compiled = compile(` .test { color: red; @@ -76,7 +112,7 @@ test("@prop single, nested value", () => { }); }); -test("@prop single, on target", () => { +test("@prop value: wildcard target", () => { const compiled = compile(` .test { color: red; @@ -106,7 +142,7 @@ test("@prop single, on target", () => { }); }); -test("@prop single, nested", () => { +test("@prop value: wildcard nested target", () => { const compiled = registerCSS(` .my-class { color: red; @@ -146,36 +182,6 @@ test("@prop single, nested", () => { }); }); -test("@prop single, top level, nested", () => { - const compiled = compile(` - .test { - color: red; - background-color: blue; - @prop background-color: myBackgroundColor.test; - } - `); - - expect(compiled.stylesheet()).toStrictEqual({ - s: [ - [ - "test", - [ - { - d: [ - { - color: "#f00", - }, - ["#00f", ["myBackgroundColor", "test"]], - ], - s: [1, 1], - v: [["__rn-css-color", "#f00"]], - }, - ], - ], - ], - }); -}); - test("@prop multiple", () => { const compiled = compile(` .test { diff --git a/src/compiler/atRules.ts b/src/compiler/atRules.ts index ba268287..b421d930 100644 --- a/src/compiler/atRules.ts +++ b/src/compiler/atRules.ts @@ -120,7 +120,7 @@ function propAtRuleBlock( return item.value.type === "colon"; }); - if (!from || from.length !== 1 || !to) { + if (!from || from.length !== 1) { return mapping; } @@ -129,6 +129,11 @@ function propAtRuleBlock( return mapping; } + if (!to) { + mapping["*"] = toRNProperty(fromToken.value.value); + return mapping; + } + mapping[toRNProperty(fromToken.value.value)] = to.flatMap((item, index) => { switch (item.value.type) { case "delim": diff --git a/src/compiler/stylesheet.ts b/src/compiler/stylesheet.ts index d96f8c9f..bd3f2d2a 100644 --- a/src/compiler/stylesheet.ts +++ b/src/compiler/stylesheet.ts @@ -411,7 +411,10 @@ export class StylesheetBuilder { declarations.push([value, propPath]); } } else if (forceTuple || Array.isArray(propPath)) { - declarations.push([value, propPath]); + declarations.push([ + value, + Array.isArray(propPath) ? propPath : [propPath], + ]); } else if (Array.isArray(value) && value.some(isStyleFunction)) { declarations.push([value, propPath]); } else {