From 02d4c5f9def2be32a639d663db1d1ce5fcf16575 Mon Sep 17 00:00:00 2001 From: kevin <5299031+kevin9327@users.noreply.github.com> Date: Fri, 30 Oct 2026 18:41:03 +0900 Subject: [PATCH] [babel-plugin] Drop floating-point noise when converting ms timings to seconds --- .../transform-value-normalization-test.js | 14 ++++++++++++++ .../src/shared/utils/normalizers/timings.js | 4 +++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js b/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js index 9ab0eb1d3..c63e867f1 100644 --- a/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js +++ b/packages/@stylexjs/babel-plugin/__tests__/transform-value-normalization-test.js @@ -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(` diff --git a/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/timings.js b/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/timings.js index 5bec8f2de..ce9c455cf 100644 --- a/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/timings.js +++ b/packages/@stylexjs/babel-plugin/src/shared/utils/normalizers/timings.js @@ -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; }