Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,40 @@ describe('@stylexjs/babel-plugin', () => {
`);
});

test('0 dimensions keep their unit category whatever its case', () => {
expect(
transform(`
import stylex from 'stylex';
const styles = stylex.create({
x: { transitionDuration: '0MS' },
y: { animationDelay: '0S' },
z: { transform: '0DEG' },

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimizations!

Would transform: rotate(0DEG) be more accurate?

w: { gridTemplateColumns: '0FR 1fr' }
});
`),
).toMatchInlineSnapshot(`
"import _inject from "@stylexjs/stylex/lib/stylex-inject";
var _inject2 = _inject;
import stylex from 'stylex';
_inject2({
ltr: ".x1mq3mr6{transition-duration:0s}",
priority: 3000
});
_inject2({
ltr: ".x1uzojwf{animation-delay:0s}",
priority: 3000
});
_inject2({
ltr: ".x1jpfit1{transform:0deg}",
priority: 3000
});
_inject2({
ltr: ".xkxvfks{grid-template-columns:0fr 1fr}",
priority: 3000
});"
`);
});

test('calc() preserves spaces around "+" and "-"', () => {
expect(
transform(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ export default function normalizeZeroDimensions(
if (!dimension || dimension.number !== '0') {
return;
}
if (angles.indexOf(dimension.unit) !== -1) {
// CSS units are ASCII case-insensitive: `0MS` is a time and `0FR` a flex
// value, and dropping their unit would change what the value means.
const unit = dimension.unit.toLowerCase();
if (angles.indexOf(unit) !== -1) {
node.value = '0deg';
} else if (timings.indexOf(dimension.unit) !== -1) {
} else if (timings.indexOf(unit) !== -1) {
node.value = '0s';
} else if (dimension.unit === fraction) {
} else if (unit === fraction) {
node.value = '0fr';
} else if (dimension.unit === percentage) {
} else if (unit === percentage) {
node.value = '0%';
} else if (!endFunction) {
node.value = '0';
Expand Down