Skip to content
Draft
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
33 changes: 33 additions & 0 deletions src/__tests__/compiler/logical-borders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,36 @@ describe("logical border styles", () => {
});
});
});

describe("logical border shorthands via var() (unparsed path)", () => {
// A var() forces a shorthand onto the unparsed path, where propertyRename
// (longhands only) and the parseBorderInline* parsers (parsed path only) do
// not reach. These must still expand to the RTL-aware start/end props.
test("border-inline-color with var()", () => {
expect(
getRule("border-inline-color: hsl(var(--primary));").rule,
).toStrictEqual([
{
s: [1, 1],
d: [
[[{}, "hsl", [{}, "var", "primary", 1]], "borderStartColor", 1],
[[{}, "hsl", [{}, "var", "primary", 1]], "borderEndColor", 1],
],
dv: 1,
},
]);
});

test("border-inline-width with var()", () => {
expect(getRule("border-inline-width: var(--w);").rule).toStrictEqual([
{
s: [1, 1],
d: [
[[{}, "var", "w", 1], "borderStartWidth", 1],
[[{}, "var", "w", 1], "borderEndWidth", 1],
],
dv: 1,
},
]);
});
});
24 changes: 24 additions & 0 deletions src/compiler/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ const unsupportedInlineStyles = new Set([
"border-inline-end-style",
]);

// Logical-border SHORTHANDS have no RN equivalent either; when var()-valued
// they reach the unparsed path (the parsed parseBorderInline* never run) and
// propertyRename only maps the longhands. Expand each to its RTL-aware
// start/end props, sharing the runtime value.
const inlineShorthandExpansion: Record<string, string[]> = {
"border-inline-color": ["border-start-color", "border-end-color"],
"border-inline-width": ["border-start-width", "border-end-width"],
};

const unparsedRuntimeParsing = new Set([
"animation",
"border",
Expand Down Expand Up @@ -955,6 +964,21 @@ export function parseUnparsedDeclaration(
property = rename;
}

/**
* Logical-border shorthands (border-inline-color / -width) reach here when
* var()-valued. RN has no border-inline-*; expand to start/end sharing the
* value, mirroring parseBorderInline* on the parsed path.
*/
const shorthandExpansion = inlineShorthandExpansion[property];
if (shorthandExpansion) {
const value = parseUnparsed(declaration.value.value, builder, property);
for (const target of shorthandExpansion) {
builder.descriptorProperty = target;
builder.addDescriptor(target, value);
}
return;
}

/**
* Unparsed shorthand properties need to be parsed at runtime
*/
Expand Down