Skip to content

Commit 0c22085

Browse files
committed
fix: <ratio> parsing
1 parent b491572 commit 0c22085

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/compiler/declarations.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,8 @@ export function reduceParseUnparsed(
996996
}
997997
}
998998

999+
// Groups are the tokens grouped together by comma location
1000+
// If a group only has 1 item, it shouldn't be an array
9991001
groups = groups.flatMap((group): StyleDescriptor[] => {
10001002
if (!Array.isArray(group)) {
10011003
return [];
@@ -1011,6 +1013,16 @@ export function reduceParseUnparsed(
10111013
} else {
10121014
return [first];
10131015
}
1016+
} else if (
1017+
// This is a special case for <ratio> values
1018+
group.every((item) =>
1019+
typeof item === "string" && item === "/"
1020+
? item
1021+
: typeof item === "number",
1022+
)
1023+
) {
1024+
// eslint-disable-next-line @typescript-eslint/no-base-to-string
1025+
return [group.join(" ")];
10141026
} else {
10151027
return [group];
10161028
}
@@ -1188,11 +1200,16 @@ export function parseUnparsed(
11881200
return parseDimension(tokenOrValue.value, builder);
11891201
case "comma":
11901202
return CommaSeparator as unknown as StyleDescriptor;
1203+
case "delim": {
1204+
if (tokenOrValue.value.value === "/") {
1205+
return tokenOrValue.value.value;
1206+
}
1207+
return;
1208+
}
11911209
case "at-keyword":
11921210
case "hash":
11931211
case "id-hash":
11941212
case "unquoted-url":
1195-
case "delim":
11961213
case "white-space":
11971214
case "comment":
11981215
case "colon":

src/runtime/native/__tests__/units.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,16 @@ test("rem - dynamic", () => {
170170
style: { fontSize: 100 },
171171
});
172172
});
173+
174+
test("<ratio>", () => {
175+
registerCSS(`.my-class { aspect-ratio: 16 / 9; }`);
176+
177+
const { result } = renderHook(() => {
178+
return useNativeCss(View, { className: "my-class" });
179+
});
180+
181+
expect(result.current.type).toBe(View);
182+
expect(result.current.props).toStrictEqual({
183+
style: { aspectRatio: "16/9" },
184+
});
185+
});

0 commit comments

Comments
 (0)