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 @@ -278,6 +278,20 @@ describe('@stylexjs/babel-plugin', () => {
`);
});

test('timing values converted to seconds carry no floating-point noise', () => {
const output = transform(`
import stylex from 'stylex';
const styles = stylex.create({
x: { transitionDuration: '33.3ms' },
y: { animationDelay: '11.3ms' },
z: { transition: 'opacity 13.8ms ease-in 10.2ms' }
});
`);
expect(output).toContain('transition-duration:.0333s');
expect(output).toContain('animation-delay:.0113s');
expect(output).toContain('transition:opacity .0138s ease-in .0102s');
});

test('transforms non-unitless property values', () => {
expect(
transform(`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export default function normalizeTimings(
if (!dimension || dimension.unit !== 'ms' || value < 10) {
return;
}
node.value = value / 1000 + 's';
// `33.3 / 1000` is 0.033299999999999996 in floating point; 15 significant
// digits drop that noise without losing any digit a CSS time can carry.
node.value = Number((value / 1000).toPrecision(15)) + 's';
});
return ast;
}